01: 腾讯云API-云服务器
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
01: 腾讯云API-云服务器的更多相关文章
- 腾讯云API弹性公网IP踩坑
由于自己管理的云服务器数量比较多,时不时需要更换IP,在管理台上一下下点击,实在浪费时间,于是就想到了通过API调用的方式,将更换IP一系列动作,全部集成到Python代码里面,实现一行命令,完成IP ...
- 借助腾讯云的云函数实现一个极简的API网关
借助腾讯云的云函数实现一个极简的API网关 Intro 微信小程序的域名需要备案,但是没有大陆的服务器,而且觉得备案有些繁琐,起初做的小程序都有点想要放弃了,后来了解到腾讯云的云函数,于是利用腾讯云的 ...
- 在腾讯CentOS7.4云服务器上安装Docker,在Docker上安装配置MySQL、Tomcat和Nginx
提示:以下是在腾讯CentOS7.4云服务器上操作. Docker的基本操作:https://www.cnblogs.com/opsprobe/p/10963098.html 一.安装Docker # ...
- .NET调用腾讯云API实例
最近项目有用到腾讯云的身份识别接口,话不多说,直接上代码: private void IDCardVerification(HttpContext context) { string imgStr = ...
- 腾讯云开放云压测“黑科技“,产品上线从此不再“压力山大"
商业转载请联系腾讯WeTest获得授权,非商业转载请注明出处. 能否解决"高并发"问题一直是检验一个产品后台是否稳定,架构是否合理,性能是否强大的核心标准.对于产品而言,多高的并发 ...
- 阿里云API网关(9)常见问题
网关指南: https://help.aliyun.com/document_detail/29487.html?spm=5176.doc48835.6.550.23Oqbl 网关控制台: https ...
- 阿里云API网关(7)开发指南-API参考
网关指南: https://help.aliyun.com/document_detail/29487.html?spm=5176.doc48835.6.550.23Oqbl 网关控制台: https ...
- GDC快讯,腾讯CMatrix布局云游戏B端领域
2019年3月20日-22日, GDC游戏开发者大会(Game Developers Conference,以下简称GDC)于旧金山召开.每年的GDC大会上,来自世界各地,数以万计的游戏开发者们都会分 ...
- 借助百度云API进行人脸识别
前言:本篇博客是笔者第一次使用百度云api进行人脸检测,主要内容包括两部分,一是获取接口,二是借助接口进行人脸检测.笔者也是初步了解这方面的内容,也是参考了杂七杂八的博文,内容可能存在错误及其他毛病, ...
- 利用用阿里云API实现DDNS
前言 之前动态域名解析是用的是腾达路由器上集成的第三方动态解析服务花生壳,解析费用一年40元.后来觉得域名前缀不好,想换掉,花生壳需要重新购买新的域名解析费用,增加1条或者2条动态解析无所谓,万一以后 ...
随机推荐
- C#的托管与非托管大难点
托管代码与非托管代码 众所周知,我们正常编程所用的高级语言,是无法被计算机识别的.需要先将高级语言翻译为机器语言,才能被机器理解和运行.在标准C/C++中,编译过程是这样的:源代码首先经过预处理器,对 ...
- MYSQL转换编码的解决方法
MYSQL转换编码的解决方法 一.在utf8的mysql下 得到中文‘游客’的gbk下的16进制编码 mysql> SELECT hex(CONVERT( '游客' USING gbk )); ...
- react-router@4.0 使用和源码解析
如果你已经是一个正在开发中的react应用,想要引入更好的管理路由功能.那么,react-router是你最好的选择~react-router版本现今已经到4.0.0了,而上一个稳定版本还是2.8.1 ...
- MySQL 8.0 InnoDB新特性
MySQL 8.0 InnoDB新特性 1.数据字典全部采用InnoDB引擎存储,支持DDL原子性.crash safe,metadata管理更完善 2.快速在线加新列(腾讯互娱DBA团队贡献) 3. ...
- 理解 JavaScript 中的 this
前言 理解this是我们要深入理解 JavaScript 中必不可少的一个步骤,同时只有理解了 this,你才能更加清晰地写出与自己预期一致的 JavaScript 代码. 本文是这系列的第三篇,往期 ...
- #20175201 实验一 Java开发环境的熟悉(Linux + Eclipse)
一.实验内容 1.使用JDK编译.运行简单的Java程序: 2.使用Eclipse 编辑.编译.运行.调试Java程序. (一)命令行下Java程序开发 1.过程 2.结果 调试代码遇到的问题: 解决 ...
- Android使用https与服务器交互的正确姿势
HTTPS 使用 SSL 在客户端和服务器之间进行加密通信,错误地使用 SSL ,将会导致其它人能够拦截网络上的应用数据. 使用一个包含公钥及与其匹配的私钥的证书配置服务器,作为 SSL 客户端与服务 ...
- 1、Linux的安装及基本配置
1.安装 2.登录后开启root用户 https://www.cnblogs.com/suhfj-825/p/8611436.html https://www.cnblogs.com/suhfj-82 ...
- 一HTML基础知识
网站(前段项目)的目录结构及命名 网站的结构:网站是存放在服务器上的一个文件夹(根目录),是网站所有文件的集合.网站中所有文件按照文件类型或功能分门别类的整理存放. 网站命名规则:网站中的所有文件命名 ...
- 2018-2019-2 网络对抗技术 20165321 Exp6 信息搜集与漏洞扫描
1.实践目标 掌握信息搜集的最基础技能与常用工具的使用方法. 2.实践内容 (1)各种搜索技巧的应用 百度查找IP地址: 查了一下kali的IP地址 https://fofa.so/的使用: 查询了一 ...