def __init__(self, target, debuglevel=0): """ :param target: an hcpsdk.Target object :param debuglevel: 0..9 (used in *http.client*) """ self.logger = logging.getLogger(__name__ + '.Replication') hcpsdk.checkport(target, hcpsdk.P_MAPI) self.target = target self.debuglevel = debuglevel self.connect_time = 0.0 self.service_time = 0.0
def listtenants(target, timeout=60, debuglevel=0): """ Get a list of available Tenants :param target: an hcpsdk.Target object :param timeout: the connection timeout in seconds :param debuglevel: 0..9 (used in *http.client*) :returns: a list() of *Tenant()* objects :raises: *hcpsdk.HcpsdkPortError* in case *target* is initialized with a port different that *P_MAPI* """ logger = logging.getLogger(__name__) logger.debug('getting a list of Tenants') hcpsdk.checkport(target, hcpsdk.P_MAPI) tenantslist = [] try: con = hcpsdk.Connection(target, timeout=timeout, debuglevel=debuglevel) except Exception as e: raise hcpsdk.HcpsdkError(str(e)) try: con.GET('/mapi/tenants', headers={'Accept': 'application/json'}, params={'verbose': 'true'}) except Exception as e: logger.debug('getting a list of Tenants failed: {}'.format(e)) raise TenantError('get Tenant list failed: {}'.format(e)) else: if con.response_status == 200: for t in loads(con.read().decode())['name']: tenantslist.append(Tenant(target, t, debuglevel=debuglevel)) logger.debug('got a list of {} Tenants'.format(len(tenantslist))) else: con.close() logger.debug('getting a list of Tenants failed: {}-{}'.format( con.response_status, con.response_reason)) raise TenantError('unable to list Tenants ({} - {})'.format( con.response_status, con.response_reason)) con.close() return tenantslist
def listtenants(target, timeout=60, debuglevel=0): """ Get a list of available Tenants :param target: an hcpsdk.Target object :param timeout: the connection timeout in seconds :param debuglevel: 0..9 (used in *http.client*) :returns: a list() of *Tenant()* objects :raises: *hcpsdk.HcpsdkPortError* in case *target* is initialized with a port different that *P_MAPI* """ logger = logging.getLogger(__name__) logger.debug('getting a list of Tenants') hcpsdk.checkport(target, hcpsdk.P_MAPI) tenantslist = [] try: con = hcpsdk.Connection(target, timeout=timeout, debuglevel=debuglevel) except Exception as e: raise hcpsdk.HcpsdkError(str(e)) try: con.GET('/mapi/tenants', headers={'Accept': 'application/json'}, params={'verbose': 'true'}) except Exception as e: logger.debug('getting a list of Tenants failed: {}'.format(e)) raise TenantError('get Tenant list failed: {}'.format(e)) else: if con.response_status == 200: for t in loads(con.read().decode())['name']: tenantslist.append(Tenant(target, t, debuglevel=debuglevel)) logger.debug('got a list of {} Tenants'.format(len(tenantslist))) else: con.close() logger.debug('getting a list of Tenants failed: {}-{}' .format(con.response_status, con.response_reason)) raise TenantError('unable to list Tenants ({} - {})' .format(con.response_status, con.response_reason)) con.close() return tenantslist
def __init__(self, target, debuglevel=0): """ :param target: an hcpsdk.Target object :param debuglevel: 0..9 (used in *http.client*) :raises: *hcpsdk.HcpsdkPortError* in case *target* is initialized with an incorrect port for use by this class. """ self.logger = logging.getLogger(__name__ + '.Logs') hcpsdk.checkport(target, hcpsdk.P_MAPI) self.target = target self.debuglevel = debuglevel self.connect_time = 0.0 self.service_time = 0.0 self.prepare_xml = None self.suggestedfilename = '' # the filename suggested by HCP try: self.con = hcpsdk.Connection(self.target, debuglevel=self.debuglevel) except Exception as e: raise hcpsdk.HcpsdkError(str(e))
def __init__(self, target, timeout=600, debuglevel=0): ''' :param target: an hcpsdk.Target object pointing to an HCP FQDN starting with **admin.** for access from a system level account or **<tenant>.** for a tenant level account :param timeout: the connection timeout; relatively high per default, as generating the report can take longer than **hcpsdk**\ s default of 30 seconds on a busy system :param debuglevel: 0..9 (used in *http.client*) ''' self.logger = logging.getLogger(__name__ + '.Chargeback') hcpsdk.checkport(target, hcpsdk.P_MAPI) self.connect_time = 0.0 self.service_time = 0.0 try: self.con = hcpsdk.Connection(target, timeout=timeout, debuglevel=debuglevel) except Exception as e: raise hcpsdk.HcpsdkError(str(e))