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
|
||||
# under the License.
|
||||
|
||||
from distutils import version
|
||||
import functools
|
||||
import hashlib
|
||||
|
||||
import eventlet
|
||||
from neutron import version
|
||||
from neutron import version as n_version
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib import exceptions
|
||||
from oslo_config import cfg
|
||||
@ -33,9 +34,10 @@ LOG = log.getLogger(__name__)
|
||||
MAX_DISPLAY_NAME_LEN = 40
|
||||
MAX_RESOURCE_TYPE_LEN = 20
|
||||
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'
|
||||
OS_NEUTRON_ID_SCOPE = 'os-neutron-id'
|
||||
NSXV3_VERSION_1_1_0 = '1.1.0'
|
||||
|
||||
|
||||
# Allowed network types for the NSX Plugin
|
||||
@ -66,6 +68,11 @@ class NsxV3NetworkTypes:
|
||||
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):
|
||||
tags = ([dict(tag=value, scope=key)
|
||||
for key, value in six.iteritems(kwargs)])
|
||||
@ -116,7 +123,7 @@ def build_v3_api_version_tag():
|
||||
return [{'scope': OS_NEUTRON_ID_SCOPE,
|
||||
'tag': NSX_NEUTRON_PLUGIN},
|
||||
{'scope': "os-api-version",
|
||||
'tag': version.version_info.release_string()}]
|
||||
'tag': n_version.version_info.release_string()}]
|
||||
|
||||
|
||||
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',
|
||||
'tag': project_name[:MAX_TAG_LEN]},
|
||||
{'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):
|
||||
|
@ -157,7 +157,8 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
def __init__(self):
|
||||
super(NsxV3Plugin, self).__init__()
|
||||
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._nsx_client = nsx_client.NSX3Client(self._api_cluster)
|
||||
nsx_client._set_default_api_cluster(self._api_cluster)
|
||||
@ -205,8 +206,9 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
"switching profile: %s") % NSX_V3_DHCP_PROFILE_NAME
|
||||
raise nsx_exc.NsxPluginException(msg)
|
||||
|
||||
LOG.debug("Initializing NSX v3 Mac Learning switching profile")
|
||||
self._mac_learning_profile = None
|
||||
if utils.is_nsx_version_1_1_0(self._nsx_version):
|
||||
LOG.debug("Initializing NSX v3 Mac Learning switching profile")
|
||||
try:
|
||||
self._mac_learning_profile = self._init_mac_learning_profile()
|
||||
# Only expose the extension if it is supported
|
||||
@ -216,6 +218,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
"profile: %(name)s. Reason: %(reason)s"),
|
||||
{'name': NSX_V3_MAC_LEARNING_PROFILE_NAME,
|
||||
'reason': e})
|
||||
|
||||
self._unsubscribe_callback_events()
|
||||
if cfg.CONF.api_replay_mode:
|
||||
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.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.nsxlib import v3 as nsxlib
|
||||
from vmware_nsx.nsxlib.v3 import client
|
||||
from vmware_nsx.nsxlib.v3 import cluster
|
||||
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):
|
||||
"""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()
|
||||
nsx_client = client.NSX3Client(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_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
|
||||
cluster_id = uuidutils.generate_uuid()
|
||||
self.mock_api.post(
|
||||
|
Loading…
x
Reference in New Issue
Block a user