@@ -143,25 +143,34 @@ def _get_remove_mappings(self, req_to_modes, vm):
143143 if ACTION_TYPE_REMOVE_VLAN in req_to_modes :
144144 for mode , actions in req_to_modes [ACTION_TYPE_REMOVE_VLAN ].items ():
145145 for action in actions :
146- interface_attributes = \
147- [attr .attributeValue for attr in action .connectorAttributes
148- if attr .attributeName == INTERFACE ]
149- for interface_attribute in interface_attributes :
146+ macs = self ._get_macs_from_action (action )
147+ for mac in macs :
150148 vm_network_remove_mapping = VmNetworkRemoveMapping ()
151- vm_network_remove_mapping .mac_address = interface_attribute
149+ vm_network_remove_mapping .mac_address = mac
152150 vm_network_remove_mapping .vm_uuid = vm
153151 remove_mappings .append (vm_network_remove_mapping )
154152 return remove_mappings
155153
154+ def _get_macs_from_action (self , action ):
155+ interface_attributes = \
156+ [attr .attributeValue for attr in action .connectorAttributes
157+ if attr .attributeName == INTERFACE ]
158+ macs = []
159+ for interface_attribute in interface_attributes :
160+ macs += self ._split_names (interface_attribute )
161+ return macs
162+
156163 def _get_set_mappings (self , req_to_modes ):
157164 set_mappings = []
158165 if ACTION_TYPE_SET_VLAN in req_to_modes :
159166 set_requests = req_to_modes [ACTION_TYPE_SET_VLAN ]
160167 for mode , actions in set_requests .items ():
161168 for action in actions :
162169 vnic_name = self ._get_vnic_name (action )
163- vnic_to_network = self ._create_map (action .connectionParams .vlanId , mode , vnic_name )
164- set_mappings .append (vnic_to_network )
170+ vnic_names = self ._split_names (vnic_name )
171+ for name in vnic_names :
172+ vnic_to_network = self ._create_map (action .connectionParams .vlanId , mode , name )
173+ set_mappings .append (vnic_to_network )
165174
166175 # this line makes sure that the vNICS with names are first
167176 return sorted (set_mappings , key = lambda x : x .vnic_name , reverse = True )
@@ -220,7 +229,7 @@ def _set_vlan(self, action_mappings, si, vm_uuid, logger):
220229 for action in actions :
221230 error_result = self ._create_error_action_res (action , e )
222231 results .append (error_result )
223-
232+ results = self . _consolidate_duplicate_results ( results )
224233 return results
225234
226235 def _prepare_connection_results_for_extraction (self , connection_results ):
@@ -256,7 +265,20 @@ def _get_set_vlan_result_suc(self, act_by_mode_by_vlan_by_nic, connection_res_ma
256265 result .type = ACTION_TYPE_SET_VLAN
257266 result .updatedInterface = res .mac_address
258267 results .append (result )
259- return results
268+ final_res = self ._consolidate_duplicate_results (results )
269+ return final_res
270+
271+ def _consolidate_duplicate_results (self , results ):
272+ mapping = dict ()
273+ final_res = []
274+ for result in results :
275+ self ._add_safely_to_dict (value = result , dictionary = mapping , key = result .actionId )
276+ for action_id , actions in mapping .items ():
277+ final_act = actions [0 ]
278+ for action in actions [1 :]:
279+ final_act .updatedInterface = '{0},{1}' .format (final_act .updatedInterface , action .updatedInterface )
280+ final_res .append (final_act )
281+ return final_res
260282
261283 def _group_actions_by_vlan_by_vnic (self , set_actions_grouped_by_vlan_id ):
262284 set_act_group_by_mode_by_vlan_by_requsted_vnic = dict ()
@@ -266,12 +288,21 @@ def _group_actions_by_vlan_by_vnic(self, set_actions_grouped_by_vlan_id):
266288 set_act_group_by_mode_by_vlan_by_requsted_vnic [mode ][vlan_id ] = dict ()
267289 for action in actions :
268290 name = self ._get_vnic_name (action )
269- self ._add_safely_to_dict (
270- dictionary = set_act_group_by_mode_by_vlan_by_requsted_vnic [mode ][vlan_id ],
271- key = name ,
272- value = action )
291+ names = self ._split_names (name )
292+ for v_name in names :
293+ self ._add_safely_to_dict (
294+ dictionary = set_act_group_by_mode_by_vlan_by_requsted_vnic [mode ][vlan_id ],
295+ key = v_name ,
296+ value = action )
273297 return set_act_group_by_mode_by_vlan_by_requsted_vnic
274298
299+ @staticmethod
300+ def _split_names (name ):
301+ if not name :
302+ return [name ]
303+
304+ return [v_name for v_name in name .strip ().split (',' ) if v_name ]
305+
275306 def _group_action_by_vlan_id (self , set_vlan_actions ):
276307 set_actions_grouped_by_vlan_id = dict ()
277308 for mode , actions in set_vlan_actions .items ():
@@ -282,8 +313,7 @@ def _group_action_by_vlan_id(self, set_vlan_actions):
282313 return set_actions_grouped_by_vlan_id
283314
284315 def _remove_vlan (self , action_mappings , si , vm_uuid , logger ):
285-
286- results = []
316+ final_res = []
287317 mode_to_actions = action_mappings .action_tree [ACTION_TYPE_REMOVE_VLAN ]
288318 try :
289319 self .logger .info ('disconnecting vm({0})' .format (vm_uuid ))
@@ -299,9 +329,10 @@ def _remove_vlan(self, action_mappings, si, vm_uuid, logger):
299329 interface_to_action = dict ()
300330 for mode , actions in mode_to_actions .items ():
301331 for action in actions :
302- name = self ._get_mac (action )
303- interface_to_action [name ] = action
304-
332+ names = self ._get_macs_from_action (action )
333+ for name in names :
334+ interface_to_action [name ] = action
335+ results = []
305336 for res in connection_results :
306337 action = interface_to_action [res .vnic_mac ]
307338 action_result = ActionResult ()
@@ -312,13 +343,15 @@ def _remove_vlan(self, action_mappings, si, vm_uuid, logger):
312343 action_result .errorMessage = None
313344 action_result .updatedInterface = res .vnic_mac
314345 results .append (action_result )
346+ final_res = self ._consolidate_duplicate_results (results )
315347 except Exception as e :
316348 self .logger .error ('Exception raised while disconnecting vm({0}) with exception: {1}' .format (vm_uuid , e ))
317349 for mode , actions in mode_to_actions .items ():
318350 for action in actions :
319351 error_result = self ._create_error_action_res (action , e )
320- results .append (error_result )
321- return results
352+ final_res .append (error_result )
353+ final_res = self ._consolidate_duplicate_results (final_res )
354+ return final_res
322355
323356 @staticmethod
324357 def _create_error_action_res (action , e ):
0 commit comments