當前位置: 首頁>>代碼示例>>Python>>正文


Python sdk.UcloudApiClient類代碼示例

本文整理匯總了Python中sdk.UcloudApiClient的典型用法代碼示例。如果您正苦於以下問題:Python UcloudApiClient類的具體用法?Python UcloudApiClient怎麽用?Python UcloudApiClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了UcloudApiClient類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create

def create(tag=None, name=None, password='dangerous', cpu='1', memory=2, diskSpace=50, imageId="uimage-j4fbrn",
           uhostType='Normal',StorageType='LocalDisk'):
    ApiClient = UcloudApiClient(base_url, public_key, private_key)
    Parameters = {
        "Action": "CreateUHostInstance",
        "Region": region,
        "Zone":zone,
        "ImageId": imageId,
        "LoginMode": "Password",
        "Password": base64.b64encode(password),
        "Tag": tag,
        "CPU": cpu,
        "Memory": int(memory) * 1024,
        "DiskSpace": int(diskSpace),
        "Name": name,
        "StorageType":StorageType,
        "UHostType": uhostType  # SATA_SSD ,BigData

    }
    response = ApiClient.get("/", Parameters)
    if 0 != response['RetCode']:
        print response
        exit(1)

    for i in range(120):
        time.sleep(1)
        host = get(name)
        if host and 'IPSet' in host and 'IP' in host['IPSet'][0]:  # and 'Running' in host['State']
            print host['IPSet'][0]['IP']
            return host
    raise TypeError("can not get host info")
開發者ID:zgfh,項目名稱:ucloud-cli,代碼行數:31,代碼來源:host_utils.py

示例2: flush_cdn

def flush_cdn(DomainId,UrlList,Type='dir'):
    ApiClient = UcloudApiClient(base_url, public_key, private_key)
    Parameters = {
        "Action": "RefreshUcdnDomainCache",
        "Region": region,
        "Zone":zone,
        "ProjectId":project_id,
        "DomainId": DomainId,
        "Type": Type,
        "UrlList.0": UrlList
    }
    response = ApiClient.get("/", Parameters)
    if 0 != response['RetCode']:
        print response
        exit(1)
    print response
    taskId=response['TaskId']
    for i in range(1200):
        status=flush_task_status_cdn(DomainId,taskId)
        print status
        if status=="success":
            return True
        elif status=="failure":
            return False
        time.sleep(1)
    return False
開發者ID:zgfh,項目名稱:ucloud-cli,代碼行數:26,代碼來源:cdn_utils.py

示例3: get_all

def get_all():
    ApiClient = UcloudApiClient(base_url, public_key, private_key)
    Parameters = {
        "Action": "DescribeUHostInstance",
        "Region": region,
        "Limit": '100000'
    }
    response = ApiClient.get("/", Parameters);

    print json.dumps(response, sort_keys=True, indent=4, separators=(',', ': '))
開發者ID:zgfh,項目名稱:ucloud-cli,代碼行數:10,代碼來源:host_utils.py

示例4: delete

def delete(ip):
    ip = get(ip)
    ApiClient = UcloudApiClient(base_url, public_key, private_key)
    Parameters = {
        "Action": "ReleaseEIP",
        "Region": region,
        "EIPId": ip['EIPId']
    }
    response = ApiClient.get("/", Parameters);

    print json.dumps(response, sort_keys=True, indent=4, separators=(',', ': '))
開發者ID:zgfh,項目名稱:ucloud-cli,代碼行數:11,代碼來源:ip_utils.py

示例5: get_ulb_list

def get_ulb_list(region):
    """get one user's ulb list"""
    api_client = UcloudApiClient(config.base_url, config.public_key,
                                 config.private_key)

    params = {};
    params['Action'] = "DescribeULB"
    params['Region'] = "cn-bj1"

    response = api_client.get("/", params)
    pprint(response)
開發者ID:yuexizhaohong,項目名稱:python,代碼行數:11,代碼來源:get_ulb_list.py

示例6: delete

