Add external network options to osc network create
The following patch adds the options "--external" & "--internal" and the suboptions to "external": "--default" & "--no-default", to "osc network create" CLI to provide the user an option to create a network as an external network. Change-Id: Idf73714bb94c0610ea164131140a51848908b00b Partial-Bug: #1545537
This commit is contained in:
		@@ -17,6 +17,7 @@ Create new network
 | 
			
		||||
        [--enable | --disable]
 | 
			
		||||
        [--share | --no-share]
 | 
			
		||||
        [--availability-zone-hint <availability-zone>]
 | 
			
		||||
        [--external [--default | --no-default] | --internal]
 | 
			
		||||
        <name>
 | 
			
		||||
 | 
			
		||||
.. option:: --project <project>
 | 
			
		||||
@@ -59,6 +60,29 @@ Create new network
 | 
			
		||||
    IPv4 subnet for fixed IPs (in CIDR notation)
 | 
			
		||||
    (Compute v2 network only)
 | 
			
		||||
 | 
			
		||||
.. option:: --external
 | 
			
		||||
 | 
			
		||||
    Set this network as an external network.
 | 
			
		||||
    Requires the "external-net" extension to be enabled.
 | 
			
		||||
    (Network v2 only)
 | 
			
		||||
 | 
			
		||||
.. option:: --internal
 | 
			
		||||
 | 
			
		||||
    Set this network as an internal network (default)
 | 
			
		||||
    (Network v2 only)
 | 
			
		||||
 | 
			
		||||
.. option:: --default
 | 
			
		||||
 | 
			
		||||
    Specify if this network should be used as
 | 
			
		||||
    the default external network
 | 
			
		||||
    (Network v2 only)
 | 
			
		||||
 | 
			
		||||
.. option:: --no-default
 | 
			
		||||
 | 
			
		||||
    Do not use the network as the default external network.
 | 
			
		||||
    By default, no network is set as an external network.
 | 
			
		||||
    (Network v2 only)
 | 
			
		||||
 | 
			
		||||
.. _network_create-name:
 | 
			
		||||
.. describe:: <name>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -144,6 +144,27 @@ class CreateNetwork(common.NetworkAndComputeShowOne):
 | 
			
		||||
                 '(requires the Network Availability Zone extension, '
 | 
			
		||||
                 'this option can be repeated).',
 | 
			
		||||
        )
 | 
			
		||||
        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)')
 | 
			
		||||
        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.'
 | 
			
		||||
                 'By default, no network is set as an external network.')
 | 
			
		||||
        return parser
 | 
			
		||||
 | 
			
		||||
    def update_parser_compute(self, parser):
 | 
			
		||||
@@ -156,6 +177,14 @@ class CreateNetwork(common.NetworkAndComputeShowOne):
 | 
			
		||||
 | 
			
		||||
    def take_action_network(self, client, 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
 | 
			
		||||
        obj = client.create_network(**attrs)
 | 
			
		||||
        columns = _get_columns(obj)
 | 
			
		||||
        data = utils.get_item_properties(obj, columns, formatters=_formatters)
 | 
			
		||||
 
 | 
			
		||||
@@ -152,6 +152,7 @@ class FakeNetwork(object):
 | 
			
		||||
            'router_external': True,
 | 
			
		||||
            'availability_zones': [],
 | 
			
		||||
            'availability_zone_hints': [],
 | 
			
		||||
            'is_default': False,
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        # Overwrite default attributes.
 | 
			
		||||
@@ -161,7 +162,7 @@ class FakeNetwork(object):
 | 
			
		||||
        network_methods = {
 | 
			
		||||
            'keys': ['id', 'name', 'admin_state_up', 'router_external',
 | 
			
		||||
                     'status', 'subnets', 'tenant_id', 'availability_zones',
 | 
			
		||||
                     'availability_zone_hints'],
 | 
			
		||||
                     'availability_zone_hints', 'is_default'],
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        # Overwrite default methods.
 | 
			
		||||
 
 | 
			
		||||
@@ -51,6 +51,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
 | 
			
		||||
        'availability_zone_hints',
 | 
			
		||||
        'availability_zones',
 | 
			
		||||
        'id',
 | 
			
		||||
        'is_default',
 | 
			
		||||
        'name',
 | 
			
		||||
        'project_id',
 | 
			
		||||
        'router_external',
 | 
			
		||||
@@ -63,6 +64,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
 | 
			
		||||
        utils.format_list(_network.availability_zone_hints),
 | 
			
		||||
        utils.format_list(_network.availability_zones),
 | 
			
		||||
        _network.id,
 | 
			
		||||
        _network.is_default,
 | 
			
		||||
        _network.name,
 | 
			
		||||
        _network.project_id,
 | 
			
		||||
        network._format_router_external(_network.router_external),
 | 
			
		||||
@@ -119,6 +121,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
 | 
			
		||||
            ('enable', True),
 | 
			
		||||
            ('share', None),
 | 
			
		||||
            ('project', None),
 | 
			
		||||
            ('external', False),
 | 
			
		||||
        ]
 | 
			
		||||
 | 
			
		||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
			
		||||
