Add external network options to osc network set

The following patch adds the options "--external" & "--internal"
and the suboptions to "external": "--default" & "--no-default",
to "osc network set" CLI to provide the user an option to set
a network as an external network or remove the setting.

Change-Id: I3a7f2cb249bc8101cbb01322d7732e913237d6cd
Partial-Bug: #1545537
This commit is contained in:
reedip 2016-04-08 14:24:30 +09:00 committed by Reedip
parent be6027e09b
commit 67f8b898eb
4 changed files with 62 additions and 11 deletions

View File

@ -171,6 +171,7 @@ Set network properties
[--name <name>] [--name <name>]
[--enable | --disable] [--enable | --disable]
[--share | --no-share] [--share | --no-share]
[--external [--default | --no-default] | --internal]
<network> <network>
.. option:: --name <name> .. option:: --name <name>
@ -193,6 +194,24 @@ Set network properties
Do not share the network between projects Do not share the network between projects
.. option:: --external
Set this network as an external network.
Requires the "external-net" extension to be enabled.
.. option:: --internal
Set this network as an internal network
.. option:: --default
Specify if this network should be used as
the default external network
.. option:: --no-default
Do not use the network as the default external network.
.. _network_set-network: .. _network_set-network:
.. describe:: <network> .. describe:: <network>

View File

@ -76,6 +76,16 @@ def _get_attrs(client_manager, parsed_args):
parsed_args.availability_zone_hints is not None: parsed_args.availability_zone_hints is not None:
attrs['availability_zone_hints'] = parsed_args.availability_zone_hints attrs['availability_zone_hints'] = parsed_args.availability_zone_hints
# update_external_network_options
if parsed_args.internal:
attrs['router:external'] = False
if parsed_args.external:
attrs['router:external'] = True
if parsed_args.no_default:
attrs['is_default'] = False
if parsed_args.default:
attrs['is_default'] = True
return attrs return attrs
@ -197,14 +207,6 @@ class CreateNetwork(common.NetworkAndComputeShowOne):
def take_action_network(self, client, parsed_args): def take_action_network(self, client, parsed_args):
attrs = _get_attrs(self.app.client_manager, parsed_args) attrs = _get_attrs(self.app.client_manager, parsed_args)
if parsed_args.internal:
attrs['router:external'] = False
if parsed_args.external:
attrs['router:external'] = True
if parsed_args.no_default:
attrs['is_default'] = False
if parsed_args.default:
attrs['is_default'] = True
if parsed_args.provider_network_type: if parsed_args.provider_network_type:
attrs['provider:network_type'] = parsed_args.provider_network_type attrs['provider:network_type'] = parsed_args.provider_network_type
if parsed_args.physical_network: if parsed_args.physical_network:
@ -379,6 +381,26 @@ class SetNetwork(command.Command):
action='store_true', action='store_true',
help='Do not share the network between projects', help='Do not share the network between projects',
) )
external_router_grp = parser.add_mutually_exclusive_group()
external_router_grp.add_argument(
'--external',
action='store_true',
help='Set this network as an external network. '
'Requires the "external-net" extension to be enabled.')
external_router_grp.add_argument(
'--internal',
action='store_true',
help='Set this network as an internal network')
default_router_grp = parser.add_mutually_exclusive_group()
default_router_grp.add_argument(
'--default',
action='store_true',
help='Specify if this network should be used as '
'the default external network')
default_router_grp.add_argument(
'--no-default',
action='store_true',
help='Do not use the network as the default external network.')
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):

View File

@ -482,12 +482,16 @@ class TestSetNetwork(TestNetwork):
'--enable', '--enable',
'--name', 'noob', '--name', 'noob',
'--share', '--share',
'--external',
'--default',
] ]
verifylist = [ verifylist = [
('network', self._network.name), ('network', self._network.name),
('enable', True), ('enable', True),
('name', 'noob'), ('name', 'noob'),
('share', True), ('share', True),
('external', True),
('default', True),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -497,6 +501,8 @@ class TestSetNetwork(TestNetwork):
'name': 'noob', 'name': 'noob',
'admin_state_up': True, 'admin_state_up': True,
'shared': True, 'shared': True,
'router:external': True,
'is_default': True,
} }
self.network.update_network.assert_called_once_with( self.network.update_network.assert_called_once_with(
self._network, **attrs) self._network, **attrs)
@ -507,11 +513,13 @@ class TestSetNetwork(TestNetwork):
self._network.name, self._network.name,
'--disable', '--disable',
'--no-share', '--no-share',
'--internal',
] ]
verifylist = [ verifylist = [
('network', self._network.name), ('network', self._network.name),
('disable', True), ('disable', True),
('no_share', True), ('no_share', True),
('internal', True),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@ -520,6 +528,7 @@ class TestSetNetwork(TestNetwork):
attrs = { attrs = {
'admin_state_up': False, 'admin_state_up': False,
'shared': False, 'shared': False,
'router:external': False,
} }
self.network.update_network.assert_called_once_with( self.network.update_network.assert_called_once_with(
self._network, **attrs) self._network, **attrs)

View File

@ -2,6 +2,7 @@
features: features:
- | - |
Add external network options ``--external|--internal`` and ``--external`` Add external network options ``--external|--internal`` and ``--external``
suboptions ``--default|--no-default`` to the ``network create`` command. suboptions ``--default|--no-default`` to the ``network create`` and
These options are available for Networkv2 only. ``network set`` commands.
[Bug `1545537 <https://bugs.launchpad.net/bugs/1545537>`_] These options are available for Network version 2 only.
[Bug `1545537 <https://bugs.launchpad.net/bugs/1545537>`_]