예제 #1
0
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()

Any analysis can be done from the data in the database at a future point '''


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)
예제 #3
0
# primary HCP
P_HCP = 'hcp73.archivas.com'
P_ADMIN = 'admin.' + P_HCP
P_TENANT = 'm.' + P_HCP
P_NS_GOOD = 'n9.' + P_TENANT
P_NS_BAD = "this_wont_work.at-all"
P_PORT = 80
P_SSLPORT = 443
P_ADMINPORT = 8000
P_MAPIPORT = 9090
P_DNSCACHE = True

P_USER = "******"
P_PASSWORD = "******"
P_AUTH = hcpsdk.NativeAuthorization(P_USER, P_PASSWORD)

P_ADMUSER = "******"
P_ADMPWD = "service01"
P_ADMAUTH = hcpsdk.NativeAuthorization(P_ADMUSER, P_ADMPWD)

# replica HCP
R_HCP = 'hcp72.archivas.com'
R_ADMIN = 'admin' + R_HCP
R_TENANT = 'm.' + R_HCP
R_NS_GOOD = 'n.' + R_TENANT
R_NS_BAD = "this_wont_work.at-all"
R_PORT = P_PORT
R_ADMINPORT = P_ADMINPORT
R_MAPIPORT = P_MAPIPORT
R_DNSCACHE = P_DNSCACHE
예제 #4
0
    # end sample block 10
    # start sample block 15
    if P_DEBUG:
        import logging
        logging.basicConfig(level=logging.DEBUG,
                            style='{',
                            format='{levelname:>5s} {msg}')
        # noinspection PyShadowingBuiltins
        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
예제 #5
0
        import logging
        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
예제 #6
0
def showdownloadprogress(nBytes):
    '''
    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)