def delete(ip):
    host = get(ip=ip)
    stop(ip, check=True)
    ApiClient = UcloudApiClient(base_url, public_key, private_key)
    Parameters = {
        "Action": "TerminateUHostInstance",
        "Region": region,
        "UHostId": host['UHostId']
    }
    response = ApiClient.get("/", Parameters);

    print json.dumps(response, sort_keys=True, indent=4, separators=(',', ': '))
開發者ID:zgfh,項目名稱:ucloud-cli,代碼行數:12,代碼來源:host_utils.py

示例7: modify_eip_weight

def modify_eip_weight(ip,weight=50):
    ip = get(ip)
    print 'start modify_eip_weight {} to weight{} '.format(ip,weight)
    ApiClient = UcloudApiClient(base_url, public_key, private_key)
    Parameters = {
        "Action": "ModifyEIPWeight",
        "Region": region,
        'Weight':weight,
        "EIPId": ip['EIPId']
    }
    response = ApiClient.get("/", Parameters);

    print json.dumps(response, sort_keys=True, indent=4, separators=(',', ': '))
開發者ID:zgfh,項目名稱:ucloud-cli,代碼行數:13,代碼來源:ip_utils.py

示例8: unbing

def unbing(ip,hostId):
    ip = get(ip)
    ApiClient = UcloudApiClient(base_url, public_key, private_key)
    Parameters = {
        "Action": "UnBindEIP",
        "Region": region,
        'ResourceType':'uhost',
        'ResourceId':hostId, #TODO
        "EIPId": ip['EIPId']
    }
    response = ApiClient.get("/", Parameters);

    print json.dumps(response, sort_keys=True, indent=4, separators=(',', ': '))
開發者ID:zgfh,項目名稱:ucloud-cli,代碼行數:13,代碼來源:ip_utils.py

示例9: stop

def stop(ip, check=False):
    host = get(ip=ip)
    ApiClient = UcloudApiClient(base_url, public_key, private_key)
    Parameters = {
        "Action": "StopUHostInstance",
        "Region": region,
        "UHostId": host['UHostId']
    }
    response = ApiClient.get("/", Parameters);
    if check:
        checkStatus(ip, 'Stopped')

    print json.dumps(response, sort_keys=True, indent=4, separators=(',', ': '))
開發者ID:zgfh,項目名稱:ucloud-cli,代碼行數:13,代碼來源:host_utils.py

示例10: get_metric

def get_metric(region, resource_type, resource_id, metric_name,
               timerange=1 * 60 * 60):
    """Get UCloud monitor data
    Region: "cn-east-01"|"cn-north-01"|"cn-south-01"|"hk-01"|"cn-north-02"
                華東       北京bgpa         華南      香港    北京bgpb
    ResourceType: 'uhost'|'udb'|'umem'|'ulb'
    MetricName:
        uhost:
            'NetworkIn'
            'NetworkOut'
            'CPUUtilization'
            'IORead'
            'IOWrite'
            'DiskReadOps'
            'DiskWriteOps'
            'NICIn'
            'NICOut'
            'MemUsage'
            'DataSpaceUsage'
            'RootSpaceUsage'
            'ReadonlyDiskCount'
            'RunnableProcessCount'
            'BlockProcessCount'
        udb:
            'CPUUtilization'
            'MemUsage'
            'QPS'
            'ExpensiveQuery'

        ulb:
            'NetworkOut'
            'CurrentConnections'

        umem:
            'Usage'
            'QPS'
            'InstanceCount'

    """
    api_client = UcloudApiClient(config.base_url, config.public_key,
                                 config.private_key)

    params = {};
    params['Region'] = region
    params['Action'] = 'GetMetric' 
    params['ResourceType'] = resource_type 
    params['ResourceID'] = resource_id 
    params['MetricName'] = metric_name
    params['TimeRange'] = timerange 
    response = api_client.get("/", params)
    pprint(response)
開發者ID:alkaiddiamond,項目名稱:python-sdk-v2,代碼行數:51,代碼來源:get_metric.py

示例11: get

