From 55d2a30ee7310ba590ab34066f7e6fff24132145 Mon Sep 17 00:00:00 2001 From: Shih-Hao Li Date: Mon, 26 Sep 2016 19:20:59 -0700 Subject: [PATCH] NSXv3: Fix attachment setting during create_port and update_port This patch adds logic to distinguish when to reset or make no change on the attachment in the backend during create_port and update_port. Change-Id: I46017a9756d807267b489e32bfdd20b4a2f65800 --- vmware_nsx/nsxlib/v3/resources.py | 7 +++++- vmware_nsx/plugins/nsx_v3/plugin.py | 36 +++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/vmware_nsx/nsxlib/v3/resources.py b/vmware_nsx/nsxlib/v3/resources.py index a19b569633..fd24c8925f 100644 --- a/vmware_nsx/nsxlib/v3/resources.py +++ b/vmware_nsx/nsxlib/v3/resources.py @@ -241,7 +241,8 @@ class LogicalPort(AbstractRESTResource): body['switching_profile_ids'] = profiles # Note that attachment could be None, meaning reset it. - body['attachment'] = attachment + if attachment is not False: + body['attachment'] = attachment return body @@ -256,6 +257,10 @@ class LogicalPort(AbstractRESTResource): 'resource_type': nsx_constants.CIF_RESOURCE_TYPE} attachment['context'] = context return attachment + elif attachment_type is None or vif_uuid is None: + return None # reset attachment + else: + return False # no attachment change def create(self, lswitch_id, vif_uuid, tags=None, attachment_type=nsx_constants.ATTACHMENT_VIF, diff --git a/vmware_nsx/plugins/nsx_v3/plugin.py b/vmware_nsx/plugins/nsx_v3/plugin.py index 04c5544c84..ee4577da7f 100644 --- a/vmware_nsx/plugins/nsx_v3/plugin.py +++ b/vmware_nsx/plugins/nsx_v3/plugin.py @@ -1276,17 +1276,25 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, context, port_data) address_bindings = (self._build_address_bindings(port_data) if psec_is_on else []) - vif_uuid = port_data['id'] - attachment_type = nsx_constants.ATTACHMENT_VIF - if not device_owner or device_owner == l3_db.DEVICE_OWNER_ROUTER_INTF: + + if not device_owner: + # no attachment attachment_type = None vif_uuid = None - # Change the attachment type for L2 gateway owned ports. - if l2gw_port_check: + elif l2gw_port_check: + # Change the attachment type for L2 gateway owned ports. # NSX backend requires the vif id be set to bridge endpoint id # for ports plugged into a Bridge Endpoint. vif_uuid = device_id attachment_type = device_owner + elif device_owner == l3_db.DEVICE_OWNER_ROUTER_INTF: + # no attachment change + attachment_type = False + vif_uuid = False + else: + # default attachment + attachment_type = nsx_constants.ATTACHMENT_VIF + vif_uuid = port_data['id'] profiles = [] if psec_is_on and address_bindings: @@ -1861,13 +1869,21 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, tags_update = utils.add_v3_tag(tags_update, resource_type, updated_device_id) - vif_uuid = updated_port['id'] parent_vif_id, tag = self._get_data_from_binding_profile( context, updated_port) - attachment_type = nsx_constants.ATTACHMENT_VIF - if (not updated_device_owner or - updated_device_owner in (l3_db.DEVICE_OWNER_ROUTER_INTF, - nsx_constants.BRIDGE_ENDPOINT)): + + if updated_device_owner in (original_device_owner, + l3_db.DEVICE_OWNER_ROUTER_INTF, + nsx_constants.BRIDGE_ENDPOINT): + # no attachment change + attachment_type = False + vif_uuid = False + elif updated_device_owner: + # default attachment + attachment_type = nsx_constants.ATTACHMENT_VIF + vif_uuid = updated_port['id'] + else: + # no attachment attachment_type = None vif_uuid = None