本文整理汇总了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")
示例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
示例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=(',', ': '))
示例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=(',', ': '))
示例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)
示例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=(',', ': '))
示例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=(',', ': '))
示例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=(',', ': '))
示例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=(',', ': '))
示例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)
示例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
示例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=(',', ': '))
示例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)
示例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"
示例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']