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
This commit is contained in:
Shih-Hao Li 2016-09-26 19:20:59 -07:00
parent 9959d18f44
commit 55d2a30ee7
2 changed files with 32 additions and 11 deletions

View File

@ -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,

View File

@ -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