summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Theis <rtheis@us.ibm.com>2016-08-18 17:06:22 +0100
committerRichard Theis <rtheis@us.ibm.com>2016-09-14 08:01:56 -0500
commit7cba0ed671a1771d082da969a95ca0b4f4b9dafe (patch)
treea7b89168bee8dc92c8f9722928c7252497ed2f17
parent6f326acd260d035cb024f0c5e3ef2237277d8b37 (diff)
downloadpython-openstackclient-7cba0ed671a1771d082da969a95ca0b4f4b9dafe.tar.gz
Doc, help and message updates for port unset
Update port unset based on review comments in [1]. [1] https://review.openstack.org/#/c/306236/ Change-Id: Icae6e3869516f2d53f90ad46efc03f897c00b0e5 Implements: blueprint network-property-unset
-rw-r--r--doc/source/command-objects/subnet.rst8
-rw-r--r--openstackclient/network/v2/subnet.py57
2 files changed, 28 insertions, 37 deletions
diff --git a/doc/source/command-objects/subnet.rst b/doc/source/command-objects/subnet.rst
index 16092bcd..4566d74d 100644
--- a/doc/source/command-objects/subnet.rst
+++ b/doc/source/command-objects/subnet.rst
@@ -292,9 +292,9 @@ Unset subnet properties
.. option:: --allocation-pool start=<ip-address>,end=<ip-address>
- Allocation pool to be removed from this subnet e.g.:
- ``start=192.168.199.2,end=192.168.199.254``
- (repeat option to unset multiple Allocation pools)
+ Allocation pool IP addresses to be removed from this
+ subnet e.g.: ``start=192.168.199.2,end=192.168.199.254``
+ (repeat option to unset multiple allocation pools)
.. option:: --host-route destination=<subnet>,gateway=<ip-address>
@@ -314,4 +314,4 @@ Unset subnet properties
.. _subnet_unset-subnet:
.. describe:: <subnet>
- subnet to modify (name or ID)
+ Subnet to modify (name or ID)
diff --git a/openstackclient/network/v2/subnet.py b/openstackclient/network/v2/subnet.py
index 6feb8aa0..f1c7d15d 100644
--- a/openstackclient/network/v2/subnet.py
+++ b/openstackclient/network/v2/subnet.py
@@ -28,9 +28,14 @@ from openstackclient.identity import common as identity_common
LOG = logging.getLogger(__name__)
-def _update_arguments(obj_list, parsed_args_list):
+def _update_arguments(obj_list, parsed_args_list, option):
for item in parsed_args_list:
- obj_list.remove(item)
+ try:
+ obj_list.remove(item)
+ except ValueError:
+ msg = (_("Subnet does not contain %(option)s %(value)s") %
+ {'option': option, 'value': item})
+ raise exceptions.CommandError(msg)
def _format_allocation_pools(data):
@@ -493,9 +498,9 @@ class UnsetSubnet(command.Command):
dest='allocation_pools',
action=parseractions.MultiKeyValueAction,
required_keys=['start', 'end'],
- help=_('Allocation pool to be removed from this subnet '
- 'e.g.: start=192.168.199.2,end=192.168.199.254 '
- '(repeat option to unset multiple Allocation pools)')
+ help=_('Allocation pool IP addresses to be removed from this '
+ 'subnet e.g.: start=192.168.199.2,end=192.168.199.254 '
+ '(repeat option to unset multiple allocation pools)')
)
parser.add_argument(
'--dns-nameserver',
@@ -503,7 +508,7 @@ class UnsetSubnet(command.Command):
action='append',
dest='dns_nameservers',
help=_('DNS server to be removed from this subnet '
- '(repeat option to set multiple DNS servers)')
+ '(repeat option to unset multiple DNS servers)')
)
parser.add_argument(
'--host-route',
@@ -540,39 +545,25 @@ class UnsetSubnet(command.Command):
tmp_obj = copy.deepcopy(obj)
attrs = {}
if parsed_args.dns_nameservers:
- try:
- _update_arguments(tmp_obj.dns_nameservers,
- parsed_args.dns_nameservers)
- except ValueError as error:
- msg = (_("%s not in dns-nameservers") % str(error))
- raise exceptions.CommandError(msg)
+ _update_arguments(tmp_obj.dns_nameservers,
+ parsed_args.dns_nameservers,
+ 'dns-nameserver')
attrs['dns_nameservers'] = tmp_obj.dns_nameservers
if parsed_args.host_routes:
- try:
- _update_arguments(
- tmp_obj.host_routes,
- convert_entries_to_nexthop(parsed_args.host_routes))
- except ValueError as error:
- msg = (_("Subnet does not have %s in host-routes") %
- str(error))
- raise exceptions.CommandError(msg)
+ _update_arguments(
+ tmp_obj.host_routes,
+ convert_entries_to_nexthop(parsed_args.host_routes),
+ 'host-route')
attrs['host_routes'] = tmp_obj.host_routes
if parsed_args.allocation_pools:
- try:
- _update_arguments(tmp_obj.allocation_pools,
- parsed_args.allocation_pools)
- except ValueError as error:
- msg = (_("Subnet does not have %s in allocation-pools") %
- str(error))
- raise exceptions.CommandError(msg)
+ _update_arguments(tmp_obj.allocation_pools,
+ parsed_args.allocation_pools,
+ 'allocation-pool')
attrs['allocation_pools'] = tmp_obj.allocation_pools
if parsed_args.service_types:
- try:
- _update_arguments(tmp_obj.service_types,
- parsed_args.service_types)
- except ValueError as error:
- msg = (_("%s not in service-types") % str(error))
- raise exceptions.CommandError(msg)
+ _update_arguments(tmp_obj.service_types,
+ parsed_args.service_types,
+ 'service-type')
attrs['service_types'] = tmp_obj.service_types
if attrs:
client.update_subnet(obj, **attrs)