Add manager status validation to validate connection

When validating if a connection with the NSX manager is up, also check
the manager status directly

Change-Id: I5de7054a058a74e8237a3344e0951ce37976c135
changes/81/627181/6
Adit Sarfaty 4 years ago
parent 77d8d2bf5b
commit 470fea025e
  1. 29
      vmware_nsxlib/v3/__init__.py
  2. 4
      vmware_nsxlib/v3/cluster.py
  3. 4
      vmware_nsxlib/v3/config.py

@ -69,8 +69,10 @@ class NsxLibBase(object):
def set_config(self, nsxlib_config):
"""Set config user provided and extend it according to application"""
self.nsxlib_config = nsxlib_config
self.nsxlib_config.extend(keepalive_section=self.keepalive_section,
url_base=self.client_url_prefix)
self.nsxlib_config.extend(
keepalive_section=self.keepalive_section,
validate_connection_method=self.validate_connection_method,
url_base=self.client_url_prefix)
@abc.abstractproperty
def client_url_prefix(self):
@ -80,6 +82,10 @@ class NsxLibBase(object):
def keepalive_section(self):
pass
@abc.abstractproperty
def validate_connection_method(self):
pass
@abc.abstractmethod
def init_api(self):
pass
@ -312,6 +318,20 @@ class NsxLib(NsxLibBase):
def keepalive_section(self):
return 'transport-zones'
@property
def validate_connection_method(self):
"""Return a method that will validate the NSX manager status"""
def check_manager_status(client, manager_url):
status = client.get('node/services/manager/status', silent=True)
if (not status or 'runtime_state' not in status or
status['runtime_state'] != 'running'):
msg = _("Manager is not in running state: %s") % status
LOG.warning(msg)
raise exceptions.ResourceNotFound(
manager=manager_url, operation=msg)
return check_manager_status
def get_version(self):
if self.nsx_version:
return self.nsx_version
@ -451,6 +471,11 @@ class NsxPolicyLib(NsxLibBase):
def keepalive_section(self):
return 'infra'
@property
def validate_connection_method(self):
# TODO(asarfaty): Find an equivalent api to check policy status
pass
def get_version(self):
"""Get the NSX Policy manager version

@ -189,6 +189,10 @@ class NSXRequestsHTTPProvider(AbstractHTTPProvider):
LOG.warning(msg)
raise exceptions.ResourceNotFound(
manager=endpoint.provider.url, operation=msg)
# Also check the manager state directly
if cluster_api.nsxlib_config.validate_connection_method:
cluster_api.nsxlib_config.validate_connection_method(
client, endpoint.provider.url)
def new_connection(self, cluster_api, provider):
config = cluster_api.nsxlib_config

@ -145,9 +145,11 @@ class NsxLibConfig(object):
'dhcp_profile_uuid is not used by the nsxlib, and will '
'be removed from its configuration in the future.')
def extend(self, keepalive_section, url_base=None):
def extend(self, keepalive_section, validate_connection_method=None,
url_base=None):
"""Called by library code to initialize application-specific data"""
self.keepalive_section = keepalive_section
self.validate_connection_method = validate_connection_method
self.url_base = url_base
def _attribute_by_index(self, scalar_or_list, index):

Loading…
Cancel
Save