NSX|P: Do not use transactional apis if not supported

Creating a segment port with transactional APIs resets the segment name
if partial updates is not yet supported

Change-Id: I3036227149c35c135d26469a90506f543d08dd2f
This commit is contained in:
asarfaty 2020-03-03 09:21:12 +02:00 committed by Adit Sarfaty
parent d1f41da8b5
commit 4f9acdfb5e
1 changed files with 36 additions and 21 deletions

View File

@ -1422,6 +1422,29 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
return tags
def _do_port_backend_calls(self, name, segment_id,
spoofguard_profile, seg_sec_profile,
mac_discovery_profile, qos_policy_id, **kwargs):
self.nsxpolicy.segment_port.create_or_overwrite(
name, segment_id, **kwargs)
# add the security profiles to the port
self.nsxpolicy.segment_port_security_profiles.create_or_overwrite(
name, segment_id, port_id=kwargs['port_id'],
spoofguard_profile_id=spoofguard_profile,
segment_security_profile_id=seg_sec_profile)
# add the mac discovery profile to the port
self.nsxpolicy.segment_port_discovery_profiles.create_or_overwrite(
name, segment_id, kwargs['port_id'],
mac_discovery_profile_id=mac_discovery_profile)
# Add QoS segment profile (only if QoS is enabled)
if directory.get_plugin(plugin_const.QOS):
self.nsxpolicy.segment_port_qos_profiles.create_or_overwrite(
name, segment_id, kwargs['port_id'],
qos_profile_id=qos_policy_id)
def _create_or_update_port_on_backend(self, context, port_data, is_psec_on,
qos_policy_id, original_port=None):
is_create = original_port is None
@ -1495,27 +1518,19 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
'admin_state_up' in port_data):
kwargs['admin_state'] = port_data['admin_state_up']
# Create/ update the backend port in a single transaction
with policy_trans.NsxPolicyTransaction():
self.nsxpolicy.segment_port.create_or_overwrite(
name, segment_id, **kwargs)
# add the security profiles to the port
self.nsxpolicy.segment_port_security_profiles.create_or_overwrite(
name, segment_id, port_data['id'],
spoofguard_profile_id=spoofguard_profile,
segment_security_profile_id=seg_sec_profile)
# add the mac discovery profile to the port
self.nsxpolicy.segment_port_discovery_profiles.create_or_overwrite(
name, segment_id, port_data['id'],
mac_discovery_profile_id=mac_discovery_profile)
# Add QoS segment profile (only if QoS is enabled)
if directory.get_plugin(plugin_const.QOS):
self.nsxpolicy.segment_port_qos_profiles.create_or_overwrite(
name, segment_id, port_data['id'],
qos_profile_id=qos_policy_id)
if not self.nsxpolicy.feature_supported(
nsxlib_consts.FEATURE_PARTIAL_UPDATES):
# If partial updates are not supported, using transactions will
# reset the backend segment name
self._do_port_backend_calls(
name, segment_id, spoofguard_profile, seg_sec_profile,
mac_discovery_profile, qos_policy_id, **kwargs)
else:
# Create/ update the backend port in a single transaction
with policy_trans.NsxPolicyTransaction():
self._do_port_backend_calls(
name, segment_id, spoofguard_profile, seg_sec_profile,
mac_discovery_profile, qos_policy_id, **kwargs)
# Update port admin status using passthrough api, only if it changed
# or new port with disabled admin state