@@ -138,6 +141,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
 | 
			
		||||
            "--project", identity_fakes_v3.project_name,
 | 
			
		||||
            "--project-domain", identity_fakes_v3.domain_name,
 | 
			
		||||
            "--availability-zone-hint", "nova",
 | 
			
		||||
            "--external", "--default",
 | 
			
		||||
            self._network.name,
 | 
			
		||||
        ]
 | 
			
		||||
        verifylist = [
 | 
			
		||||
@@ -146,6 +150,8 @@ class TestCreateNetworkIdentityV3(TestNetwork):
 | 
			
		||||
            ('project', identity_fakes_v3.project_name),
 | 
			
		||||
            ('project_domain', identity_fakes_v3.domain_name),
 | 
			
		||||
            ('availability_zone_hints', ["nova"]),
 | 
			
		||||
            ('external', True),
 | 
			
		||||
            ('default', True),
 | 
			
		||||
            ('name', self._network.name),
 | 
			
		||||
        ]
 | 
			
		||||
 | 
			
		||||
@@ -158,6 +164,8 @@ class TestCreateNetworkIdentityV3(TestNetwork):
 | 
			
		||||
            'name': self._network.name,
 | 
			
		||||
            'shared': True,
 | 
			
		||||
            'tenant_id': identity_fakes_v3.project_id,
 | 
			
		||||
            'is_default': True,
 | 
			
		||||
            'router:external': True,
 | 
			
		||||
        })
 | 
			
		||||
        self.assertEqual(self.columns, columns)
 | 
			
		||||
        self.assertEqual(self.data, data)
 | 
			
		||||
@@ -172,6 +180,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
 | 
			
		||||
            ('enable', True),
 | 
			
		||||
            ('no_share', True),
 | 
			
		||||
            ('name', self._network.name),
 | 
			
		||||
            ('external', False),
 | 
			
		||||
        ]
 | 
			
		||||
 | 
			
		||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
			
		||||
@@ -198,6 +207,7 @@ class TestCreateNetworkIdentityV2(TestNetwork):
 | 
			
		||||
        'availability_zone_hints',
 | 
			
		||||
        'availability_zones',
 | 
			
		||||
        'id',
 | 
			
		||||
        'is_default',
 | 
			
		||||
        'name',
 | 
			
		||||
        'project_id',
 | 
			
		||||
        'router_external',
 | 
			
		||||
@@ -210,6 +220,7 @@ class TestCreateNetworkIdentityV2(TestNetwork):
 | 
			
		||||
        utils.format_list(_network.availability_zone_hints),
 | 
			
		||||
        utils.format_list(_network.availability_zones),
 | 
			
		||||
        _network.id,
 | 
			
		||||
        _network.is_default,
 | 
			
		||||
        _network.name,
 | 
			
		||||
        _network.project_id,
 | 
			
		||||
        network._format_router_external(_network.router_external),
 | 
			
		||||
@@ -253,6 +264,7 @@ class TestCreateNetworkIdentityV2(TestNetwork):
 | 
			
		||||
            ('share', None),
 | 
			
		||||
            ('name', self._network.name),
 | 
			
		||||
            ('project', identity_fakes_v2.project_name),
 | 
			
		||||
            ('external', False),
 | 
			
		||||
        ]
 | 
			
		||||
 | 
			
		||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
			
		||||
@@ -278,6 +290,7 @@ class TestCreateNetworkIdentityV2(TestNetwork):
 | 
			
		||||
            ('project', identity_fakes_v3.project_name),
 | 
			
		||||
            ('project_domain', identity_fakes_v3.domain_name),
 | 
			
		||||
            ('name', self._network.name),
 | 
			
		||||
            ('external', False),
 | 
			
		||||
        ]
 | 
			
		||||
 | 
			
		||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
			
		||||
@@ -514,6 +527,7 @@ class TestShowNetwork(TestNetwork):
 | 
			
		||||
        'availability_zone_hints',
 | 
			
		||||
        'availability_zones',
 | 
			
		||||
        'id',
 | 
			
		||||
        'is_default',
 | 
			
		||||
        'name',
 | 
			
		||||
        'project_id',
 | 
			
		||||
        'router_external',
 | 
			
		||||
@@ -526,6 +540,7 @@ class TestShowNetwork(TestNetwork):
 | 
			
		||||
        utils.format_list(_network.availability_zone_hints),
 | 
			
		||||
        utils.format_list(_network.availability_zones),
 | 
			
		||||
        _network.id,
 | 
			
		||||
        _network.is_default,
 | 
			
		||||
        _network.name,
 | 
			
		||||
        _network.project_id,
 | 
			
		||||
        network._format_router_external(_network.router_external),
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,9 @@
 | 
			
		||||
---
 | 
			
		||||
features:
 | 
			
		||||
  - |
 | 
			
		||||
    New options have been added to the ``network create`` command
 | 
			
		||||
    to support external network functionality. The new options are
 | 
			
		||||
    ``--external/--internal`` and suboptions to ``external``:
 | 
			
		||||
    ``--default/--no-default``.
 | 
			
		||||
    These options are available for Networkv2 only.
 | 
			
		||||
    [Bug `1545537 <https://bugs.launchpad.net/bugs/1545537>`_]
 | 
			
		||||
		Reference in New Issue
	
	Block a user