1.1 云服务器

  1、腾讯云SDK使用举例

      网址:https://cloud.tencent.com/document/sdk/Python

#! /usr/bin/env python
# -*- coding: utf-8 -*-
from tencentcloud.common import credential
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
# 导入对应产品模块的client models。
from tencentcloud.cvm.v20170312 import cvm_client, models secretId = "*********************************"
secretKey = "*********************************"
try:
# 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
cred = credential.Credential(secretId=secretId, secretKey=secretKey) # 实例化要请求产品(以cvm为例)的client对象
client = cvm_client.CvmClient(cred, "ap-shanghai") # 以查询可用区接口为例 # 实例化一个请求对象
req = models.DescribeZonesRequest() # 通过client对象调用想要访问的接口,需要传入请求对象
resp = client.DescribeZones(req)
# 输出json格式的字符串回包
print '##########################'
print resp.to_json_string() except TencentCloudSDKException as err:
print(err) ret = {
"TotalCount": 5,
"ZoneSet": [{
"ZoneState": "UNAVAILABLE",
"ZoneName": "上海一区",
"Zone": "ap-shanghai-1",
"ZoneId": ""
}, {
"ZoneState": "AVAILABLE",
"ZoneName": "上海二区",
"Zone": "ap-shanghai-2",
"ZoneId": ""
}, {
"ZoneState": "AVAILABLE",
"ZoneName": "上海三区",
"Zone": "ap-shanghai-3",
"ZoneId": ""
}, {
"ZoneState": "AVAILABLE",
"ZoneName": "上海四区",
"Zone": "ap-shanghai-4",
"ZoneId": ""
}, {
"ZoneState": "UNAVAILABLE",
"ZoneName": "上海五区",
"Zone": "ap-shanghai-5",
"ZoneId": ""
}],
"RequestId": "ebd821c7-ac5c-4dfd-8038-762346bd14d1"
}

腾讯云SDK使用举例

  2、地域相关接口

      网址https://cloud.tencent.com/document/api/213/15708

#! /usr/bin/env python
# -*- coding: utf-8 -*-
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.cvm.v20170312 import cvm_client, models
from day04.settings import secretKey,secretId # 导入腾讯云账户secretId,secretKey值 # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
def instantiates_auth_obj():
cred = credential.Credential(secretId=secretId, secretKey=secretKey)
return cred # 查询地域列表
def query_zero_list():
try:
cred = instantiates_auth_obj()
httpProfile = HttpProfile()
httpProfile.endpoint = "cvm.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = cvm_client.CvmClient(cred, "", clientProfile)
req = models.DescribeRegionsRequest()
params = '{}'
req.from_json_string(params)
resp = client.DescribeRegions(req)
ret = resp.to_json_string()
return ret
except TencentCloudSDKException as err:
print(err) print query_zero_list()
d = {
"TotalCount": 19,
"RegionSet": [{
"RegionState": "AVAILABLE",
"Region": "ap-bangkok",
"RegionName": "亚太地区(曼谷)"
}, {
"RegionState": "AVAILABLE",
"Region": "ap-beijing",
"RegionName": "华北地区(北京)"
},{
"RegionState": "AVAILABLE",
"Region": "na-siliconvalley",
"RegionName": "美国西部(硅谷)"
}, {
"RegionState": "AVAILABLE",
"Region": "na-toronto",
"RegionName": "北美地区(多伦多)"
}],
"RequestId": "8418f014-9ad1-4292-83f1-cf90d27f8ef8"
}

查询地域列表:如北京、曼谷

