Skip to content

Commit 7e990ba

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Doc, help and message updates for port unset"
2 parents e6b09ee + 7cba0ed commit 7e990ba

2 files changed

Lines changed: 28 additions & 37 deletions

File tree

doc/source/command-objects/subnet.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ Unset subnet properties
292292
293293
.. option:: --allocation-pool start=<ip-address>,end=<ip-address>
294294
295-
Allocation pool to be removed from this subnet e.g.:
296-
``start=192.168.199.2,end=192.168.199.254``
297-
(repeat option to unset multiple Allocation pools)
295+
Allocation pool IP addresses to be removed from this
296+
subnet e.g.: ``start=192.168.199.2,end=192.168.199.254``
297+
(repeat option to unset multiple allocation pools)
298298
299299
.. option:: --host-route destination=<subnet>,gateway=<ip-address>
300300
@@ -314,4 +314,4 @@ Unset subnet properties
314314
.. _subnet_unset-subnet:
315315
.. describe:: <subnet>
316316
317-
subnet to modify (name or ID)
317+
Subnet to modify (name or ID)

openstackclient/network/v2/subnet.py

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@
2828
LOG = logging.getLogger(__name__)
2929

3030

31-
def _update_arguments(obj_list, parsed_args_list):
31+
def _update_arguments(obj_list, parsed_args_list, option):
3232
for item in parsed_args_list:
33-
obj_list.remove(item)
33+
try:
34+
obj_list.remove(item)
35+
except ValueError:
36+
msg = (_("Subnet does not contain %(option)s %(value)s") %
37+
{'option': option, 'value': item})
38+
raise exceptions.CommandError(msg)
3439

3540

3641
def _format_allocation_pools(data):
@@ -493,17 +498,17 @@ def get_parser(self, prog_name):
493498
dest='allocation_pools',
494499
action=parseractions.MultiKeyValueAction,
495500
required_keys=['start', 'end'],
496-
help=_('Allocation pool to be removed from this subnet '
497-
'e.g.: start=192.168.199.2,end=192.168.199.254 '
498-
'(repeat option to unset multiple Allocation pools)')
501+
help=_('Allocation pool IP addresses to be removed from this '
502+
'subnet e.g.: start=192.168.199.2,end=192.168.199.254 '
503+
'(repeat option to unset multiple allocation pools)')
499504
)
500505
parser.add_argument(
501506
'--dns-nameserver',
502507
metavar='<dns-nameserver>',
503508
action='append',
504509
dest='dns_nameservers',
505510
help=_('DNS server to be removed from this subnet '
506-
'(repeat option to set multiple DNS servers)')
511+
'(repeat option to unset multiple DNS servers)')
507512
)
508513
parser.add_argument(
509514
'--host-route',
@@ -540,39 +545,25 @@ def take_action(self, parsed_args):
540545
tmp_obj = copy.deepcopy(obj)
541546
attrs = {}
542547
if parsed_args.dns_nameservers:
543-
try:
544-
_update_arguments(tmp_obj.dns_nameservers,
545-
parsed_args.dns_nameservers)
546-
except ValueError as error:
547-
msg = (_("%s not in dns-nameservers") % str(error))
548-
raise exceptions.CommandError(msg)
548+
_update_arguments(tmp_obj.dns_nameservers,
549+
parsed_args.dns_nameservers,
550+
'dns-nameserver')
549551
attrs['dns_nameservers'] = tmp_obj.dns_nameservers
550552
if parsed_args.host_routes:
551-
try:
552-
_update_arguments(
553-
tmp_obj.host_routes,
554-
convert_entries_to_nexthop(parsed_args.host_routes))
555-
except ValueError as error:
556-
msg = (_("Subnet does not have %s in host-routes") %
557-
str(error))
558-
raise exceptions.CommandError(msg)
553+
_update_arguments(
554+
tmp_obj.host_routes,
555+
convert_entries_to_nexthop(parsed_args.host_routes),
556+
'host-route')
559557
attrs['host_routes'] = tmp_obj.host_routes
560558
if parsed_args.allocation_pools:
561-
try:
562-
_update_arguments(tmp_obj.allocation_pools,
563-
parsed_args.allocation_pools)
564-
except ValueError as error:
565-
msg = (_("Subnet does not have %s in allocation-pools") %
566-
str(error))
567-
raise exceptions.CommandError(msg)
559+
_update_arguments(tmp_obj.allocation_pools,
560+
parsed_args.allocation_pools,
561+
'allocation-pool')
568562
attrs['allocation_pools'] = tmp_obj.allocation_pools
569563
if parsed_args.service_types:
570-
try:
571-
_update_arguments(tmp_obj.service_types,
572-
parsed_args.service_types)
573-
except ValueError as error:
574-
msg = (_("%s not in service-types") % str(error))
575-
raise exceptions.CommandError(msg)
564+
_update_arguments(tmp_obj.service_types,
565+
parsed_args.service_types,
566+
'service-type')
576567
attrs['service_types'] = tmp_obj.service_types
577568
if attrs:
578569
client.update_subnet(obj, **attrs)

0 commit comments

Comments
 (0)