From 107bc5164f99ef956d952273235648c7f8f26764 Mon Sep 17 00:00:00 2001 From: reedip Date: Mon, 14 Mar 2016 15:35:46 +0900 Subject: [PATCH] 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 --- doc/source/command-objects/network.rst | 24 +++++++++++++++ openstackclient/network/v2/network.py | 29 +++++++++++++++++++ openstackclient/tests/network/v2/fakes.py | 3 +- .../tests/network/v2/test_network.py | 15 ++++++++++ ...add-external-options-7a66219d263bb1e5.yaml | 9 ++++++ 5 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/add-external-options-7a66219d263bb1e5.yaml diff --git a/doc/source/command-objects/network.rst b/doc/source/command-objects/network.rst index 9e109279f..e0a649c15 100644 --- a/doc/source/command-objects/network.rst +++ b/doc/source/command-objects/network.rst @@ -17,6 +17,7 @@ Create new network [--enable | --disable] [--share | --no-share] [--availability-zone-hint ] + [--external [--default | --no-default] | --internal] .. option:: --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:: diff --git a/openstackclient/network/v2/network.py b/openstackclient/network/v2/network.py index 42648e455..6fd18efb4 100644 --- a/openstackclient/network/v2/network.py +++ b/openstackclient/network/v2/network.py @@ -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) diff --git a/openstackclient/tests/network/v2/fakes.py b/openstackclient/tests/network/v2/fakes.py index e35fbe165..7f89ef7a9 100644 --- a/openstackclient/tests/network/v2/fakes.py +++ b/openstackclient/tests/network/v2/fakes.py @@ -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. diff --git a/openstackclient/tests/network/v2/test_network.py b/openstackclient/tests/network/v2/test_network.py index 26b98f772..572bc6aee 100644 --- a/openstackclient/tests/network/v2/test_network.py +++ b/openstackclient/tests/network/v2/test_network.py @@ -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), diff --git a/releasenotes/notes/add-external-options-7a66219d263bb1e5.yaml b/releasenotes/notes/add-external-options-7a66219d263bb1e5.yaml new file mode 100644 index 000000000..7b8eaff00 --- /dev/null +++ b/releasenotes/notes/add-external-options-7a66219d263bb1e5.yaml @@ -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 `_]