#! /usr/bin/env python
# -*- coding: utf-8 -*-
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.cvm.v20170312 import cvm_client, models
from day04.settings import secretKey,secretId # 导入腾讯云账户secretId,secretKey值 # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
def instantiates_auth_obj():
cred = credential.Credential(secretId=secretId, secretKey=secretKey)
return cred # 查询指定地域可用区列表
def zero_region_list(zones):
try:
cred = instantiates_auth_obj()
httpProfile = HttpProfile()
httpProfile.endpoint = "cvm.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = cvm_client.CvmClient(cred, zones, clientProfile)
req = models.DescribeZonesRequest()
params = '{}'
req.from_json_string(params)
resp = client.DescribeZones(req)
ret = resp.to_json_string()
return ret except TencentCloudSDKException as err:
print(err)
return {} print zero_region_list('ap-beijing')
d = {
"TotalCount": 5,
"ZoneSet": [{
"ZoneState": "AVAILABLE",
"ZoneName": "北京一区",
"Zone": "ap-beijing-1",
"ZoneId": ""
},{
"ZoneState": "UNAVAILABLE",
"ZoneName": "北京五区",
"Zone": "ap-beijing-5",
"ZoneId": ""
}],
"RequestId": "011d2390-9dfc-4ba2-a73a-038b740be408"
}

查询指定地域中有哪些地区:如北京一区、北京二区

  3、实例相关

#! /usr/bin/env python
# -*- coding: utf-8 -*-
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.cvm.v20170312 import cvm_client, models
from day04.settings import secretKey,secretId # 导入腾讯云账户secretId,secretKey值 # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
def instantiates_auth_obj():
cred = credential.Credential(secretId=secretId, secretKey=secretKey)
return cred # 查询指定地域可用区列表(查询北京地域所有主机信息 InstanceId机器唯一ID)
def zero_hosts_list(zones):
try:
cred = instantiates_auth_obj()
httpProfile = HttpProfile()
httpProfile.endpoint = "cvm.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = cvm_client.CvmClient(cred, zones, clientProfile)
req = models.DescribeInstancesRequest()
params = '{}'
req.from_json_string(params)
resp = client.DescribeInstances(req)
return resp
except TencentCloudSDKException as err:
print(err)
return {} print zero_hosts_list('ap-beijing')
d = {
"InstanceSet": [{
"RenewFlag": "NOTIFY_AND_AUTO_RENEW",
"InstanceState": "RUNNING",
"LoginSettings": {
"KeyIds": None,
"Password": None,
"KeepImageLogin": None
},
"RestrictState": "NORMAL",
"ExpiredTime": "2019-04-11T07:25:00Z",
"Memory": 1,
"CreatedTime": "2019-03-11T07:25:00Z",
"CPU": 1,
"PublicIpAddresses": ["118.89.245.148"],
"Tags": [{
"Key": "costcenter",
"Value": "devops"
}, {
"Key": "负责人",
"Value": "zihe.feng"
}],
"InstanceId": "ins-3n9jqe9x",
"ImageId": "img-qp03e2j7",
"StopChargingMode": "NOT_APPLICABLE",
"InstanceChargeType": "PREPAID",
"InstanceType": "S2.SMALL1",
"SystemDisk": {
"DiskSize": 100,
"DiskId": "disk-bxp7e5c1",
"DiskType": "CLOUD_SSD"
},
"Placement": {
"ProjectId": 0,
"HostIds": None,
"Zone": "ap-beijing-1"
},
"PrivateIpAddresses": ["172.20.0.10"],
"OsName": "CentOS 7.3 64位",
"SecurityGroupIds": ["sg-od0hrpvh"],
"InstanceName": "bj-test-common-ss-1",
"DataDisks": None,
"VirtualPrivateCloud": {
"SubnetId": "subnet-qebil5dp",
"AsVpcGateway": False,
"VpcId": "vpc-fbv2dybq",
"PrivateIpAddresses": None
},
"InternetAccessible": {
"PublicIpAssigned": None,
"InternetChargeType": "TRAFFIC_POSTPAID_BY_HOUR",
"BandwidthPackageId": None,
"InternetMaxBandwidthOut": 200
}
}, {
"RenewFlag": "NOTIFY_AND_AUTO_RENEW",
"InstanceState": "RUNNING",
"LoginSettings": {
"KeyIds": ["skey-h64mpzpz"],
"Password": None,
"KeepImageLogin": None
},
"RestrictState": "NORMAL",
"ExpiredTime": "2019-04-07T11:11:42Z",
"Memory": 56,
"CreatedTime": "2019-03-07T11:11:42Z",
"CPU": 28,
"PublicIpAddresses": ["154.8.155.101"],
"Tags": [],
"InstanceId": "ins-33hru7oj",
"ImageId": "img-qp03e2j7",
"StopChargingMode": "NOT_APPLICABLE",
"InstanceChargeType": "PREPAID",
"InstanceType": "GN2.7XLARGE56",
"SystemDisk": {
"DiskSize": 50,
"DiskId": "ldisk-czzwc94e",
"DiskType": "LOCAL_SSD"
},
"Placement": {
"ProjectId": 0,
"HostIds": None,
"Zone": "ap-beijing-2"
},
"PrivateIpAddresses": ["172.21.0.15"],
"OsName": "CentOS 7.3 64位",
"SecurityGroupIds": ["sg-od0hrpvh"],
"InstanceName": "bj-prod-research-gpu-2",
"DataDisks": [{
"DeleteWithInstance": None,
"DiskSize": 1650,
"DiskId": "ldisk-1xfm3yi6",
"DiskType": "LOCAL_SSD"
}],
"VirtualPrivateCloud": {
"SubnetId": "subnet-iyhhdfun",
"AsVpcGateway": False,
"VpcId": "vpc-pmccgax8",
"PrivateIpAddresses": None
},
"InternetAccessible": {
"PublicIpAssigned": None,
"InternetChargeType": "TRAFFIC_POSTPAID_BY_HOUR",
"BandwidthPackageId": None,
"InternetMaxBandwidthOut": 200
}
}],
"TotalCount": 11,
"RequestId": "b68ed268-d528-48e8-aa29-416b126d7489"
}

