|
28 | 28 | LOG = logging.getLogger(__name__) |
29 | 29 |
|
30 | 30 |
|
31 | | -def _update_arguments(obj_list, parsed_args_list): |
| 31 | +def _update_arguments(obj_list, parsed_args_list, option): |
32 | 32 | 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) |
34 | 39 |
|
35 | 40 |
|
36 | 41 | def _format_allocation_pools(data): |
@@ -493,17 +498,17 @@ def get_parser(self, prog_name): |
493 | 498 | dest='allocation_pools', |
494 | 499 | action=parseractions.MultiKeyValueAction, |
495 | 500 | 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)') |
499 | 504 | ) |
500 | 505 | parser.add_argument( |
501 | 506 | '--dns-nameserver', |
502 | 507 | metavar='<dns-nameserver>', |
503 | 508 | action='append', |
504 | 509 | dest='dns_nameservers', |
505 | 510 | 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)') |
507 | 512 | ) |
508 | 513 | parser.add_argument( |
509 | 514 | '--host-route', |
@@ -540,39 +545,25 @@ def take_action(self, parsed_args): |
540 | 545 | tmp_obj = copy.deepcopy(obj) |
541 | 546 | attrs = {} |
542 | 547 | 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') |
549 | 551 | attrs['dns_nameservers'] = tmp_obj.dns_nameservers |
550 | 552 | 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') |
559 | 557 | attrs['host_routes'] = tmp_obj.host_routes |
560 | 558 | 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') |
568 | 562 | attrs['allocation_pools'] = tmp_obj.allocation_pools |
569 | 563 | 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') |
576 | 567 | attrs['service_types'] = tmp_obj.service_types |
577 | 568 | if attrs: |
578 | 569 | client.update_subnet(obj, **attrs) |
0 commit comments