@@ -109,7 +109,6 @@ def _get_attrs(client_manager, parsed_args):
109109 'The --host-id option is deprecated, '
110110 'please use --host instead.'
111111 ))
112-
113112 if parsed_args .fixed_ip is not None :
114113 attrs ['fixed_ips' ] = parsed_args .fixed_ip
115114 if parsed_args .device :
@@ -428,8 +427,7 @@ def get_parser(self, prog_name):
428427 metavar = "<name>" ,
429428 help = _ ("Set port name" )
430429 )
431- fixed_ip = parser .add_mutually_exclusive_group ()
432- fixed_ip .add_argument (
430+ parser .add_argument (
433431 '--fixed-ip' ,
434432 metavar = 'subnet=<subnet>,ip-address=<ip-address>' ,
435433 action = parseractions .MultiKeyValueAction ,
@@ -438,24 +436,27 @@ def get_parser(self, prog_name):
438436 "subnet=<subnet>,ip-address=<ip-address> "
439437 "(repeat option to set multiple fixed IP addresses)" )
440438 )
441- fixed_ip .add_argument (
439+ parser .add_argument (
442440 '--no-fixed-ip' ,
443441 action = 'store_true' ,
444- help = _ ("Clear existing information of fixed IP addresses" )
442+ help = _ ("Clear existing information of fixed IP addresses."
443+ "Specify both --fixed-ip and --no-fixed-ip "
444+ "to overwrite the current fixed IP addresses." )
445445 )
446- binding_profile = parser .add_mutually_exclusive_group ()
447- binding_profile .add_argument (
446+ parser .add_argument (
448447 '--binding-profile' ,
449448 metavar = '<binding-profile>' ,
450449 action = JSONKeyValueAction ,
451450 help = _ ("Custom data to be passed as binding:profile. Data may "
452451 "be passed as <key>=<value> or JSON. "
453452 "(repeat option to set multiple binding:profile data)" )
454453 )
455- binding_profile .add_argument (
454+ parser .add_argument (
456455 '--no-binding-profile' ,
457456 action = 'store_true' ,
458- help = _ ("Clear existing information of binding:profile" )
457+ help = _ ("Clear existing information of binding:profile."
458+ "Specify both --binding-profile and --no-binding-profile "
459+ "to overwrite the current binding:profile information." )
459460 )
460461 parser .add_argument (
461462 'port' ,
@@ -471,7 +472,11 @@ def take_action(self, parsed_args):
471472 attrs = _get_attrs (self .app .client_manager , parsed_args )
472473 obj = client .find_port (parsed_args .port , ignore_missing = False )
473474 if 'binding:profile' in attrs :
474- attrs ['binding:profile' ].update (obj .binding_profile )
475+ # Do not modify attrs if both binding_profile/no_binding given
476+ if not parsed_args .no_binding_profile :
477+ tmp_binding_profile = copy .deepcopy (obj .binding_profile )
478+ tmp_binding_profile .update (attrs ['binding:profile' ])
479+ attrs ['binding:profile' ] = tmp_binding_profile
475480 elif parsed_args .no_binding_profile :
476481 attrs ['binding:profile' ] = {}
477482 if 'fixed_ips' in attrs :
@@ -480,7 +485,9 @@ def take_action(self, parsed_args):
480485 # would therefore add an empty dictionary, while we need
481486 # to append the attrs['fixed_ips'] iff there is some info
482487 # in the obj.fixed_ips. Therefore I have opted for this `for` loop
483- attrs ['fixed_ips' ] += [ip for ip in obj .fixed_ips if ip ]
488+ # Do not modify attrs if fixed_ip/no_fixed_ip given
489+ if not parsed_args .no_fixed_ip :
490+ attrs ['fixed_ips' ] += [ip for ip in obj .fixed_ips if ip ]
484491 elif parsed_args .no_fixed_ip :
485492 attrs ['fixed_ips' ] = []
486493
0 commit comments