From b38be94a5d82eb88d27c81e697152ad064854466 Mon Sep 17 00:00:00 2001 From: reedip Date: Wed, 20 Apr 2016 17:31:52 +0900 Subject: Introduce overwrite functionality in ``osc port set`` The overwrite functionality allows user to overwrite either the binding-profile or the fixed-ips of a specific port. Change-Id: I8ec3d04eeaf28972ee545fcdda4d5f7bd9deb915 partially-implements: blueprint allow-overwrite-set-options --- openstackclient/network/v2/port.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'openstackclient/network') diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py index 05c5a012..b3634eb7 100644 --- a/openstackclient/network/v2/port.py +++ b/openstackclient/network/v2/port.py @@ -109,7 +109,6 @@ def _get_attrs(client_manager, parsed_args): 'The --host-id option is deprecated, ' 'please use --host instead.' )) - if parsed_args.fixed_ip is not None: attrs['fixed_ips'] = parsed_args.fixed_ip if parsed_args.device: @@ -409,8 +408,7 @@ class SetPort(command.Command): metavar="", help=_("Set port name") ) - fixed_ip = parser.add_mutually_exclusive_group() - fixed_ip.add_argument( + parser.add_argument( '--fixed-ip', metavar='subnet=,ip-address=', action=parseractions.MultiKeyValueAction, @@ -419,13 +417,14 @@ class SetPort(command.Command): "subnet=,ip-address= " "(repeat option to set multiple fixed IP addresses)") ) - fixed_ip.add_argument( + parser.add_argument( '--no-fixed-ip', action='store_true', - help=_("Clear existing information of fixed IP addresses") + help=_("Clear existing information of fixed IP addresses." + "Specify both --fixed-ip and --no-fixed-ip " + "to overwrite the current fixed IP addresses.") ) - binding_profile = parser.add_mutually_exclusive_group() - binding_profile.add_argument( + parser.add_argument( '--binding-profile', metavar='', action=JSONKeyValueAction, @@ -433,10 +432,12 @@ class SetPort(command.Command): "be passed as = or JSON. " "(repeat option to set multiple binding:profile data)") ) - binding_profile.add_argument( + parser.add_argument( '--no-binding-profile', action='store_true', - help=_("Clear existing information of binding:profile") + help=_("Clear existing information of binding:profile." + "Specify both --binding-profile and --no-binding-profile " + "to overwrite the current binding:profile information.") ) parser.add_argument( 'port', @@ -452,7 +453,11 @@ class SetPort(command.Command): attrs = _get_attrs(self.app.client_manager, parsed_args) obj = client.find_port(parsed_args.port, ignore_missing=False) if 'binding:profile' in attrs: - attrs['binding:profile'].update(obj.binding_profile) + # Do not modify attrs if both binding_profile/no_binding given + if not parsed_args.no_binding_profile: + tmp_binding_profile = copy.deepcopy(obj.binding_profile) + tmp_binding_profile.update(attrs['binding:profile']) + attrs['binding:profile'] = tmp_binding_profile elif parsed_args.no_binding_profile: attrs['binding:profile'] = {} if 'fixed_ips' in attrs: @@ -461,7 +466,9 @@ class SetPort(command.Command): # would therefore add an empty dictionary, while we need # to append the attrs['fixed_ips'] iff there is some info # in the obj.fixed_ips. Therefore I have opted for this `for` loop - attrs['fixed_ips'] += [ip for ip in obj.fixed_ips if ip] + # Do not modify attrs if fixed_ip/no_fixed_ip given + if not parsed_args.no_fixed_ip: + attrs['fixed_ips'] += [ip for ip in obj.fixed_ips if ip] elif parsed_args.no_fixed_ip: attrs['fixed_ips'] = [] -- cgit v1.2.1