def getDBUUID(self): routes = ['dbUUID'] err, response = self.makeGet(routes) if response is not None: ConnectionManager.addInstance(response['dbUUID'], self.managementConnection) return None, response else: return err, None
def __init__(self, user=None, password=None, logger=None, managementServers=None, managementProtocol='https', dbUUID=None): """**Initializes a singleton connection to the management server, by default uses an application user, it is optional to provide a different user and password for the connection.** :param user: management user name, defaults to None :type user: str, optional :param password: password for the management user, defaults to None :type password: str, optional :param managementServers: The string should be in the following format: \"<server name or IP>:<port>,<server name or IP>:<port>,...\", defaults to None :type managementServers: str, optional :param managementProtocol: The management servers protocol, defaults to https :type managementProtocol: str, optional :raises ConnectionManagerError: If there was a problem connecting to the management server. """ self.logger = logger if logger else Logger().getLogger('NVMeshSDK') if not managementServers: managementServers, managementProtocol = self.getManagementServersAndProtocolFromConfigs( ) managementServers = Utils.transformManagementClusterToUrls( managementServers, managementProtocol) if not dbUUID: dbUUID = self.getDBUUID(managementServers) try: if user is not None and password is not None: self.managementConnection = ConnectionManager.getInstance( dbUUID=dbUUID, user=user, password=password, logger=logger, managementServers=managementServers) else: self.managementConnection = ConnectionManager.getInstance( dbUUID=dbUUID, logger=logger, managementServers=managementServers) except ConnectionManagerError as e: raise e
def init_nvmesh_sdk(): connected = False # try until able to connect to NVMesh Management while not connected: try: ConnectionManager.getInstance( managementServer=[NVMESH_MGMT_ADDRESS], logToSysLog=False) connected = ConnectionManager.getInstance().isAlive() except ManagementTimeout as ex: logger.info( "Waiting for NVMesh Management server on {}".format( NVMESH_MGMT_ADDRESS)) time.sleep(1) logger.info("Connected to NVMesh Management server on {}".format( ConnectionManager.getInstance().managementServer))
def __init__(self, user=None, password=None): """**Initializes a singleton connection to the management server, by default uses an application user, it is optional to provide a different user and password for the connection.** :param user: management user name, defaults to None :type user: str, optional :param password: password for the management user, defaults to None :type password: str, optional :raises ConnectionManagerError: If there was a problem connecting to the management server. """ try: if user is not None and password is not None: self.managementConnection = ConnectionManager.getInstance( user=user, password=password) else: self.managementConnection = ConnectionManager.getInstance() except ConnectionManagerError as e: raise e
def init_sdk(): connected = False # try until able to connect to NVMesh Management print( "Looking for a NVMesh Management server using {} from servers {}". format(Config.MANAGEMENT_PROTOCOL, Config.MANAGEMENT_SERVERS)) while not connected: try: NVMeshSDKHelper._try_get_sdk_instance() connected = ConnectionManager.getInstance().isAlive() except ManagementTimeout as ex: NVMeshSDKHelper.logger.info( "Waiting for NVMesh Management server on {}".format( ConnectionManager.getInstance().managementServer)) Utils.interruptable_sleep(10) print("Connected to NVMesh Management server on {}".format( ConnectionManager.getInstance().managementServer))
def get_management_version_info(): err, out = ConnectionManager.getInstance().get('/version') if not err: version_info = {} lines = out.split('\n') for line in lines: try: key_val_pair = line.split('=') key = key_val_pair[0] value = key_val_pair[1].replace('"', '') version_info[key] = value except: pass return version_info return None
def _try_get_sdk_instance(): protocol = Config.MANAGEMENT_PROTOCOL managementServers = Config.MANAGEMENT_SERVERS user = Config.MANAGEMENT_USERNAME password = Config.MANAGEMENT_PASSWORD serversWithProtocol = [ '{0}://{1}'.format(protocol, server) for server in managementServers.split(',') ] return ConnectionManager.getInstance( managementServer=serversWithProtocol, user=user, password=password, logToSysLog=False)
def _check_for_volume_api_wrong_zone_bug(api, api_params, log): allowed_mgmt_servers = [ 'https://' + address for address in api_params['managementServers'].split(',') ] if api.managementConnection.managementServers[ 0] not in allowed_mgmt_servers: # This means we asked for a connection to management server cluster A but got a connection to management server cluster B db_uuid_to_servers = [ 'db_uuid={} servers={}'.format(db_uuid, conn_mgr.managementServers) for db_uuid, conn_mgr in ConnectionManager.debug_getInstances().items() ] log.debug('SDK internals: {}'.format(db_uuid_to_servers)) raise ValueError( 'BUG! Got wrong API object! got Connection for {} but expected one of {}' .format(api.managementConnection.managementServers[0], allowed_mgmt_servers))
def __init__(self, managementServersUrls, logger=None): try: self.managementConnection = ConnectionManager.getInstance(managementServers=managementServersUrls, dbUUID=None, logger=logger) except ConnectionManagerError as e: raise e