From 88be7ddd388c440d3f80564c7f1f4f2aed1a8e36 Mon Sep 17 00:00:00 2001 From: Ankur Gupta <ankur.gupta@intel.com> Date: Mon, 19 Sep 2016 16:43:28 -0500 Subject: [PATCH] Add --description to Create/Set Network Added simple option for network description to create and set network. Change-Id: I90ce4db4e365a56ecddb00d59f4c5aa2ebbd49a3 Partially-Implements: blueprint network-command-options --- doc/source/command-objects/network.rst | 10 ++++++++++ openstackclient/network/v2/network.py | 14 ++++++++++++++ openstackclient/tests/unit/network/v2/fakes.py | 1 + .../tests/unit/network/v2/test_network.py | 12 ++++++++++++ 4 files changed, 37 insertions(+) diff --git a/doc/source/command-objects/network.rst b/doc/source/command-objects/network.rst index 5d9a5ca860..8075d50919 100644 --- a/doc/source/command-objects/network.rst +++ b/doc/source/command-objects/network.rst @@ -23,6 +23,7 @@ Create new network [--project <project> [--project-domain <project-domain>]] [--enable | --disable] [--share | --no-share] + [--description <description>] [--availability-zone-hint <availability-zone>] [--enable-port-security | --disable-port-security] [--external [--default | --no-default] | --internal] @@ -65,6 +66,10 @@ Create new network Do not share the network between projects +.. option:: --description <description> + + Set network description + .. option:: --availability-zone-hint <availability-zone> Availability Zone in which to create this network @@ -206,6 +211,7 @@ Set network properties [--name <name>] [--enable | --disable] [--share | --no-share] + [--description <description>] [--enable-port-security | --disable-port-security] [--external [--default | --no-default] | --internal] [--provider-network-type <provider-network-type>] @@ -234,6 +240,10 @@ Set network properties Do not share the network between projects +.. option:: --description <description> + + Set network description + .. option:: --enable-port-security Enable port security by default for ports created on diff --git a/openstackclient/network/v2/network.py b/openstackclient/network/v2/network.py index ccc02fd8e6..31b173e138 100644 --- a/openstackclient/network/v2/network.py +++ b/openstackclient/network/v2/network.py @@ -78,6 +78,10 @@ def _get_attrs(client_manager, parsed_args): parsed_args.availability_zone_hints is not None: attrs['availability_zone_hints'] = parsed_args.availability_zone_hints + # set description + if parsed_args.description: + attrs['description'] = parsed_args.description + # update_external_network_options if parsed_args.internal: attrs['router:external'] = False @@ -191,6 +195,11 @@ class CreateNetwork(common.NetworkAndComputeShowOne): metavar='<project>', help=_("Owner's project (name or ID)") ) + parser.add_argument( + '--description', + metavar='<description>', + help=_("Set network description") + ) identity_common.add_project_domain_option_to_parser(parser) parser.add_argument( '--availability-zone-hint', @@ -420,6 +429,11 @@ class SetNetwork(command.Command): action='store_true', help=_("Do not share the network between projects") ) + parser.add_argument( + '--description', + metavar="<description", + help=_("Set network description") + ) port_security_group = parser.add_mutually_exclusive_group() port_security_group.add_argument( '--enable-port-security', diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py index 4cc3512e9d..73a7d2fdeb 100644 --- a/openstackclient/tests/unit/network/v2/fakes.py +++ b/openstackclient/tests/unit/network/v2/fakes.py @@ -285,6 +285,7 @@ class FakeNetwork(object): 'id': 'network-id-' + uuid.uuid4().hex, 'name': 'network-name-' + uuid.uuid4().hex, 'status': 'ACTIVE', + 'description': 'network-description-' + uuid.uuid4().hex, 'tenant_id': 'project-id-' + uuid.uuid4().hex, 'admin_state_up': True, 'shared': False, diff --git a/openstackclient/tests/unit/network/v2/test_network.py b/openstackclient/tests/unit/network/v2/test_network.py index 84ead0938b..1094131e52 100644 --- a/openstackclient/tests/unit/network/v2/test_network.py +++ b/openstackclient/tests/unit/network/v2/test_network.py @@ -57,6 +57,7 @@ class TestCreateNetworkIdentityV3(TestNetwork): 'admin_state_up', 'availability_zone_hints', 'availability_zones', + 'description', 'id', 'is_default', 'name', @@ -73,6 +74,7 @@ class TestCreateNetworkIdentityV3(TestNetwork): network._format_admin_state(_network.admin_state_up), utils.format_list(_network.availability_zone_hints), utils.format_list(_network.availability_zones), + _network.description, _network.id, _network.is_default, _network.name, @@ -129,6 +131,7 @@ class TestCreateNetworkIdentityV3(TestNetwork): arglist = [ "--disable", "--share", + "--description", self._network.description, "--project", self.project.name, "--project-domain", self.domain.name, "--availability-zone-hint", "nova", @@ -143,6 +146,7 @@ class TestCreateNetworkIdentityV3(TestNetwork): verifylist = [ ('disable', True), ('share', True), + ('description', self._network.description), ('project', self.project.name), ('project_domain', self.domain.name), ('availability_zone_hints', ["nova"]), @@ -164,6 +168,7 @@ class TestCreateNetworkIdentityV3(TestNetwork): 'availability_zone_hints': ["nova"], 'name': self._network.name, 'shared': True, + 'description': self._network.description, 'tenant_id': self.project.id, 'is_default': True, 'router:external': True, @@ -216,6 +221,7 @@ class TestCreateNetworkIdentityV2(TestNetwork): 'admin_state_up', 'availability_zone_hints', 'availability_zones', + 'description', 'id', 'is_default', 'name', @@ -232,6 +238,7 @@ class TestCreateNetworkIdentityV2(TestNetwork): network._format_admin_state(_network.admin_state_up), utils.format_list(_network.availability_zone_hints), utils.format_list(_network.availability_zones), + _network.description, _network.id, _network.is_default, _network.name, @@ -532,6 +539,7 @@ class TestSetNetwork(TestNetwork): '--enable', '--name', 'noob', '--share', + '--description', self._network.description, '--external', '--default', '--provider-network-type', 'vlan', @@ -543,6 +551,7 @@ class TestSetNetwork(TestNetwork): verifylist = [ ('network', self._network.name), ('enable', True), + ('description', self._network.description), ('name', 'noob'), ('share', True), ('external', True), @@ -560,6 +569,7 @@ class TestSetNetwork(TestNetwork): attrs = { 'name': 'noob', 'admin_state_up': True, + 'description': self._network.description, 'shared': True, 'router:external': True, 'is_default': True, @@ -624,6 +634,7 @@ class TestShowNetwork(TestNetwork): 'admin_state_up', 'availability_zone_hints', 'availability_zones', + 'description', 'id', 'is_default', 'name', @@ -640,6 +651,7 @@ class TestShowNetwork(TestNetwork): network._format_admin_state(_network.admin_state_up), utils.format_list(_network.availability_zone_hints), utils.format_list(_network.availability_zones), + _network.description, _network.id, _network.is_default, _network.name,