NSX|V3: ensure that port update allows traffic
Ensure that when a port is update that the VIF attachment is also updated. This allows traffic to be sent to and from the instance. Change-Id: Id031bdd3e5a37d3b5b9da2fb7ec34290adf7cabe Closes-bug: #1533198
This commit is contained in:
parent
6eccbe5ec7
commit
2172dee816
@ -174,7 +174,8 @@ class LogicalPort(AbstractRESTResource):
|
|||||||
self, display_name=None,
|
self, display_name=None,
|
||||||
admin_state=True, tags=None,
|
admin_state=True, tags=None,
|
||||||
address_bindings=None,
|
address_bindings=None,
|
||||||
switch_profile_ids=None):
|
switch_profile_ids=None,
|
||||||
|
attachment=None):
|
||||||
tags = tags or []
|
tags = tags or []
|
||||||
address_bindings = address_bindings or []
|
address_bindings = address_bindings or []
|
||||||
switch_profile_ids = switch_profile_ids or []
|
switch_profile_ids = switch_profile_ids or []
|
||||||
@ -211,15 +212,13 @@ class LogicalPort(AbstractRESTResource):
|
|||||||
})
|
})
|
||||||
body['switching_profile_ids'] = profiles
|
body['switching_profile_ids'] = profiles
|
||||||
|
|
||||||
|
if attachment:
|
||||||
|
body['attachment'] = attachment
|
||||||
|
|
||||||
return body
|
return body
|
||||||
|
|
||||||
def create(self, lswitch_id, vif_uuid, tags=None,
|
def _prepare_attachment(self, vif_uuid, parent_name, parent_tag,
|
||||||
attachment_type=nsx_constants.ATTACHMENT_VIF,
|
address_bindings, attachment_type):
|
||||||
admin_state=True, name=None, address_bindings=None,
|
|
||||||
parent_name=None, parent_tag=None,
|
|
||||||
switch_profile_ids=None):
|
|
||||||
tags = tags or []
|
|
||||||
|
|
||||||
# NOTE(arosen): if a parent_name is specified we need to use the
|
# NOTE(arosen): if a parent_name is specified we need to use the
|
||||||
# CIF's attachment.
|
# CIF's attachment.
|
||||||
key_values = None
|
key_values = None
|
||||||
@ -233,21 +232,33 @@ class LogicalPort(AbstractRESTResource):
|
|||||||
# NOTE(arosen): The above api body structure might change
|
# NOTE(arosen): The above api body structure might change
|
||||||
# in the future
|
# in the future
|
||||||
|
|
||||||
body = {'logical_switch_id': lswitch_id}
|
|
||||||
if attachment_type and vif_uuid:
|
if attachment_type and vif_uuid:
|
||||||
body['attachment'] = {'attachment_type': attachment_type,
|
attachment = {'attachment_type': attachment_type,
|
||||||
'id': vif_uuid}
|
'id': vif_uuid}
|
||||||
|
|
||||||
if key_values:
|
if key_values:
|
||||||
body['attachment']['context'] = {'key_values': key_values}
|
attachment['context'] = {'key_values': key_values}
|
||||||
body['attachment']['context']['resource_type'] = \
|
attachment['context']['resource_type'] = \
|
||||||
nsx_constants.CIF_RESOURCE_TYPE
|
nsx_constants.CIF_RESOURCE_TYPE
|
||||||
|
return attachment
|
||||||
|
|
||||||
|
def create(self, lswitch_id, vif_uuid, tags=None,
|
||||||
|
attachment_type=nsx_constants.ATTACHMENT_VIF,
|
||||||
|
admin_state=True, name=None, address_bindings=None,
|
||||||
|
parent_name=None, parent_tag=None,
|
||||||
|
switch_profile_ids=None):
|
||||||
|
tags = tags or []
|
||||||
|
|
||||||
|
body = {'logical_switch_id': lswitch_id}
|
||||||
|
attachment = self._prepare_attachment(vif_uuid, parent_name,
|
||||||
|
parent_tag, address_bindings,
|
||||||
|
attachment_type)
|
||||||
body.update(self._build_body_attrs(
|
body.update(self._build_body_attrs(
|
||||||
display_name=name,
|
display_name=name,
|
||||||
admin_state=admin_state, tags=tags,
|
admin_state=admin_state, tags=tags,
|
||||||
address_bindings=address_bindings,
|
address_bindings=address_bindings,
|
||||||
switch_profile_ids=switch_profile_ids))
|
switch_profile_ids=switch_profile_ids,
|
||||||
|
attachment=attachment))
|
||||||
return self._client.create(body=body)
|
return self._client.create(body=body)
|
||||||
|
|
||||||
def delete(self, lport_id):
|
def delete(self, lport_id):
|
||||||
@ -256,18 +267,25 @@ class LogicalPort(AbstractRESTResource):
|
|||||||
@utils.retry_upon_exception_nsxv3(
|
@utils.retry_upon_exception_nsxv3(
|
||||||
nsx_exc.StaleRevision,
|
nsx_exc.StaleRevision,
|
||||||
max_attempts=cfg.CONF.nsx_v3.retries)
|
max_attempts=cfg.CONF.nsx_v3.retries)
|
||||||
def update(self, lport_id, name=None, admin_state=None,
|
def update(self, lport_id, vif_uuid,
|
||||||
|
name=None, admin_state=None,
|
||||||
address_bindings=None, switch_profile_ids=None,
|
address_bindings=None, switch_profile_ids=None,
|
||||||
resources=None):
|
resources=None,
|
||||||
|
attachment_type=nsx_constants.ATTACHMENT_VIF,
|
||||||
|
parent_name=None, parent_tag=None):
|
||||||
lport = self.get(lport_id)
|
lport = self.get(lport_id)
|
||||||
tags = lport.get('tags', [])
|
tags = lport.get('tags', [])
|
||||||
if resources:
|
if resources:
|
||||||
tags = utils.update_v3_tags(tags, resources)
|
tags = utils.update_v3_tags(tags, resources)
|
||||||
|
attachment = self._prepare_attachment(vif_uuid, parent_name,
|
||||||
|
parent_tag, address_bindings,
|
||||||
|
attachment_type)
|
||||||
lport.update(self._build_body_attrs(
|
lport.update(self._build_body_attrs(
|
||||||
display_name=name,
|
display_name=name,
|
||||||
admin_state=admin_state, tags=tags,
|
admin_state=admin_state, tags=tags,
|
||||||
address_bindings=address_bindings,
|
address_bindings=address_bindings,
|
||||||
switch_profile_ids=switch_profile_ids))
|
switch_profile_ids=switch_profile_ids,
|
||||||
|
attachment=attachment))
|
||||||
|
|
||||||
# If revision_id of the payload that we send is older than what NSX has
|
# If revision_id of the payload that we send is older than what NSX has
|
||||||
# then we will get a 412: Precondition Failed. In that case we need to
|
# then we will get a 412: Precondition Failed. In that case we need to
|
||||||
|
@ -852,12 +852,30 @@ class NsxV3Plugin(addr_pair_db.AllowedAddressPairsMixin,
|
|||||||
resources = [{'resource_type': resource_type,
|
resources = [{'resource_type': resource_type,
|
||||||
'tag': updated_device_id}]
|
'tag': updated_device_id}]
|
||||||
|
|
||||||
|
vif_uuid = updated_port['id']
|
||||||
|
parent_name, 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)):
|
||||||
|
attachment_type = None
|
||||||
|
vif_uuid = None
|
||||||
|
|
||||||
|
if updated_device_owner.startswith(const.DEVICE_OWNER_COMPUTE_PREFIX):
|
||||||
|
name = 'instance-port_%s' % updated_port['id']
|
||||||
|
else:
|
||||||
|
name = updated_port.get('name')
|
||||||
|
|
||||||
self._port_client.update(
|
self._port_client.update(
|
||||||
lport_id, name=updated_port.get('name'),
|
lport_id, vif_uuid, name=name,
|
||||||
|
attachment_type=attachment_type,
|
||||||
admin_state=updated_port.get('admin_state_up'),
|
admin_state=updated_port.get('admin_state_up'),
|
||||||
address_bindings=address_bindings,
|
address_bindings=address_bindings,
|
||||||
switch_profile_ids=switch_profile_ids,
|
switch_profile_ids=switch_profile_ids,
|
||||||
resources=resources)
|
resources=resources,
|
||||||
|
parent_name=parent_name,
|
||||||
|
parent_tag=tag)
|
||||||
|
|
||||||
security.update_lport_with_security_groups(
|
security.update_lport_with_security_groups(
|
||||||
context, lport_id,
|
context, lport_id,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user