@@ -114,8 +114,6 @@ def _get_attrs(client_manager, parsed_args):
114114 ))
115115 if parsed_args .description is not None :
116116 attrs ['description' ] = parsed_args .description
117- if parsed_args .fixed_ip is not None :
118- attrs ['fixed_ips' ] = parsed_args .fixed_ip
119117 if parsed_args .device :
120118 attrs ['device_id' ] = parsed_args .device
121119 if parsed_args .device_owner is not None :
@@ -124,8 +122,6 @@ def _get_attrs(client_manager, parsed_args):
124122 attrs ['admin_state_up' ] = True
125123 if parsed_args .disable :
126124 attrs ['admin_state_up' ] = False
127- if parsed_args .binding_profile is not None :
128- attrs ['binding:profile' ] = parsed_args .binding_profile
129125 if parsed_args .vnic_type is not None :
130126 attrs ['binding:vnic_type' ] = parsed_args .vnic_type
131127 if parsed_args .host :
@@ -389,13 +385,20 @@ def take_action(self, parsed_args):
389385 _prepare_fixed_ips (self .app .client_manager , parsed_args )
390386 attrs = _get_attrs (self .app .client_manager , parsed_args )
391387
388+ if parsed_args .binding_profile is not None :
389+ attrs ['binding:profile' ] = parsed_args .binding_profile
390+
391+ if parsed_args .fixed_ip :
392+ attrs ['fixed_ips' ] = parsed_args .fixed_ip
393+
392394 if parsed_args .security_group :
393395 attrs ['security_group_ids' ] = [client .find_security_group (
394396 sg , ignore_missing = False ).id
395397 for sg in
396398 parsed_args .security_group ]
397399 elif parsed_args .no_security_group :
398400 attrs ['security_group_ids' ] = []
401+
399402 if parsed_args .allowed_address_pairs :
400403 attrs ['allowed_address_pairs' ] = (
401404 _convert_address_pairs (parsed_args ))
@@ -674,48 +677,50 @@ def take_action(self, parsed_args):
674677 _prepare_fixed_ips (self .app .client_manager , parsed_args )
675678 attrs = _get_attrs (self .app .client_manager , parsed_args )
676679 obj = client .find_port (parsed_args .port , ignore_missing = False )
677- if 'binding:profile' in attrs :
678- # Do not modify attrs if both binding_profile/no_binding given
679- if not parsed_args .no_binding_profile :
680- tmp_binding_profile = copy .deepcopy (obj .binding_profile )
681- tmp_binding_profile .update (attrs ['binding:profile' ])
682- attrs ['binding:profile' ] = tmp_binding_profile
683- elif parsed_args .no_binding_profile :
684- attrs ['binding:profile' ] = {}
685- if 'fixed_ips' in attrs :
686- # When user unsets the fixed_ips, obj.fixed_ips = [{}].
687- # Adding the obj.fixed_ips list to attrs['fixed_ips']
688- # would therefore add an empty dictionary, while we need
689- # to append the attrs['fixed_ips'] iff there is some info
690- # in the obj.fixed_ips. Therefore I have opted for this `for` loop
691- # Do not modify attrs if fixed_ip/no_fixed_ip given
692- if not parsed_args .no_fixed_ip :
693- attrs ['fixed_ips' ] += [ip for ip in obj .fixed_ips if ip ]
694- elif parsed_args .no_fixed_ip :
695- attrs ['fixed_ips' ] = []
696680
697- if parsed_args .security_group :
698- attrs ['security_group_ids ' ] = [
699- client . find_security_group ( sg , ignore_missing = False ). id for
700- sg in parsed_args . security_group ]
701- if not parsed_args . no_security_group :
702- attrs ['security_group_ids' ] += obj . security_group_ids
681+ if parsed_args .no_binding_profile :
682+ attrs ['binding:profile ' ] = {}
683+ if parsed_args . binding_profile :
684+ if 'binding:profile' not in attrs :
685+ attrs [ 'binding:profile' ] = copy . deepcopy ( obj . binding_profile )
686+ attrs ['binding:profile' ]. update ( parsed_args . binding_profile )
703687
704- elif parsed_args .no_security_group :
688+ if parsed_args .no_fixed_ip :
689+ attrs ['fixed_ips' ] = []
690+ if parsed_args .fixed_ip :
691+ if 'fixed_ips' not in attrs :
692+ # obj.fixed_ips = [{}] if no fixed IPs are set.
693+ # Only append this to attrs['fixed_ips'] if actual fixed
694+ # IPs are present to avoid adding an empty dict.
695+ attrs ['fixed_ips' ] = [ip for ip in obj .fixed_ips if ip ]
696+ attrs ['fixed_ips' ].extend (parsed_args .fixed_ip )
697+
698+ if parsed_args .no_security_group :
705699 attrs ['security_group_ids' ] = []
706-
707- if (parsed_args .allowed_address_pairs and
708- parsed_args .no_allowed_address_pair ):
709- attrs ['allowed_address_pairs' ] = (
710- _convert_address_pairs (parsed_args ))
711-
712- elif parsed_args .allowed_address_pairs :
713- attrs ['allowed_address_pairs' ] = (
714- [addr for addr in obj .allowed_address_pairs if addr ] +
715- _convert_address_pairs (parsed_args ))
716-
717- elif parsed_args .no_allowed_address_pair :
700+ if parsed_args .security_group :
701+ if 'security_group_ids' not in attrs :
702+ # NOTE(dtroyer): Get existing security groups, iterate the
703+ # list to force a new list object to be
704+ # created and make sure the SDK Resource
705+ # marks the attribute 'dirty'.
706+ attrs ['security_group_ids' ] = [
707+ id for id in obj .security_group_ids
708+ ]
709+ attrs ['security_group_ids' ].extend (
710+ client .find_security_group (sg , ignore_missing = False ).id
711+ for sg in parsed_args .security_group
712+ )
713+
714+ if parsed_args .no_allowed_address_pair :
718715 attrs ['allowed_address_pairs' ] = []
716+ if parsed_args .allowed_address_pairs :
717+ if 'allowed_address_pairs' not in attrs :
718+ attrs ['allowed_address_pairs' ] = (
719+ [addr for addr in obj .allowed_address_pairs if addr ]
720+ )
721+ attrs ['allowed_address_pairs' ].extend (
722+ _convert_address_pairs (parsed_args )
723+ )
719724
720725 client .update_port (obj , ** attrs )
721726
0 commit comments