def get(ip=None,tag=None):
    ApiClient = UcloudApiClient(base_url, public_key, private_key)
    Parameters = {
        "Action": "DescribeEIP",
        "Region": region,
        "Limit": '100000'
    }
    ips = ApiClient.get("/", Parameters)
    #print ips
    for ip_tmp in ips['EIPSet']:
        if ip and  ip == ip_tmp['EIPAddr'][0]['IP'] :
            return ip_tmp
        if tag and tag == ip_tmp['Tag'] :
            return ip_tmp
開發者ID:zgfh,項目名稱:ucloud-cli,代碼行數:14,代碼來源:ip_utils.py

示例12: ReinstallUHostInstance

def ReinstallUHostInstance(ip, password='dangerous', imageId='uimage-j4fbrn'):
    host = get(ip=ip)
    poweroff(ip, check=True)
    ApiClient = UcloudApiClient(base_url, public_key, private_key)
    Parameters = {
        "Action": "ReinstallUHostInstance",
        "Region": region,
        "UHostId": host['UHostId'],
        "Password": base64.b64encode(password),
        "ImageId": imageId
    }
    response = ApiClient.get("/", Parameters);

    print json.dumps(response, sort_keys=True, indent=4, separators=(',', ': '))
開發者ID:zgfh,項目名稱:ucloud-cli,代碼行數:14,代碼來源:host_utils.py

示例13: get_metric

def get_metric(region, resource_type, resource_id, metric_name,
               timerange=1 * 60 * 60):
    """Get UCloud monitor data
    Region: "cn-east-01"|"cn-north-01"|"cn-south-01"|"hk-01"|"cn-north-02"
            East China   Bejing bgpa   South China  Hong Kong   Beijing bgpb
    ResourceType: 'uhost'|'udb'|'umem'|'ulb'
    MetricName:
        uhost:
            'NetworkIn'
            'NetworkOut'
            'CPUUtilization'
            'IORead'
            'IOWrite'
            'DiskReadOps'
            'DiskWriteOps'
            'NICIn'
            'NICOut'
            'MemUsage'
            'DataSpaceUsage'
            'RootSpaceUsage'
            'ReadonlyDiskCount'
            'RunnableProcessCount'
            'BlockProcessCount'
        udb:
            'CPUUtilization'
            'MemUsage'
            'QPS'
            'ExpensiveQuery'

        ulb:
            'NetworkOut'
            'CurrentConnections'

        umem:
            'Usage'
            'QPS'
            'InstanceCount'

    """
    api_client = UcloudApiClient(config.base_url, config.public_key,
                                 config.private_key)

    response = api_client.get("/", Action="GetMetric",
                              Region=region,
                              ResourceType=resource_type,
                              ResourceID=resource_id,
                              MetricName=metric_name,
                              TimeRange=timerange)
    pprint(response)
開發者ID:bragr,項目名稱:python-sdk-v2,代碼行數:49,代碼來源:get_metric.py

示例14: get

def get(host_name='', ip=''):
    ApiClient = UcloudApiClient(base_url, public_key, private_key)
    Parameters = {
        "Action": "DescribeUHostInstance",
        "Region": region,
        "Limit": '100000'
    }
    hosts = ApiClient.get("/", Parameters)

    for host in hosts['UHostSet'] :
        if 'Name' in host and 'IPSet' in host and len(host['IPSet'])>0 and 'IP' in host['IPSet'][0]:
            if host_name == host['Name'] or ip == host['IPSet'][0]['IP']:
                return host
        else:
            print "get host Describe err"
開發者ID:zgfh,項目名稱:ucloud-cli,代碼行數:15,代碼來源:host_utils.py

示例15: flush_task_status_cdn

def flush_task_status_cdn(DomainId,TaskId):
    ApiClient = UcloudApiClient(base_url, public_key, private_key)
    Parameters = {
        "Action": "DescribeRefreshCacheTask",
        "Region": region,
        "Zone":zone,
        "ProjectId":project_id,
        "DomainId": DomainId,
        "TaskId": TaskId
    }
    response = ApiClient.get("/", Parameters)
    if 0 != response['RetCode']:
        print response
        exit(1)
    return response['TaskSet'][0]['Status']
開發者ID:zgfh,項目名稱:ucloud-cli,代碼行數:15,代碼來源:cdn_utils.py


注:本文中的sdk.UcloudApiClient類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。