def setUp(self): self.T_HCPFILE = '/rest/hcpsdk/fail_TestHCPsdk_20_access' self.hcptarget = hcpsdk.Target(it.P_NS_GOOD, it.P_AUTH, it.P_SSLPORT, dnscache=it.P_DNSCACHE) self.con = hcpsdk.Connection(self.hcptarget)
def test_01_20_ip_address_not_available(self): """ Make sure an exception is raised if the FQDN can't be resolved """ with self.assertRaises(hcpsdk.ips.IpsError): hcpsdk.Target(it.P_NS_BAD, it.P_AUTH, port=it.P_PORT, dnscache=it.P_DNSCACHE)
def test_01_30_good_target_authority(self): """ Make sure we get a hcpsdk.Target object """ hcptarget = hcpsdk.Target(it.P_NS_GOOD, it.P_AUTH, port=it.P_PORT, dnscache=it.P_DNSCACHE) self.assertIs(type(hcptarget), hcpsdk.Target)
def test_01_10_ip_address_available(self): """ Make sure we can get a single IP address from Target object's pool """ hcptarget = hcpsdk.Target(it.P_NS_GOOD, it.P_AUTH, port=it.P_PORT, dnscache=it.P_DNSCACHE) self.assertTrue(hcptarget.getaddr() in hcptarget.addresses)
def setUp(self): # self.T_NS_GOOD = "n1.m.hcp1.snomis.local" # self.T_USER = "******" # self.T_PASSWORD = "******" # self.T_AUTH = hcpsdk.NativeAuthorization(self.T_USER, self.T_PASSWORD) # self.T_PORT = 443 self.hcptarget = hcpsdk.Target(it.P_NS_GOOD, it.P_AUTH, port=it.P_PORT, dnscache=it.P_DNSCACHE) self.nso = hcpsdk.namespace.Info(self.hcptarget)
def setUp(self): # self.T_NS_GOOD = "admin.hcp1.snomis.local" # self.T_USER = "******" # self.T_PASSWORD = "******" # self.T_AUTH = hcpsdk.NativeAuthorization(self.T_USER, self.T_PASSWORD) # self.T_PORT = 9090 self.hcptarget = hcpsdk.Target(it.P_ADMIN, it.P_ADMAUTH, port=it.P_MAPIPORT, dnscache=it.P_DNSCACHE) self.mapi = hcpsdk.mapi.Replication(self.hcptarget)
def setUp(self): sh = logging.StreamHandler(sys.stderr) fh = logging.Formatter("[%(levelname)-8s]: %(message)s") sh.setFormatter(fh) log = logging.getLogger() log.addHandler(sh) log.setLevel(logging.INFO) self.hcptarget = hcpsdk.Target(it.P_ADMIN, it.P_ADMAUTH, port=it.P_MAPIPORT, dnscache=False)
def setUp(self): print('>>> TestHcpsdk_2_Access_https_systemCA:') self.T_HCPFILE = '/rest/hcpsdk/TestHCPsdk_20_access' self.ctxt = ssl.create_default_context() print('Certificate store status:') pprint(self.ctxt.cert_store_stats()) print('CA certificates:') pprint((self.ctxt.get_ca_certs())) self.hcptarget = hcpsdk.Target(it.P_NS_GOOD, it.P_AUTH, it.P_SSLPORT, dnscache=it.P_DNSCACHE, sslcontext=self.ctxt) self.con = hcpsdk.Connection(self.hcptarget)
def setUp(self): print('>>> TestHcpsdk_1_Access_https_certfile:') self.T_HCPFILE = '/rest/hcpsdk/TestHCPsdk_20_access' self.ctxt = ssl.create_default_context( purpose=ssl.Purpose.SERVER_AUTH, cafile='certs/rootCertificate.pem') print('Certificate store status:') pprint(self.ctxt.cert_store_stats()) print('CA certificates:') pprint((self.ctxt.get_ca_certs())) self.hcptarget = hcpsdk.Target(it.P_NS_GOOD, it.P_AUTH, it.P_SSLPORT, dnscache=it.P_DNSCACHE, sslcontext=self.ctxt) self.con = hcpsdk.Connection(self.hcptarget)
import os import time import hcpsdk if __name__ == '__main__': a = hcpsdk.NativeAuthorization('n', 'n01') t = hcpsdk.Target('n1.m.hcp1.snomis.local', a, port=443) c = hcpsdk.Connection(t) r = c.GET('/rest/hcpsdk/testfile2.mp4') print(c.response_status, c.response_reason) print('len(c.read(1024)) = {}'.format(len(c.read(1024)))) for i in range(10): print('.', end='', flush=True) time.sleep(1) print() try: print('len(c.read()) = {}'.format(len(c.read()))) except Exception as e: print(str(e)) raise e finally: c.close()
def setUp(self): self.hcptarget = hcpsdk.Target(it.L_ADMIN, it.L_ADMAUTH, port=it.L_MAPIPORT, dnscache=it.L_DNSCACHE) self.logs = hcpsdk.mapi.Logs(self.hcptarget)
url = '<hcpname>.hcp.<domain>.com' tenantshortnamelist = [] tenantfullnamelist = [] namespacenamelist = [] nscapacityinfolist = [] nsquotainfolist = [] adminportal = 'admin.'+url today = datetime.date.today() datestr = str(today.year)+"/"+str(today.month)+"/"+str(today.day) auth = hcpsdk.NativeAuthorization('<monitoring user>', '<password>') tgt = hcpsdk.Target( adminportal, auth, port=hcpsdk.P_MAPI) alltenants = hcpsdk.mapi.listtenants(tgt) for atenant in alltenants: tenantshortnamelist.append(atenant.name) for btenant in alltenants: tgttnts = hcpsdk.Target(btenant.name+'.'+url, auth, port=443) tenantfullnamelist.append(tgttnts._Target__fqdn) for tenantfullname in tenantfullnamelist: tgttnt = hcpsdk.Target(tenantfullname, auth, port=hcpsdk.P_MAPI) c = hcpsdk.Connection(tgttnt) for tenantsn in tenantshortnamelist:
print = pprint = logging.info # end sample block 15 # noinspection PyUnboundLocalVariable print('running *simple_primary_only.py*') # start sample block 17 # Setup an authorization object: auth = hcpsdk.NativeAuthorization(P_USER, P_PASS) print('*I_NATIVE* authorization initialized') print('') # end sample block 17 # start sample block 20 # Setup an HCP Target object: try: t = hcpsdk.Target(P_FQDN, auth, port=P_PORT) except hcpsdk.HcpsdkError as e: sys.exit('init of *Target* failed - {}'.format(e)) else: print('Target *t* was initialized with IP addresses: {}'.format( t.addresses)) # end sample block 20 # start sample block 30 # Setup a Connection object: try: c = hcpsdk.Connection(t) except hcpsdk.HcpsdkError as e: sys.exit('init of *Target* failed - {}'.format(e)) else: print('Connection *c* uses IP address: {}'.format(c.address))
# end sample block 15 # noinspection PyUnboundLocalVariable print('running *simple_primary_only.py*') # start sample block 17 # Setup an authorization object: auth = hcpsdk.NativeAuthorization(P_USER, P_PASS) print('*I_NATIVE* authorization initialized') print('') # Create an SSL context for server authentication, using a local CAfile ctxt = create_default_context(cafile=P_CAFILE) # Setup an HCP Target object: try: t = hcpsdk.Target(P_FQDN, auth, port=P_PORT, sslcontext=ctxt) except hcpsdk.HcpsdkError as e: sys.exit('init of *Target* failed - {}'.format(e)) else: print('Target *t* was initialized with IP addresses: {}'.format( t.addresses)) # end sample block 20 # start sample block 30 # Setup a Connection object: try: c = hcpsdk.Connection(t) except hcpsdk.HcpsdkError as e: sys.exit('init of *Target* failed - {}'.format(e)) else: print('Connection *c* uses IP address: {}'.format(c.address))
logging.basicConfig(level=logging.DEBUG, style='{', format='{levelname:>5s} {msg}') # noinspection PyShadowingBuiltins print = pprint = logging.info # the place where we will find the needed source objects if sys.platform == 'win32': T_INPATH = 'd:\\__files' elif sys.platform == 'darwin': T_INPATH = '/Volumes/dev/__files' else: sys.exit('source path is undefined') print("--> Init <hcptarget> object") try: auth = hcpsdk.NativeAuthorization(T_DAAC, T_DAAC_PWD) hcptarget = hcpsdk.Target(T_NAMESPACE, auth, T_PORT) except hcpsdk.HcpsdkError as e: sys.exit("Fatal: {}".format(e.errText)) print("--> Init {} <connection> object(s)".format(T_THREADS)) conns = None conntimes = 0.0 outer_contime = time.time() try: conns = hcpsdk.Connection(hcptarget, debuglevel=0, idletime=3) except Exception as e: sys.exit('Exception: {}'.format(str(e))) else: conntimes += conns.connect_time outer_contime = time.time() - outer_contime
''' Print a simple progress meter ''' sz = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] i = 0 while nBytes > 1023: nBytes = nBytes / 1024 i = i + 1 print("\rreceived: {0:.2f} {1:}".format(nBytes, sz[i]), end='') if __name__ == '__main__': auth = hcpsdk.NativeAuthorization(USR, PWD) try: t = hcpsdk.Target(TGT, auth, port=PORT) except hcpsdk.ips.IpsError as e: sys.exit('Can\'t resolve "{}"\n\t==> {}'.format(TGT, e)) l = hcpsdk.mapi.Logs(t, debuglevel=0) # create console handler with a higher log level sh = logging.StreamHandler(sys.stderr) fh = logging.Formatter("[%(levelname)-8s]: %(message)s") sh.setFormatter(fh) log = logging.getLogger() log.addHandler(sh) # this makes the logger silent, until *debug* has activated log.setLevel(logging.CRITICAL) LogsShell().cmdloop()