def find_eip_uhost_id(eip, rzone): #获得该项目的所有EIP,遍历找到输入的eip client = Client({ "region": rzone, "project_id": project_id, "public_key": public_key, "private_key": private_key }) try: resp = client.invoke("DescribeEIP") except exc.RetCodeException as e: resp = e eipSets = resp.get('EIPSet') for eipSet in eipSets: ip = eipSet.get('EIPAddr')[0].get('IP') if ip == eip: #如果找到输入的IP,则记下eipid和uhostid eip_id = eipSet.get('EIPId') uhost_id = eipSet.get('Resource').get('ResourceID') id_array.append(eip) id_array.append(eip_id) id_array.append(uhost_id) #return uhost_id d = {"UHostIds": [uhost_id]} # 构造请求字典 try: resp = client.uhost().describe_uhost_instance(d) except exc.UCloudException as e: print(e) else: for i in range(len(resp['UHostSet'][0]['DiskSet'])): if i < 1: # print('just only system disk') pass else: disk_id = resp['UHostSet'][0]['DiskSet'][i]['DiskId'] id_array.append(disk_id) switch_arry = id_array.copy() # bind_all.extend(id_array) # switch_serial = bind_all.copy() # serialization.append(switch_serial) total_renew.append(switch_arry) #print(total_renew) id_array.clear()
def ip_related_region(): for region in regions: region_attemp = region #构造client字典 client = Client({ "region": region_attemp, "project_id": project_id, "public_key": public_key, "private_key": private_key }) try: resp = client.invoke("DescribeEIP") except exc.RetCodeException as e: resp = e eipset1 = resp.get('EIPSet') if eipset1: eipset2 = eipset1[0].get('EIPAddr') for i in range(len(eipset1)): for j in range(len(eipset2)): eip_get = eipset1[i].get('EIPAddr')[j].get("IP") if eip_get in eip_array: #print([eip_get,region_attemp]) eip_region_array.append([eip_get, region_attemp])
client = Client({ "region": "", # 相关REGION信息。https://docs.ucloud.cn/api/summary/regionlist "project_id": "", # https://console.ucloud.cn/dashboard 页面左上角获取 "public_key": "", "private_key": "", # 公私钥 https://console.ucloud.cn/uapi/apikey "base_url": "https://api.ucloud.cn", }) data = { "Zone": "", # 相关Zone信息。可用区ABCD在region后添加01、02、03、04 # "ResourceId": '', #控制台获取资源id # "BeginTime": int(time.time()-60), # "EndTime": int(time.time()), # 开始结束时间控制在一分钟 # "MetricName.0": "NetworkOutUsage", # "MetricName.1": "NetworkIn", # "MetricName.2": "NetworkOut", # "MetricName.3": "NetworkInUsage", # 查询监控的指标项。目前仅允许以下四项:NetworkOut:出向带宽,NetworkIn:入向带宽,NetworkOutUsage:出向带宽使用率,NetworkInUsage:入向带宽使用率 "ResourceType": 'uhost' # 资源类型 } # 具体产品参数在https://docs.ucloud.cn/api/ try: resp = client.invoke("GetPathXMetric", data) # 此处填写action except exc.RetCodeException as e: resp = e.json()