查询实例机型列表:如查询北京这个地域所有主机列表

11111111111111111111

最新文章

  1. CSS继承的特殊性
  2. maven nexus 私服的搭建学习
  3. Jquery 操作IFrame
  4. 图解JavaScript执行环境结构
  5. 1.5.2 什么是Analyzer--分析器
  6. 【暑假】[实用数据结构]UVAlive 3027 Corporative Network
  7. 12天学好C语言——记录我的C语言学习之路(Day 8)
  8. Visual Studio 2010 安装帮助文档问题
  9. C#基础——集合及特殊集合
  10. SQL Server -- 回忆笔记(五):T-SQL编程,系统变量,事务,游标,触发器
  11. SpringBoot系列: 使用MyBatis maven插件自动生成java代码
  12. VS中ipch文件夹和sdf文件的处理方式
  13. new 几种用法
  14. File /hbase could only be replicated to 0 nodes instead of minReplication (=1). There are 30 datanode(s) running and no node(s) are excluded in this operation.
  15. SpringCloud请求响应数据转换(一)
  16. 四种传值方法(通知、block、属性、NSUserDefaults)
  17. Resharper 安装以及破解
  18. WebLogic Server StuckThreadMaxTime value is exceeded during configuration
  19. Notepad++ v5.5以上 惯用法教程
  20. HDOJ 1238 Substrings 【最长公共子串】

热门文章

  1. 安装Office2010出现MSXML版本6.10.1129.0错误
  2. memcached加固
  3. cesium 飞线 瓣体传感器(雷达扫描) 效果
  4. DDoS攻击及防御措施
  5. spring 相关注解详情(一)
  6. ajax的get和post请求 -- 基于flask 简单示例
  7. 【托业】【全真题库】TEST3-语法题
  8. spring-boot war包
  9. 浏览器User-Agent大全
  10. JS全选反选功能