NSX-V3| Integrate with nsxlib refactored code
Change-Id: I88fb83f0cb531794b21a06cabb1f56c54744a0e1
This commit is contained in:
parent
c98a428a29
commit
cc8ac92f4c
@ -98,9 +98,9 @@ from vmware_nsx.plugins.nsx_v3 import utils as v3_utils
|
|||||||
from vmware_nsx.services.qos.common import utils as qos_com_utils
|
from vmware_nsx.services.qos.common import utils as qos_com_utils
|
||||||
from vmware_nsx.services.qos.nsx_v3 import driver as qos_driver
|
from vmware_nsx.services.qos.nsx_v3 import driver as qos_driver
|
||||||
from vmware_nsx.services.trunk.nsx_v3 import driver as trunk_driver
|
from vmware_nsx.services.trunk.nsx_v3 import driver as trunk_driver
|
||||||
|
from vmware_nsxlib.v3 import core_resources as nsx_resources
|
||||||
from vmware_nsxlib.v3 import exceptions as nsx_lib_exc
|
from vmware_nsxlib.v3 import exceptions as nsx_lib_exc
|
||||||
from vmware_nsxlib.v3 import nsx_constants as nsxlib_consts
|
from vmware_nsxlib.v3 import nsx_constants as nsxlib_consts
|
||||||
from vmware_nsxlib.v3 import resources as nsx_resources
|
|
||||||
from vmware_nsxlib.v3 import router
|
from vmware_nsxlib.v3 import router
|
||||||
from vmware_nsxlib.v3 import security
|
from vmware_nsxlib.v3 import security
|
||||||
from vmware_nsxlib.v3 import utils as nsxlib_utils
|
from vmware_nsxlib.v3 import utils as nsxlib_utils
|
||||||
@ -192,7 +192,6 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
|
|
||||||
self._nsx_version = self.nsxlib.get_version()
|
self._nsx_version = self.nsxlib.get_version()
|
||||||
LOG.info("NSX Version: %s", self._nsx_version)
|
LOG.info("NSX Version: %s", self._nsx_version)
|
||||||
self._nsx_client = self.nsxlib.client
|
|
||||||
|
|
||||||
self.cfg_group = 'nsx_v3' # group name for nsx_v3 section in nsx.ini
|
self.cfg_group = 'nsx_v3' # group name for nsx_v3 section in nsx.ini
|
||||||
self.tier0_groups_dict = {}
|
self.tier0_groups_dict = {}
|
||||||
@ -206,19 +205,12 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
self._translate_configured_names_to_uuids()
|
self._translate_configured_names_to_uuids()
|
||||||
self._init_dhcp_metadata()
|
self._init_dhcp_metadata()
|
||||||
|
|
||||||
self._port_client = nsx_resources.LogicalPort(self._nsx_client)
|
|
||||||
self.default_section = self._init_default_section_rules()
|
self.default_section = self._init_default_section_rules()
|
||||||
self._process_security_group_logging()
|
self._process_security_group_logging()
|
||||||
self._router_client = nsx_resources.LogicalRouter(self._nsx_client)
|
self._routerlib = router.RouterLib(self.nsxlib.logical_router,
|
||||||
self._router_port_client = nsx_resources.LogicalRouterPort(
|
self.nsxlib.logical_router_port,
|
||||||
self._nsx_client)
|
|
||||||
self._routerlib = router.RouterLib(self._router_client,
|
|
||||||
self._router_port_client,
|
|
||||||
self.nsxlib)
|
self.nsxlib)
|
||||||
|
|
||||||
self._switching_profiles = nsx_resources.SwitchingProfile(
|
|
||||||
self._nsx_client)
|
|
||||||
|
|
||||||
# init profiles on nsx backend
|
# init profiles on nsx backend
|
||||||
self._init_nsx_profiles()
|
self._init_nsx_profiles()
|
||||||
|
|
||||||
@ -259,11 +251,11 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
msg = _("Unable to initialize NSX v3 port spoofguard "
|
msg = _("Unable to initialize NSX v3 port spoofguard "
|
||||||
"switching profile: %s") % NSX_V3_PSEC_PROFILE_NAME
|
"switching profile: %s") % NSX_V3_PSEC_PROFILE_NAME
|
||||||
raise nsx_exc.NsxPluginException(err_msg=msg)
|
raise nsx_exc.NsxPluginException(err_msg=msg)
|
||||||
profiles = nsx_resources.SwitchingProfile
|
profile_client = self.nsxlib.switching_profile
|
||||||
self._no_psec_profile_id = profiles.build_switch_profile_ids(
|
no_psec_prof = profile_client.find_by_display_name(
|
||||||
self._switching_profiles,
|
NSX_V3_NO_PSEC_PROFILE_NAME)[0]
|
||||||
self._switching_profiles.find_by_display_name(
|
self._no_psec_profile_id = profile_client.build_switch_profile_ids(
|
||||||
NSX_V3_NO_PSEC_PROFILE_NAME)[0])[0]
|
profile_client, no_psec_prof)[0]
|
||||||
|
|
||||||
LOG.debug("Initializing NSX v3 DHCP switching profile")
|
LOG.debug("Initializing NSX v3 DHCP switching profile")
|
||||||
try:
|
try:
|
||||||
@ -359,7 +351,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
events.BEFORE_DELETE)
|
events.BEFORE_DELETE)
|
||||||
|
|
||||||
def _validate_dhcp_profile(self, dhcp_profile_uuid):
|
def _validate_dhcp_profile(self, dhcp_profile_uuid):
|
||||||
dhcp_profile = self._switching_profiles.get(dhcp_profile_uuid)
|
dhcp_profile = self.nsxlib.switching_profile.get(dhcp_profile_uuid)
|
||||||
if (dhcp_profile.get('resource_type') !=
|
if (dhcp_profile.get('resource_type') !=
|
||||||
nsx_resources.SwitchingProfileTypes.SWITCH_SECURITY):
|
nsx_resources.SwitchingProfileTypes.SWITCH_SECURITY):
|
||||||
msg = _("Invalid configuration on the backend for DHCP "
|
msg = _("Invalid configuration on the backend for DHCP "
|
||||||
@ -379,7 +371,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
def _init_dhcp_switching_profile(self):
|
def _init_dhcp_switching_profile(self):
|
||||||
with locking.LockManager.get_lock('nsxv3_dhcp_profile_init'):
|
with locking.LockManager.get_lock('nsxv3_dhcp_profile_init'):
|
||||||
if not self._get_dhcp_security_profile():
|
if not self._get_dhcp_security_profile():
|
||||||
self._switching_profiles.create_dhcp_profile(
|
self.nsxlib.switching_profile.create_dhcp_profile(
|
||||||
NSX_V3_DHCP_PROFILE_NAME, 'Neutron DHCP Security Profile',
|
NSX_V3_DHCP_PROFILE_NAME, 'Neutron DHCP Security Profile',
|
||||||
tags=self.nsxlib.build_v3_api_version_tag())
|
tags=self.nsxlib.build_v3_api_version_tag())
|
||||||
return self._get_dhcp_security_profile()
|
return self._get_dhcp_security_profile()
|
||||||
@ -387,7 +379,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
def _get_dhcp_security_profile(self):
|
def _get_dhcp_security_profile(self):
|
||||||
if hasattr(self, '_dhcp_profile') and self._dhcp_profile:
|
if hasattr(self, '_dhcp_profile') and self._dhcp_profile:
|
||||||
return self._dhcp_profile
|
return self._dhcp_profile
|
||||||
profile = self._switching_profiles.find_by_display_name(
|
profile = self.nsxlib.switching_profile.find_by_display_name(
|
||||||
NSX_V3_DHCP_PROFILE_NAME)
|
NSX_V3_DHCP_PROFILE_NAME)
|
||||||
self._dhcp_profile = nsx_resources.SwitchingProfileTypeId(
|
self._dhcp_profile = nsx_resources.SwitchingProfileTypeId(
|
||||||
profile_type=(nsx_resources.SwitchingProfileTypes.
|
profile_type=(nsx_resources.SwitchingProfileTypes.
|
||||||
@ -398,7 +390,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
def _init_mac_learning_profile(self):
|
def _init_mac_learning_profile(self):
|
||||||
with locking.LockManager.get_lock('nsxv3_mac_learning_profile_init'):
|
with locking.LockManager.get_lock('nsxv3_mac_learning_profile_init'):
|
||||||
if not self._get_mac_learning_profile():
|
if not self._get_mac_learning_profile():
|
||||||
self._switching_profiles.create_mac_learning_profile(
|
self.nsxlib.switching_profile.create_mac_learning_profile(
|
||||||
NSX_V3_MAC_LEARNING_PROFILE_NAME,
|
NSX_V3_MAC_LEARNING_PROFILE_NAME,
|
||||||
'Neutron MAC Learning Profile',
|
'Neutron MAC Learning Profile',
|
||||||
tags=self.nsxlib.build_v3_api_version_tag())
|
tags=self.nsxlib.build_v3_api_version_tag())
|
||||||
@ -408,7 +400,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
if (hasattr(self, '_mac_learning_profile')
|
if (hasattr(self, '_mac_learning_profile')
|
||||||
and self._mac_learning_profile):
|
and self._mac_learning_profile):
|
||||||
return self._mac_learning_profile
|
return self._mac_learning_profile
|
||||||
profile = self._switching_profiles.find_by_display_name(
|
profile = self.nsxlib.switching_profile.find_by_display_name(
|
||||||
NSX_V3_MAC_LEARNING_PROFILE_NAME)
|
NSX_V3_MAC_LEARNING_PROFILE_NAME)
|
||||||
self._mac_learning_profile = nsx_resources.SwitchingProfileTypeId(
|
self._mac_learning_profile = nsx_resources.SwitchingProfileTypeId(
|
||||||
profile_type=(nsx_resources.SwitchingProfileTypes.
|
profile_type=(nsx_resources.SwitchingProfileTypes.
|
||||||
@ -417,13 +409,13 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
return self._mac_learning_profile
|
return self._mac_learning_profile
|
||||||
|
|
||||||
def _get_port_security_profile_id(self):
|
def _get_port_security_profile_id(self):
|
||||||
return nsx_resources.SwitchingProfile.build_switch_profile_ids(
|
return self.nsxlib.switching_profile.build_switch_profile_ids(
|
||||||
self._switching_profiles, self._psec_profile)[0]
|
self.nsxlib.switching_profile, self._psec_profile)[0]
|
||||||
|
|
||||||
def _get_port_security_profile(self):
|
def _get_port_security_profile(self):
|
||||||
if hasattr(self, '_psec_profile') and self._psec_profile:
|
if hasattr(self, '_psec_profile') and self._psec_profile:
|
||||||
return self._psec_profile
|
return self._psec_profile
|
||||||
profile = self._switching_profiles.find_by_display_name(
|
profile = self.nsxlib.switching_profile.find_by_display_name(
|
||||||
NSX_V3_PSEC_PROFILE_NAME)
|
NSX_V3_PSEC_PROFILE_NAME)
|
||||||
self._psec_profile = profile[0] if profile else None
|
self._psec_profile = profile[0] if profile else None
|
||||||
return self._psec_profile
|
return self._psec_profile
|
||||||
@ -441,7 +433,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
if profile:
|
if profile:
|
||||||
return profile
|
return profile
|
||||||
|
|
||||||
self._switching_profiles.create_spoofguard_profile(
|
self.nsxlib.switching_profile.create_spoofguard_profile(
|
||||||
NSX_V3_PSEC_PROFILE_NAME, 'Neutron Port Security Profile',
|
NSX_V3_PSEC_PROFILE_NAME, 'Neutron Port Security Profile',
|
||||||
whitelist_ports=True, whitelist_switches=False,
|
whitelist_ports=True, whitelist_switches=False,
|
||||||
tags=self.nsxlib.build_v3_api_version_tag())
|
tags=self.nsxlib.build_v3_api_version_tag())
|
||||||
@ -492,10 +484,8 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
def _init_native_dhcp(self):
|
def _init_native_dhcp(self):
|
||||||
try:
|
try:
|
||||||
for az in self.get_azs_list():
|
for az in self.get_azs_list():
|
||||||
nsx_resources.DhcpProfile(self._nsx_client).get(
|
self.nsxlib.native_dhcp_profile.get(
|
||||||
az._native_dhcp_profile_uuid)
|
az._native_dhcp_profile_uuid)
|
||||||
self._dhcp_server = nsx_resources.LogicalDhcpServer(
|
|
||||||
self._nsx_client)
|
|
||||||
except nsx_lib_exc.ManagerError:
|
except nsx_lib_exc.ManagerError:
|
||||||
with excutils.save_and_reraise_exception():
|
with excutils.save_and_reraise_exception():
|
||||||
LOG.error("Unable to retrieve DHCP Profile %s, "
|
LOG.error("Unable to retrieve DHCP Profile %s, "
|
||||||
@ -505,8 +495,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
def _init_native_metadata(self):
|
def _init_native_metadata(self):
|
||||||
try:
|
try:
|
||||||
for az in self.get_azs_list():
|
for az in self.get_azs_list():
|
||||||
nsx_resources.MetaDataProxy(self._nsx_client).get(
|
self.nsxlib.native_md_proxy.get(az._native_md_proxy_uuid)
|
||||||
az._native_md_proxy_uuid)
|
|
||||||
except nsx_lib_exc.ManagerError:
|
except nsx_lib_exc.ManagerError:
|
||||||
with excutils.save_and_reraise_exception():
|
with excutils.save_and_reraise_exception():
|
||||||
LOG.error("Unable to retrieve Metadata Proxy %s, "
|
LOG.error("Unable to retrieve Metadata Proxy %s, "
|
||||||
@ -817,7 +806,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
name = utils.get_name_and_uuid('%s-%s' % (
|
name = utils.get_name_and_uuid('%s-%s' % (
|
||||||
'mdproxy', created_net['name'] or 'network'),
|
'mdproxy', created_net['name'] or 'network'),
|
||||||
created_net['id'])
|
created_net['id'])
|
||||||
md_port = self._port_client.create(
|
md_port = self.nsxlib.logical_port.create(
|
||||||
nsx_net_id, az._native_md_proxy_uuid,
|
nsx_net_id, az._native_md_proxy_uuid,
|
||||||
tags=tags, name=name,
|
tags=tags, name=name,
|
||||||
attachment_type=nsxlib_consts.ATTACHMENT_MDPROXY)
|
attachment_type=nsxlib_consts.ATTACHMENT_MDPROXY)
|
||||||
@ -1039,12 +1028,12 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
project_name=context.tenant_name)
|
project_name=context.tenant_name)
|
||||||
dhcp_server = None
|
dhcp_server = None
|
||||||
try:
|
try:
|
||||||
dhcp_server = self._dhcp_server.create(**server_data)
|
dhcp_server = self.nsxlib.dhcp_server.create(**server_data)
|
||||||
LOG.debug("Created logical DHCP server %(server)s for network "
|
LOG.debug("Created logical DHCP server %(server)s for network "
|
||||||
"%(network)s",
|
"%(network)s",
|
||||||
{'server': dhcp_server['id'], 'network': network['id']})
|
{'server': dhcp_server['id'], 'network': network['id']})
|
||||||
name = self._get_port_name(context, port_data)
|
name = self._get_port_name(context, port_data)
|
||||||
nsx_port = self._port_client.create(
|
nsx_port = self.nsxlib.logical_port.create(
|
||||||
nsx_net_id, dhcp_server['id'], tags=port_tags, name=name,
|
nsx_net_id, dhcp_server['id'], tags=port_tags, name=name,
|
||||||
attachment_type=nsxlib_consts.ATTACHMENT_DHCP,
|
attachment_type=nsxlib_consts.ATTACHMENT_DHCP,
|
||||||
switch_profile_ids=[self._dhcp_profile])
|
switch_profile_ids=[self._dhcp_profile])
|
||||||
@ -1056,7 +1045,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
LOG.error("Unable to create logical DHCP server for "
|
LOG.error("Unable to create logical DHCP server for "
|
||||||
"network %s", network['id'])
|
"network %s", network['id'])
|
||||||
if dhcp_server:
|
if dhcp_server:
|
||||||
self._dhcp_server.delete(dhcp_server['id'])
|
self.nsxlib.dhcp_server.delete(dhcp_server['id'])
|
||||||
super(NsxV3Plugin, self).delete_port(
|
super(NsxV3Plugin, self).delete_port(
|
||||||
context, neutron_port['id'])
|
context, neutron_port['id'])
|
||||||
|
|
||||||
@ -1074,7 +1063,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
LOG.error("Failed to create mapping for DHCP port %s,"
|
LOG.error("Failed to create mapping for DHCP port %s,"
|
||||||
"deleting port and logical DHCP server",
|
"deleting port and logical DHCP server",
|
||||||
neutron_port['id'])
|
neutron_port['id'])
|
||||||
self._dhcp_server.delete(dhcp_server['id'])
|
self.nsxlib.dhcp_server.delete(dhcp_server['id'])
|
||||||
self._cleanup_port(context, neutron_port['id'], nsx_port['id'])
|
self._cleanup_port(context, neutron_port['id'], nsx_port['id'])
|
||||||
|
|
||||||
# Configure existing ports to work with the new DHCP server
|
# Configure existing ports to work with the new DHCP server
|
||||||
@ -1108,7 +1097,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
network_id)
|
network_id)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._dhcp_server.delete(dhcp_service['nsx_service_id'])
|
self.nsxlib.dhcp_server.delete(dhcp_service['nsx_service_id'])
|
||||||
LOG.debug("Deleted logical DHCP server %(server)s for network "
|
LOG.debug("Deleted logical DHCP server %(server)s for network "
|
||||||
"%(network)s",
|
"%(network)s",
|
||||||
{'server': dhcp_service['nsx_service_id'],
|
{'server': dhcp_service['nsx_service_id'],
|
||||||
@ -1205,13 +1194,13 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
subnet['network_id'])
|
subnet['network_id'])
|
||||||
if dhcp_info:
|
if dhcp_info:
|
||||||
try:
|
try:
|
||||||
self._port_client.delete(dhcp_info['nsx_port_id'])
|
self.nsxlib.logical_port.delete(dhcp_info['nsx_port_id'])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.error("Failed to delete logical port %(id)s "
|
LOG.error("Failed to delete logical port %(id)s "
|
||||||
"during rollback. Exception: %(e)s",
|
"during rollback. Exception: %(e)s",
|
||||||
{'id': dhcp_info['nsx_port_id'], 'e': e})
|
{'id': dhcp_info['nsx_port_id'], 'e': e})
|
||||||
try:
|
try:
|
||||||
self._dhcp_server.delete(dhcp_info['nsx_service_id'])
|
self.nsxlib.dhcp_server.delete(dhcp_info['nsx_service_id'])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.error("Failed to delete logical DHCP server %(id)s "
|
LOG.error("Failed to delete logical DHCP server %(id)s "
|
||||||
"during rollback. Exception: %(e)s",
|
"during rollback. Exception: %(e)s",
|
||||||
@ -1361,7 +1350,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
nsxlib_consts.SERVICE_DHCP)
|
nsxlib_consts.SERVICE_DHCP)
|
||||||
if dhcp_service:
|
if dhcp_service:
|
||||||
try:
|
try:
|
||||||
self._dhcp_server.update(
|
self.nsxlib.dhcp_server.update(
|
||||||
dhcp_service['nsx_service_id'], **kwargs)
|
dhcp_service['nsx_service_id'], **kwargs)
|
||||||
except nsx_lib_exc.ManagerError:
|
except nsx_lib_exc.ManagerError:
|
||||||
with excutils.save_and_reraise_exception():
|
with excutils.save_and_reraise_exception():
|
||||||
@ -1503,10 +1492,11 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
def _get_qos_profile_id(self, context, policy_id):
|
def _get_qos_profile_id(self, context, policy_id):
|
||||||
switch_profile_id = nsx_db.get_switch_profile_by_qos_policy(
|
switch_profile_id = nsx_db.get_switch_profile_by_qos_policy(
|
||||||
context.session, policy_id)
|
context.session, policy_id)
|
||||||
qos_profile = self.nsxlib.qos_switching_profile.get(switch_profile_id)
|
nsxlib_qos = self.nsxlib.qos_switching_profile
|
||||||
|
qos_profile = nsxlib_qos.get(switch_profile_id)
|
||||||
if qos_profile:
|
if qos_profile:
|
||||||
profile_ids = self._switching_profiles.build_switch_profile_ids(
|
profile_ids = nsxlib_qos.build_switch_profile_ids(
|
||||||
self._switching_profiles, qos_profile)
|
self.nsxlib.switching_profile, qos_profile)
|
||||||
if profile_ids and len(profile_ids) > 0:
|
if profile_ids and len(profile_ids) > 0:
|
||||||
# We have only 1 QoS profile, so this array is of size 1
|
# We have only 1 QoS profile, so this array is of size 1
|
||||||
return profile_ids[0]
|
return profile_ids[0]
|
||||||
@ -1620,7 +1610,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
|
|
||||||
nsx_net_id = port_data[pbin.VIF_DETAILS]['nsx-logical-switch-id']
|
nsx_net_id = port_data[pbin.VIF_DETAILS]['nsx-logical-switch-id']
|
||||||
try:
|
try:
|
||||||
result = self._port_client.create(
|
result = self.nsxlib.logical_port.create(
|
||||||
nsx_net_id, vif_uuid,
|
nsx_net_id, vif_uuid,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
name=name,
|
name=name,
|
||||||
@ -1701,7 +1691,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
def _cleanup_port(self, context, port_id, lport_id):
|
def _cleanup_port(self, context, port_id, lport_id):
|
||||||
super(NsxV3Plugin, self).delete_port(context, port_id)
|
super(NsxV3Plugin, self).delete_port(context, port_id)
|
||||||
if lport_id:
|
if lport_id:
|
||||||
self._port_client.delete(lport_id)
|
self.nsxlib.logical_port.delete(lport_id)
|
||||||
|
|
||||||
def _assert_on_external_net_port_with_qos(self, port_data):
|
def _assert_on_external_net_port_with_qos(self, port_data):
|
||||||
# Prevent creating/update port with QoS policy
|
# Prevent creating/update port with QoS policy
|
||||||
@ -1773,7 +1763,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
"%(name)s") % {'name': opt_name,
|
"%(name)s") % {'name': opt_name,
|
||||||
'val': opt_val})
|
'val': opt_val})
|
||||||
raise n_exc.InvalidInput(error_message=msg)
|
raise n_exc.InvalidInput(error_message=msg)
|
||||||
elif not self._dhcp_server.get_dhcp_opt_code(opt_name):
|
elif not self.nsxlib.dhcp_server.get_dhcp_opt_code(opt_name):
|
||||||
msg = (_("DHCP option %s is not supported") % opt_name)
|
msg = (_("DHCP option %s is not supported") % opt_name)
|
||||||
raise n_exc.InvalidInput(error_message=msg)
|
raise n_exc.InvalidInput(error_message=msg)
|
||||||
|
|
||||||
@ -1799,7 +1789,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
'network': net, 'next_hop': ip})
|
'network': net, 'next_hop': ip})
|
||||||
else:
|
else:
|
||||||
other_opts.append({
|
other_opts.append({
|
||||||
'code': self._dhcp_server.get_dhcp_opt_code(
|
'code': self.nsxlib.dhcp_server.get_dhcp_opt_code(
|
||||||
opt_name),
|
opt_name),
|
||||||
'values': [opt_val]})
|
'values': [opt_val]})
|
||||||
if other_opts:
|
if other_opts:
|
||||||
@ -1815,7 +1805,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
options = self._get_dhcp_options(
|
options = self._get_dhcp_options(
|
||||||
context, ip, port.get(ext_edo.EXTRADHCPOPTS),
|
context, ip, port.get(ext_edo.EXTRADHCPOPTS),
|
||||||
port['network_id'])
|
port['network_id'])
|
||||||
binding = self._dhcp_server.create_binding(
|
binding = self.nsxlib.dhcp_server.create_binding(
|
||||||
dhcp_service_id, port['mac_address'], ip, hostname,
|
dhcp_service_id, port['mac_address'], ip, hostname,
|
||||||
cfg.CONF.nsx_v3.dhcp_lease_time, options, gateway_ip)
|
cfg.CONF.nsx_v3.dhcp_lease_time, options, gateway_ip)
|
||||||
LOG.debug("Created static binding (mac: %(mac)s, ip: %(ip)s, "
|
LOG.debug("Created static binding (mac: %(mac)s, ip: %(ip)s, "
|
||||||
@ -1855,7 +1845,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
|
|
||||||
def _delete_dhcp_binding_on_server(self, context, binding):
|
def _delete_dhcp_binding_on_server(self, context, binding):
|
||||||
try:
|
try:
|
||||||
self._dhcp_server.delete_binding(
|
self.nsxlib.dhcp_server.delete_binding(
|
||||||
binding['nsx_service_id'], binding['nsx_binding_id'])
|
binding['nsx_service_id'], binding['nsx_binding_id'])
|
||||||
LOG.debug("Deleted static binding for port %(port)s) on "
|
LOG.debug("Deleted static binding for port %(port)s) on "
|
||||||
"logical DHCP server %(server)s",
|
"logical DHCP server %(server)s",
|
||||||
@ -1918,8 +1908,9 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
if dhcp_service:
|
if dhcp_service:
|
||||||
new_ip = ips_to_add[0][1]
|
new_ip = ips_to_add[0][1]
|
||||||
try:
|
try:
|
||||||
self._dhcp_server.update(dhcp_service['nsx_service_id'],
|
self.nsxlib.dhcp_server.update(
|
||||||
server_ip=new_ip)
|
dhcp_service['nsx_service_id'],
|
||||||
|
server_ip=new_ip)
|
||||||
LOG.debug("Updated IP %(ip)s for logical DHCP server "
|
LOG.debug("Updated IP %(ip)s for logical DHCP server "
|
||||||
"%(server)s",
|
"%(server)s",
|
||||||
{'ip': new_ip,
|
{'ip': new_ip,
|
||||||
@ -1994,7 +1985,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
# Note that None is valid for gateway_ip, means deleting it.
|
# Note that None is valid for gateway_ip, means deleting it.
|
||||||
data['gateway_ip'] = gateway_ip
|
data['gateway_ip'] = gateway_ip
|
||||||
|
|
||||||
self._dhcp_server.update_binding(
|
self.nsxlib.dhcp_server.update_binding(
|
||||||
binding['nsx_service_id'], binding['nsx_binding_id'], **data)
|
binding['nsx_service_id'], binding['nsx_binding_id'], **data)
|
||||||
LOG.debug("Updated static binding (mac: %(mac)s, ip: %(ip)s, "
|
LOG.debug("Updated static binding (mac: %(mac)s, ip: %(ip)s, "
|
||||||
"gateway: %(gateway)s) for port %(port)s on "
|
"gateway: %(gateway)s) for port %(port)s on "
|
||||||
@ -2163,7 +2154,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
if not self._network_is_external(context, port['network_id']):
|
if not self._network_is_external(context, port['network_id']):
|
||||||
_net_id, nsx_port_id = nsx_db.get_nsx_switch_and_port_id(
|
_net_id, nsx_port_id = nsx_db.get_nsx_switch_and_port_id(
|
||||||
context.session, port_id)
|
context.session, port_id)
|
||||||
self._port_client.delete(nsx_port_id)
|
self.nsxlib.logical_port.delete(nsx_port_id)
|
||||||
if not utils.is_nsx_version_1_1_0(self._nsx_version):
|
if not utils.is_nsx_version_1_1_0(self._nsx_version):
|
||||||
self._update_lport_with_security_groups(
|
self._update_lport_with_security_groups(
|
||||||
context, nsx_port_id,
|
context, nsx_port_id,
|
||||||
@ -2368,7 +2359,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
switch_profile_ids.append(self._mac_learning_profile)
|
switch_profile_ids.append(self._mac_learning_profile)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._port_client.update(
|
self.nsxlib.logical_port.update(
|
||||||
lport_id, vif_uuid, name=name,
|
lport_id, vif_uuid, name=name,
|
||||||
attachment_type=attachment_type,
|
attachment_type=attachment_type,
|
||||||
admin_state=updated_port.get('admin_state_up'),
|
admin_state=updated_port.get('admin_state_up'),
|
||||||
@ -2751,7 +2742,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
# occurred during super.create_router(), which will cause
|
# occurred during super.create_router(), which will cause
|
||||||
# API retry and leaves dangling backend entries.
|
# API retry and leaves dangling backend entries.
|
||||||
try:
|
try:
|
||||||
result = self._router_client.create(
|
result = self.nsxlib.logical_router.create(
|
||||||
display_name=utils.get_name_and_uuid(
|
display_name=utils.get_name_and_uuid(
|
||||||
router['name'] or 'router', router['id']),
|
router['name'] or 'router', router['id']),
|
||||||
description=router.get('description'),
|
description=router.get('description'),
|
||||||
@ -2806,7 +2797,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
# It is safe to do now as db-level checks for resource deletion were
|
# It is safe to do now as db-level checks for resource deletion were
|
||||||
# passed (and indeed the resource was removed from the Neutron DB
|
# passed (and indeed the resource was removed from the Neutron DB
|
||||||
try:
|
try:
|
||||||
self._router_client.delete(nsx_router_id, force=True)
|
self.nsxlib.logical_router.delete(nsx_router_id, force=True)
|
||||||
except nsx_lib_exc.ResourceNotFound:
|
except nsx_lib_exc.ResourceNotFound:
|
||||||
# If the logical router was not found on the backend do not worry
|
# If the logical router was not found on the backend do not worry
|
||||||
# about it. The conditions has already been logged, so there is no
|
# about it. The conditions has already been logged, so there is no
|
||||||
@ -2889,8 +2880,8 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
display_name = utils.get_name_and_uuid(router_name, router_id)
|
display_name = utils.get_name_and_uuid(router_name, router_id)
|
||||||
nsx_router_id = nsx_router_id or nsx_db.get_nsx_router_id(
|
nsx_router_id = nsx_router_id or nsx_db.get_nsx_router_id(
|
||||||
context.session, router_id)
|
context.session, router_id)
|
||||||
self._router_client.update(nsx_router_id,
|
self.nsxlib.logical_router.update(nsx_router_id,
|
||||||
display_name=display_name)
|
display_name=display_name)
|
||||||
# Update the name of associated logical ports.
|
# Update the name of associated logical ports.
|
||||||
filters = {'device_id': [router_id],
|
filters = {'device_id': [router_id],
|
||||||
'device_owner': const.ROUTER_INTERFACE_OWNERS}
|
'device_owner': const.ROUTER_INTERFACE_OWNERS}
|
||||||
@ -2902,8 +2893,8 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
name = utils.get_name_and_uuid(
|
name = utils.get_name_and_uuid(
|
||||||
router_name, port['id'], tag='port')
|
router_name, port['id'], tag='port')
|
||||||
try:
|
try:
|
||||||
self._port_client.update(nsx_port_id, None,
|
self.nsxlib.logical_port.update(nsx_port_id, None,
|
||||||
name=name)
|
name=name)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.error("Unable to update port %(port_id)s. "
|
LOG.error("Unable to update port %(port_id)s. "
|
||||||
"Reason: %(e)s",
|
"Reason: %(e)s",
|
||||||
@ -2912,7 +2903,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
if 'description' in router_data:
|
if 'description' in router_data:
|
||||||
nsx_router_id = nsx_db.get_nsx_router_id(context.session,
|
nsx_router_id = nsx_db.get_nsx_router_id(context.session,
|
||||||
router_id)
|
router_id)
|
||||||
self._router_client.update(
|
self.nsxlib.logical_router.update(
|
||||||
nsx_router_id,
|
nsx_router_id,
|
||||||
description=router_data['description'])
|
description=router_data['description'])
|
||||||
|
|
||||||
@ -3123,13 +3114,14 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
new_using_port_id = ports[0]['id']
|
new_using_port_id = ports[0]['id']
|
||||||
_net_id, new_nsx_port_id = nsx_db.get_nsx_switch_and_port_id(
|
_net_id, new_nsx_port_id = nsx_db.get_nsx_switch_and_port_id(
|
||||||
context.session, new_using_port_id)
|
context.session, new_using_port_id)
|
||||||
self._router_port_client.update_by_lswitch_id(
|
self.nsxlib.logical_router_port.update_by_lswitch_id(
|
||||||
nsx_router_id, nsx_net_id,
|
nsx_router_id, nsx_net_id,
|
||||||
linked_logical_switch_port_id={
|
linked_logical_switch_port_id={
|
||||||
'target_id': new_nsx_port_id},
|
'target_id': new_nsx_port_id},
|
||||||
subnets=address_groups)
|
subnets=address_groups)
|
||||||
else:
|
else:
|
||||||
self._router_port_client.delete_by_lswitch_id(nsx_net_id)
|
self.nsxlib.logical_router_port.delete_by_lswitch_id(
|
||||||
|
nsx_net_id)
|
||||||
except nsx_lib_exc.ResourceNotFound:
|
except nsx_lib_exc.ResourceNotFound:
|
||||||
LOG.error("router port on router %(router_id)s for net "
|
LOG.error("router port on router %(router_id)s for net "
|
||||||
"%(net_id)s not found at the backend",
|
"%(net_id)s not found at the backend",
|
||||||
|
@ -25,7 +25,6 @@ from vmware_nsx._i18n import _
|
|||||||
from vmware_nsx.services.ipam.common import driver as common
|
from vmware_nsx.services.ipam.common import driver as common
|
||||||
from vmware_nsxlib.v3 import exceptions as nsx_lib_exc
|
from vmware_nsxlib.v3 import exceptions as nsx_lib_exc
|
||||||
from vmware_nsxlib.v3 import nsx_constants as error
|
from vmware_nsxlib.v3 import nsx_constants as error
|
||||||
from vmware_nsxlib.v3 import resources
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -35,8 +34,7 @@ class Nsxv3IpamDriver(common.NsxAbstractIpamDriver):
|
|||||||
|
|
||||||
def __init__(self, subnetpool, context):
|
def __init__(self, subnetpool, context):
|
||||||
super(Nsxv3IpamDriver, self).__init__(subnetpool, context)
|
super(Nsxv3IpamDriver, self).__init__(subnetpool, context)
|
||||||
self.nsxlib_ipam = resources.IpPool(
|
self.nsxlib_ipam = self.get_core_plugin().nsxlib.ip_pool
|
||||||
self.get_core_plugin().nsxlib.client)
|
|
||||||
|
|
||||||
# Mark which updates to the pool are supported
|
# Mark which updates to the pool are supported
|
||||||
self.support_update_gateway = True
|
self.support_update_gateway = True
|
||||||
@ -135,8 +133,7 @@ class Nsxv3IpamSubnet(common.NsxAbstractIpamSubnet):
|
|||||||
def __init__(self, subnet_id, nsx_pool_id, ctx, tenant_id):
|
def __init__(self, subnet_id, nsx_pool_id, ctx, tenant_id):
|
||||||
super(Nsxv3IpamSubnet, self).__init__(
|
super(Nsxv3IpamSubnet, self).__init__(
|
||||||
subnet_id, nsx_pool_id, ctx, tenant_id)
|
subnet_id, nsx_pool_id, ctx, tenant_id)
|
||||||
self.nsxlib_ipam = resources.IpPool(
|
self.nsxlib_ipam = self.get_core_plugin().nsxlib.ip_pool
|
||||||
self.get_core_plugin().nsxlib.client)
|
|
||||||
|
|
||||||
def backend_allocate(self, address_request):
|
def backend_allocate(self, address_request):
|
||||||
try:
|
try:
|
||||||
|
@ -64,7 +64,7 @@ class NsxV3TrunkHandler(object):
|
|||||||
session=context.session, neutron_id=subport.port_id)[1]
|
session=context.session, neutron_id=subport.port_id)[1]
|
||||||
# Retrieve child logical port from the backend
|
# Retrieve child logical port from the backend
|
||||||
try:
|
try:
|
||||||
nsx_child_port = self.plugin_driver._port_client.get(
|
nsx_child_port = self.plugin_driver.nsxlib.logical_port.get(
|
||||||
nsx_child_port_id)
|
nsx_child_port_id)
|
||||||
except nsxlib_exc.ResourceNotFound:
|
except nsxlib_exc.ResourceNotFound:
|
||||||
with excutils.save_and_reraise_exception():
|
with excutils.save_and_reraise_exception():
|
||||||
@ -90,7 +90,7 @@ class NsxV3TrunkHandler(object):
|
|||||||
seg_id = None
|
seg_id = None
|
||||||
# Update logical port in the backend to set/unset parent port
|
# Update logical port in the backend to set/unset parent port
|
||||||
try:
|
try:
|
||||||
self.plugin_driver._port_client.update(
|
self.plugin_driver.nsxlib.logical_port.update(
|
||||||
lport_id=nsx_child_port.get('id'),
|
lport_id=nsx_child_port.get('id'),
|
||||||
vif_uuid=subport.port_id,
|
vif_uuid=subport.port_id,
|
||||||
name=nsx_child_port.get('display_name'),
|
name=nsx_child_port.get('display_name'),
|
||||||
|
@ -26,7 +26,6 @@ from vmware_nsx.shell.admin.plugins.common import utils as admin_utils
|
|||||||
from vmware_nsx.shell.admin.plugins.nsxv3.resources import utils
|
from vmware_nsx.shell.admin.plugins.nsxv3.resources import utils
|
||||||
import vmware_nsx.shell.resources as shell
|
import vmware_nsx.shell.resources as shell
|
||||||
from vmware_nsxlib.v3 import nsx_constants
|
from vmware_nsxlib.v3 import nsx_constants
|
||||||
from vmware_nsxlib.v3 import resources
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
neutron_client = utils.NeutronDbClient()
|
neutron_client = utils.NeutronDbClient()
|
||||||
@ -66,10 +65,6 @@ def nsx_update_dhcp_bindings(resource, event, trigger, **kwargs):
|
|||||||
cfg.CONF.set_override('native_dhcp_metadata', True, 'nsx_v3')
|
cfg.CONF.set_override('native_dhcp_metadata', True, 'nsx_v3')
|
||||||
cfg.CONF.set_override('dhcp_profile', dhcp_profile_uuid, 'nsx_v3')
|
cfg.CONF.set_override('dhcp_profile', dhcp_profile_uuid, 'nsx_v3')
|
||||||
|
|
||||||
nsx_client = utils.get_nsxv3_client()
|
|
||||||
port_resource = resources.LogicalPort(nsx_client)
|
|
||||||
dhcp_server_resource = resources.LogicalDhcpServer(nsx_client)
|
|
||||||
|
|
||||||
port_bindings = {} # lswitch_id: [(port_id, mac, ip), ...]
|
port_bindings = {} # lswitch_id: [(port_id, mac, ip), ...]
|
||||||
server_bindings = {} # lswitch_id: dhcp_server_id
|
server_bindings = {} # lswitch_id: dhcp_server_id
|
||||||
ports = neutron_client.get_ports()
|
ports = neutron_client.get_ports()
|
||||||
@ -96,7 +91,7 @@ def nsx_update_dhcp_bindings(resource, event, trigger, **kwargs):
|
|||||||
server_data = nsxlib.native_dhcp.build_server_config(
|
server_data = nsxlib.native_dhcp.build_server_config(
|
||||||
network, subnet, port, net_tags)
|
network, subnet, port, net_tags)
|
||||||
server_data['dhcp_profile_id'] = dhcp_profile_uuid
|
server_data['dhcp_profile_id'] = dhcp_profile_uuid
|
||||||
dhcp_server = dhcp_server_resource.create(**server_data)
|
dhcp_server = nsxlib.dhcp_server.create(**server_data)
|
||||||
LOG.info("Created logical DHCP server %(server)s for "
|
LOG.info("Created logical DHCP server %(server)s for "
|
||||||
"network %(network)s",
|
"network %(network)s",
|
||||||
{'server': dhcp_server['id'],
|
{'server': dhcp_server['id'],
|
||||||
@ -107,7 +102,7 @@ def nsx_update_dhcp_bindings(resource, event, trigger, **kwargs):
|
|||||||
# Update logical port for DHCP purpose.
|
# Update logical port for DHCP purpose.
|
||||||
lswitch_id, lport_id = (
|
lswitch_id, lport_id = (
|
||||||
neutron_client.get_lswitch_and_lport_id(port['id']))
|
neutron_client.get_lswitch_and_lport_id(port['id']))
|
||||||
port_resource.update(
|
nsxlib.logical_port.update(
|
||||||
lport_id, dhcp_server['id'],
|
lport_id, dhcp_server['id'],
|
||||||
attachment_type=nsx_constants.ATTACHMENT_DHCP)
|
attachment_type=nsx_constants.ATTACHMENT_DHCP)
|
||||||
server_bindings[lswitch_id] = dhcp_server['id']
|
server_bindings[lswitch_id] = dhcp_server['id']
|
||||||
@ -136,7 +131,7 @@ def nsx_update_dhcp_bindings(resource, event, trigger, **kwargs):
|
|||||||
{'network': '%s' % cfg.CONF.nsx_v3.native_metadata_route,
|
{'network': '%s' % cfg.CONF.nsx_v3.native_metadata_route,
|
||||||
'next_hop': ip}]}}
|
'next_hop': ip}]}}
|
||||||
subnet = neutron_client.get_subnet(subnet_id)
|
subnet = neutron_client.get_subnet(subnet_id)
|
||||||
binding = dhcp_server_resource.create_binding(
|
binding = nsxlib.dhcp_server.create_binding(
|
||||||
dhcp_server_id, mac, ip, hostname,
|
dhcp_server_id, mac, ip, hostname,
|
||||||
cfg.CONF.nsx_v3.dhcp_lease_time, options,
|
cfg.CONF.nsx_v3.dhcp_lease_time, options,
|
||||||
subnet.get('gateway_ip'))
|
subnet.get('gateway_ip'))
|
||||||
|
@ -25,14 +25,10 @@ from vmware_nsx.shell.admin.plugins.common import utils as admin_utils
|
|||||||
from vmware_nsx.shell.admin.plugins.nsxv3.resources import utils
|
from vmware_nsx.shell.admin.plugins.nsxv3.resources import utils
|
||||||
import vmware_nsx.shell.resources as shell
|
import vmware_nsx.shell.resources as shell
|
||||||
from vmware_nsxlib.v3 import nsx_constants
|
from vmware_nsxlib.v3 import nsx_constants
|
||||||
from vmware_nsxlib.v3 import resources
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
neutron_client = utils.NeutronDbClient()
|
neutron_client = utils.NeutronDbClient()
|
||||||
nsx_client = utils.get_nsxv3_client()
|
|
||||||
nsxlib = utils.get_connected_nsxlib()
|
nsxlib = utils.get_connected_nsxlib()
|
||||||
port_resource = resources.LogicalPort(nsx_client)
|
|
||||||
dhcp_server_resource = resources.LogicalDhcpServer(nsx_client)
|
|
||||||
|
|
||||||
|
|
||||||
def _get_dhcp_profile_uuid(**kwargs):
|
def _get_dhcp_profile_uuid(**kwargs):
|
||||||
@ -54,7 +50,7 @@ def _get_orphaned_dhcp_servers(dhcp_profile_uuid):
|
|||||||
server_net_pairs = []
|
server_net_pairs = []
|
||||||
|
|
||||||
# Find matching DHCP servers for a given dhcp_profile_uuid.
|
# Find matching DHCP servers for a given dhcp_profile_uuid.
|
||||||
response = dhcp_server_resource.list()
|
response = nsxlib.dhcp_server.list()
|
||||||
for dhcp_server in response['results']:
|
for dhcp_server in response['results']:
|
||||||
if dhcp_server['dhcp_profile_id'] != dhcp_profile_uuid:
|
if dhcp_server['dhcp_profile_id'] != dhcp_profile_uuid:
|
||||||
continue
|
continue
|
||||||
@ -140,12 +136,14 @@ def nsx_clean_orphaned_dhcp_servers(resource, event, trigger, **kwargs):
|
|||||||
|
|
||||||
for server in orphaned_servers:
|
for server in orphaned_servers:
|
||||||
try:
|
try:
|
||||||
|
# TODO(asarfaty): should add this as api to nsxlib instead of
|
||||||
|
# abusing it
|
||||||
resource = ('?attachment_type=DHCP_SERVICE&attachment_id=%s' %
|
resource = ('?attachment_type=DHCP_SERVICE&attachment_id=%s' %
|
||||||
server['id'])
|
server['id'])
|
||||||
response = port_resource._client.url_get(resource)
|
response = nsxlib.logical_port.get(resource)
|
||||||
if response and response['result_count'] > 0:
|
if response and response['result_count'] > 0:
|
||||||
port_resource.delete(response['results'][0]['id'])
|
nsxlib.logical_port.delete(response['results'][0]['id'])
|
||||||
dhcp_server_resource.delete(server['id'])
|
nsxlib.dhcp_server.delete(server['id'])
|
||||||
net_id = server.get('neutron_net_id')
|
net_id = server.get('neutron_net_id')
|
||||||
if net_id:
|
if net_id:
|
||||||
# Delete neutron_net_id -> dhcp_service_id mapping from the DB.
|
# Delete neutron_net_id -> dhcp_service_id mapping from the DB.
|
||||||
|
@ -25,7 +25,6 @@ from vmware_nsx.shell.admin.plugins.common import utils as admin_utils
|
|||||||
from vmware_nsx.shell.admin.plugins.nsxv3.resources import utils
|
from vmware_nsx.shell.admin.plugins.nsxv3.resources import utils
|
||||||
import vmware_nsx.shell.resources as shell
|
import vmware_nsx.shell.resources as shell
|
||||||
from vmware_nsxlib.v3 import nsx_constants
|
from vmware_nsxlib.v3 import nsx_constants
|
||||||
from vmware_nsxlib.v3 import resources
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
neutron_client = utils.NeutronDbClient()
|
neutron_client = utils.NeutronDbClient()
|
||||||
@ -76,9 +75,6 @@ def nsx_update_metadata_proxy(resource, event, trigger, **kwargs):
|
|||||||
cfg.CONF.set_override('metadata_proxy', metadata_proxy_uuid, 'nsx_v3')
|
cfg.CONF.set_override('metadata_proxy', metadata_proxy_uuid, 'nsx_v3')
|
||||||
|
|
||||||
with utils.NsxV3PluginWrapper() as plugin:
|
with utils.NsxV3PluginWrapper() as plugin:
|
||||||
nsx_client = utils.get_nsxv3_client()
|
|
||||||
port_resource = resources.LogicalPort(nsx_client)
|
|
||||||
|
|
||||||
# For each Neutron network, check if it is an internal metadata
|
# For each Neutron network, check if it is an internal metadata
|
||||||
# network.
|
# network.
|
||||||
# If yes, delete the network and associated router interface.
|
# If yes, delete the network and associated router interface.
|
||||||
@ -111,10 +107,11 @@ def nsx_update_metadata_proxy(resource, event, trigger, **kwargs):
|
|||||||
name = nsx_utils.get_name_and_uuid('%s-%s' % (
|
name = nsx_utils.get_name_and_uuid('%s-%s' % (
|
||||||
'mdproxy', network['name'] or 'network'), network['id'])
|
'mdproxy', network['name'] or 'network'), network['id'])
|
||||||
# check if this logical port already exists
|
# check if this logical port already exists
|
||||||
existing_ports = port_resource.find_by_display_name(name)
|
existing_ports = nsxlib.logical_port.find_by_display_name(
|
||||||
|
name)
|
||||||
if not existing_ports:
|
if not existing_ports:
|
||||||
# create a new port with the md-proxy
|
# create a new port with the md-proxy
|
||||||
port_resource.create(
|
nsxlib.logical_port.create(
|
||||||
lswitch_id, metadata_proxy_uuid, tags=tags, name=name,
|
lswitch_id, metadata_proxy_uuid, tags=tags, name=name,
|
||||||
attachment_type=nsx_constants.ATTACHMENT_MDPROXY)
|
attachment_type=nsx_constants.ATTACHMENT_MDPROXY)
|
||||||
LOG.info("Enabled native metadata proxy for network %s",
|
LOG.info("Enabled native metadata proxy for network %s",
|
||||||
@ -122,7 +119,7 @@ def nsx_update_metadata_proxy(resource, event, trigger, **kwargs):
|
|||||||
else:
|
else:
|
||||||
# update the MDproxy of this port
|
# update the MDproxy of this port
|
||||||
port = existing_ports[0]
|
port = existing_ports[0]
|
||||||
port_resource.update(
|
nsxlib.logical_port.update(
|
||||||
port['id'], metadata_proxy_uuid,
|
port['id'], metadata_proxy_uuid,
|
||||||
attachment_type=nsx_constants.ATTACHMENT_MDPROXY)
|
attachment_type=nsx_constants.ATTACHMENT_MDPROXY)
|
||||||
LOG.info("Updated native metadata proxy for network %s",
|
LOG.info("Updated native metadata proxy for network %s",
|
||||||
|
@ -20,7 +20,6 @@ from vmware_nsx.shell.admin.plugins.common import utils as admin_utils
|
|||||||
from vmware_nsx.shell.admin.plugins.nsxv3.resources import utils
|
from vmware_nsx.shell.admin.plugins.nsxv3.resources import utils
|
||||||
from vmware_nsx.shell import resources as shell
|
from vmware_nsx.shell import resources as shell
|
||||||
from vmware_nsxlib.v3 import exceptions as nsx_exc
|
from vmware_nsxlib.v3 import exceptions as nsx_exc
|
||||||
from vmware_nsxlib.v3 import resources as nsx_resources
|
|
||||||
|
|
||||||
from neutron.db import db_base_plugin_v2
|
from neutron.db import db_base_plugin_v2
|
||||||
from neutron.db import l3_db
|
from neutron.db import l3_db
|
||||||
@ -29,6 +28,7 @@ from neutron_lib import context as neutron_context
|
|||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
nsxlib = utils.get_connected_nsxlib()
|
||||||
|
|
||||||
|
|
||||||
class RoutersPlugin(db_base_plugin_v2.NeutronDbPluginV2,
|
class RoutersPlugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||||
@ -36,11 +36,6 @@ class RoutersPlugin(db_base_plugin_v2.NeutronDbPluginV2,
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def get_router_client():
|
|
||||||
_nsx_client = utils.get_nsxv3_client()
|
|
||||||
return nsx_resources.LogicalRouter(_nsx_client)
|
|
||||||
|
|
||||||
|
|
||||||
@admin_utils.output_header
|
@admin_utils.output_header
|
||||||
def list_missing_routers(resource, event, trigger, **kwargs):
|
def list_missing_routers(resource, event, trigger, **kwargs):
|
||||||
"""List neutron routers that are missing the NSX backend router
|
"""List neutron routers that are missing the NSX backend router
|
||||||
@ -48,7 +43,6 @@ def list_missing_routers(resource, event, trigger, **kwargs):
|
|||||||
plugin = RoutersPlugin()
|
plugin = RoutersPlugin()
|
||||||
admin_cxt = neutron_context.get_admin_context()
|
admin_cxt = neutron_context.get_admin_context()
|
||||||
neutron_routers = plugin.get_routers(admin_cxt)
|
neutron_routers = plugin.get_routers(admin_cxt)
|
||||||
router_client = get_router_client()
|
|
||||||
routers = []
|
routers = []
|
||||||
for router in neutron_routers:
|
for router in neutron_routers:
|
||||||
neutron_id = router['id']
|
neutron_id = router['id']
|
||||||
@ -61,7 +55,7 @@ def list_missing_routers(resource, event, trigger, **kwargs):
|
|||||||
'nsx_id': None})
|
'nsx_id': None})
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
router_client.get(nsx_id)
|
nsxlib.logical_router.get(nsx_id)
|
||||||
except nsx_exc.ResourceNotFound:
|
except nsx_exc.ResourceNotFound:
|
||||||
routers.append({'name': router['name'],
|
routers.append({'name': router['name'],
|
||||||
'neutron_id': neutron_id,
|
'neutron_id': neutron_id,
|
||||||
|
@ -86,7 +86,8 @@ def _mock_nsx_backend_calls():
|
|||||||
return key
|
return key
|
||||||
|
|
||||||
mock.patch(
|
mock.patch(
|
||||||
"vmware_nsxlib.v3.resources.SwitchingProfile.find_by_display_name",
|
"vmware_nsxlib.v3.core_resources.NsxLibSwitchingProfile."
|
||||||
|
"find_by_display_name",
|
||||||
return_value=[fake_profile]
|
return_value=[fake_profile]
|
||||||
).start()
|
).start()
|
||||||
|
|
||||||
@ -94,7 +95,7 @@ def _mock_nsx_backend_calls():
|
|||||||
"vmware_nsxlib.v3.router.RouterLib.validate_tier0").start()
|
"vmware_nsxlib.v3.router.RouterLib.validate_tier0").start()
|
||||||
|
|
||||||
mock.patch(
|
mock.patch(
|
||||||
"vmware_nsxlib.v3.resources.SwitchingProfile."
|
"vmware_nsxlib.v3.core_resources.NsxLibSwitchingProfile."
|
||||||
"create_port_mirror_profile",
|
"create_port_mirror_profile",
|
||||||
side_effect=_return_id_key).start()
|
side_effect=_return_id_key).start()
|
||||||
|
|
||||||
@ -135,7 +136,7 @@ def _mock_nsx_backend_calls():
|
|||||||
side_effect=_return_id_key).start()
|
side_effect=_return_id_key).start()
|
||||||
|
|
||||||
mock.patch(
|
mock.patch(
|
||||||
"vmware_nsxlib.v3.resources.LogicalRouter.create",
|
"vmware_nsxlib.v3.core_resources.NsxLibLogicalRouter.create",
|
||||||
side_effect=_return_id_key).start()
|
side_effect=_return_id_key).start()
|
||||||
|
|
||||||
mock.patch(
|
mock.patch(
|
||||||
@ -249,7 +250,7 @@ class TestNetworksV2(test_plugin.TestNetworksV2, NsxV3PluginTestCaseMixin):
|
|||||||
def test_network_failure_rollback(self):
|
def test_network_failure_rollback(self):
|
||||||
cfg.CONF.set_override('native_dhcp_metadata', True, 'nsx_v3')
|
cfg.CONF.set_override('native_dhcp_metadata', True, 'nsx_v3')
|
||||||
self.plugin = directory.get_plugin()
|
self.plugin = directory.get_plugin()
|
||||||
with mock.patch.object(self.plugin._port_client, 'create',
|
with mock.patch.object(self.plugin.nsxlib.logical_port, 'create',
|
||||||
side_effect=api_exc.NsxApiException):
|
side_effect=api_exc.NsxApiException):
|
||||||
self.network()
|
self.network()
|
||||||
ctx = context.get_admin_context()
|
ctx = context.get_admin_context()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user