NSX|V3 utility to identify CrossHairs version
Adding a commin utility to identify CrossHairs by the nsx version, And use it where needed. Change-Id: I5e0faa048765c8398267e3fdf8b9be4a9ea86475
This commit is contained in:
parent
cd041ff985
commit
8e12e74538
@ -13,11 +13,12 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from distutils import version
|
||||||
import functools
|
import functools
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
import eventlet
|
import eventlet
|
||||||
from neutron import version
|
from neutron import version as n_version
|
||||||
from neutron_lib.api import validators
|
from neutron_lib.api import validators
|
||||||
from neutron_lib import exceptions
|
from neutron_lib import exceptions
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
@ -33,9 +34,10 @@ LOG = log.getLogger(__name__)
|
|||||||
MAX_DISPLAY_NAME_LEN = 40
|
MAX_DISPLAY_NAME_LEN = 40
|
||||||
MAX_RESOURCE_TYPE_LEN = 20
|
MAX_RESOURCE_TYPE_LEN = 20
|
||||||
MAX_TAG_LEN = 40
|
MAX_TAG_LEN = 40
|
||||||
NEUTRON_VERSION = version.version_info.release_string()
|
NEUTRON_VERSION = n_version.version_info.release_string()
|
||||||
NSX_NEUTRON_PLUGIN = 'NSX Neutron plugin'
|
NSX_NEUTRON_PLUGIN = 'NSX Neutron plugin'
|
||||||
OS_NEUTRON_ID_SCOPE = 'os-neutron-id'
|
OS_NEUTRON_ID_SCOPE = 'os-neutron-id'
|
||||||
|
NSXV3_VERSION_1_1_0 = '1.1.0'
|
||||||
|
|
||||||
|
|
||||||
# Allowed network types for the NSX Plugin
|
# Allowed network types for the NSX Plugin
|
||||||
@ -66,6 +68,11 @@ class NsxV3NetworkTypes:
|
|||||||
VXLAN = 'vxlan'
|
VXLAN = 'vxlan'
|
||||||
|
|
||||||
|
|
||||||
|
def is_nsx_version_1_1_0(nsx_version):
|
||||||
|
return (version.LooseVersion(nsx_version) >=
|
||||||
|
version.LooseVersion(NSXV3_VERSION_1_1_0))
|
||||||
|
|
||||||
|
|
||||||
def get_tags(**kwargs):
|
def get_tags(**kwargs):
|
||||||
tags = ([dict(tag=value, scope=key)
|
tags = ([dict(tag=value, scope=key)
|
||||||
for key, value in six.iteritems(kwargs)])
|
for key, value in six.iteritems(kwargs)])
|
||||||
@ -116,7 +123,7 @@ def build_v3_api_version_tag():
|
|||||||
return [{'scope': OS_NEUTRON_ID_SCOPE,
|
return [{'scope': OS_NEUTRON_ID_SCOPE,
|
||||||
'tag': NSX_NEUTRON_PLUGIN},
|
'tag': NSX_NEUTRON_PLUGIN},
|
||||||
{'scope': "os-api-version",
|
{'scope': "os-api-version",
|
||||||
'tag': version.version_info.release_string()}]
|
'tag': n_version.version_info.release_string()}]
|
||||||
|
|
||||||
|
|
||||||
def _validate_resource_type_length(resource_type):
|
def _validate_resource_type_length(resource_type):
|
||||||
@ -151,7 +158,7 @@ def build_v3_tags_payload(resource, resource_type, project_name):
|
|||||||
{'scope': 'os-project-name',
|
{'scope': 'os-project-name',
|
||||||
'tag': project_name[:MAX_TAG_LEN]},
|
'tag': project_name[:MAX_TAG_LEN]},
|
||||||
{'scope': 'os-api-version',
|
{'scope': 'os-api-version',
|
||||||
'tag': version.version_info.release_string()[:MAX_TAG_LEN]}]
|
'tag': n_version.version_info.release_string()[:MAX_TAG_LEN]}]
|
||||||
|
|
||||||
|
|
||||||
def add_v3_tag(tags, resource_type, tag):
|
def add_v3_tag(tags, resource_type, tag):
|
||||||
|
@ -157,7 +157,8 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(NsxV3Plugin, self).__init__()
|
super(NsxV3Plugin, self).__init__()
|
||||||
LOG.info(_LI("Starting NsxV3Plugin"))
|
LOG.info(_LI("Starting NsxV3Plugin"))
|
||||||
LOG.info(_LI("NSX Version: %s"), nsxlib.get_version())
|
self._nsx_version = nsxlib.get_version()
|
||||||
|
LOG.info(_LI("NSX Version: %s"), self._nsx_version)
|
||||||
self._api_cluster = nsx_cluster.NSXClusteredAPI()
|
self._api_cluster = nsx_cluster.NSXClusteredAPI()
|
||||||
self._nsx_client = nsx_client.NSX3Client(self._api_cluster)
|
self._nsx_client = nsx_client.NSX3Client(self._api_cluster)
|
||||||
nsx_client._set_default_api_cluster(self._api_cluster)
|
nsx_client._set_default_api_cluster(self._api_cluster)
|
||||||
@ -205,17 +206,19 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
"switching profile: %s") % NSX_V3_DHCP_PROFILE_NAME
|
"switching profile: %s") % NSX_V3_DHCP_PROFILE_NAME
|
||||||
raise nsx_exc.NsxPluginException(msg)
|
raise nsx_exc.NsxPluginException(msg)
|
||||||
|
|
||||||
LOG.debug("Initializing NSX v3 Mac Learning switching profile")
|
|
||||||
self._mac_learning_profile = None
|
self._mac_learning_profile = None
|
||||||
try:
|
if utils.is_nsx_version_1_1_0(self._nsx_version):
|
||||||
self._mac_learning_profile = self._init_mac_learning_profile()
|
LOG.debug("Initializing NSX v3 Mac Learning switching profile")
|
||||||
# Only expose the extension if it is supported
|
try:
|
||||||
self.supported_extension_aliases.append('mac-learning')
|
self._mac_learning_profile = self._init_mac_learning_profile()
|
||||||
except Exception as e:
|
# Only expose the extension if it is supported
|
||||||
LOG.warning(_LW("Unable to initialize NSX v3 MAC Learning "
|
self.supported_extension_aliases.append('mac-learning')
|
||||||
"profile: %(name)s. Reason: %(reason)s"),
|
except Exception as e:
|
||||||
{'name': NSX_V3_MAC_LEARNING_PROFILE_NAME,
|
LOG.warning(_LW("Unable to initialize NSX v3 MAC Learning "
|
||||||
'reason': e})
|
"profile: %(name)s. Reason: %(reason)s"),
|
||||||
|
{'name': NSX_V3_MAC_LEARNING_PROFILE_NAME,
|
||||||
|
'reason': e})
|
||||||
|
|
||||||
self._unsubscribe_callback_events()
|
self._unsubscribe_callback_events()
|
||||||
if cfg.CONF.api_replay_mode:
|
if cfg.CONF.api_replay_mode:
|
||||||
self.supported_extension_aliases.append('api-replay')
|
self.supported_extension_aliases.append('api-replay')
|
||||||
|
@ -20,7 +20,9 @@ from oslo_config import cfg
|
|||||||
|
|
||||||
from vmware_nsx._i18n import _LI
|
from vmware_nsx._i18n import _LI
|
||||||
from vmware_nsx.common import nsx_constants
|
from vmware_nsx.common import nsx_constants
|
||||||
|
from vmware_nsx.common import utils as comm_utils
|
||||||
from vmware_nsx.dhcp_meta import rpc as nsx_rpc
|
from vmware_nsx.dhcp_meta import rpc as nsx_rpc
|
||||||
|
from vmware_nsx.nsxlib import v3 as nsxlib
|
||||||
from vmware_nsx.nsxlib.v3 import client
|
from vmware_nsx.nsxlib.v3 import client
|
||||||
from vmware_nsx.nsxlib.v3 import cluster
|
from vmware_nsx.nsxlib.v3 import cluster
|
||||||
from vmware_nsx.nsxlib.v3 import native_dhcp
|
from vmware_nsx.nsxlib.v3 import native_dhcp
|
||||||
@ -50,6 +52,12 @@ def list_dhcp_bindings(resource, event, trigger, **kwargs):
|
|||||||
def nsx_update_dhcp_bindings(resource, event, trigger, **kwargs):
|
def nsx_update_dhcp_bindings(resource, event, trigger, **kwargs):
|
||||||
"""Resync DHCP bindings for NSXv3 CrossHairs."""
|
"""Resync DHCP bindings for NSXv3 CrossHairs."""
|
||||||
|
|
||||||
|
nsx_version = nsxlib.get_version()
|
||||||
|
if not comm_utils.is_nsx_version_1_1_0(nsx_version):
|
||||||
|
LOG.info(_LI("This utility is not available for NSX version %s"),
|
||||||
|
nsx_version)
|
||||||
|
return
|
||||||
|
|
||||||
cluster_api = cluster.NSXClusteredAPI()
|
cluster_api = cluster.NSXClusteredAPI()
|
||||||
nsx_client = client.NSX3Client(cluster_api)
|
nsx_client = client.NSX3Client(cluster_api)
|
||||||
client._set_default_api_cluster(cluster_api)
|
client._set_default_api_cluster(cluster_api)
|
||||||
|
@ -101,6 +101,12 @@ class NsxV3PluginTestCaseMixin(test_plugin.NeutronDbPluginV2TestCase,
|
|||||||
_patch_object(nsx_plugin, 'nsx_client', new=mock_client_module)
|
_patch_object(nsx_plugin, 'nsx_client', new=mock_client_module)
|
||||||
_patch_object(nsx_plugin, 'nsx_cluster', new=mock_cluster_module)
|
_patch_object(nsx_plugin, 'nsx_cluster', new=mock_cluster_module)
|
||||||
|
|
||||||
|
# Mock the nsx v3 version
|
||||||
|
mock_nsxlib_get_version = mock.patch(
|
||||||
|
"vmware_nsx.nsxlib.v3.get_version",
|
||||||
|
return_value='1.1.0')
|
||||||
|
mock_nsxlib_get_version.start()
|
||||||
|
|
||||||
# populate pre-existing mock resources
|
# populate pre-existing mock resources
|
||||||
cluster_id = uuidutils.generate_uuid()
|
cluster_id = uuidutils.generate_uuid()
|
||||||
self.mock_api.post(
|
self.mock_api.post(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user