Exemplo n.º 1
0
    # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
    cred = credential.Credential("secretId", "secretKey")

    # 实例化一个http选项,可选的,没有特殊需求可以跳过。
    httpProfile = HttpProfile()
    httpProfile.reqMethod = "GET"  # post请求(默认为post请求)
    httpProfile.reqTimeout = 30  # 请求超时时间,单位为秒(默认60秒)
    httpProfile.endpoint = "cvm.ap-shanghai.tencentcloudapi.com"  # 指定接入地域域名(默认就近接入)

    # 实例化一个client选项,可选的,没有特殊需求可以跳过。
    clientProfile = ClientProfile()
    clientProfile.signMethod = "HmacSHA256"  # 指定签名算法(默认为HmacSHA256)
    clientProfile.httpProfile = httpProfile

    # 实例化要请求产品(以cvm为例)的client对象,clientProfile是可选的。
    client = cvm_client.CvmClient(cred, "ap-shanghai", clientProfile)

    # 实例化一个cvm实例信息查询请求对象,每个接口都会对应一个request对象。
    req = models.DescribeInstancesRequest()

    # 填充请求参数,这里request对象的成员变量即对应接口的入参。
    # 你可以通过官网接口文档或跳转到request对象的定义处查看请求参数的定义。
    respFilter = models.Filter()  # 创建Filter对象, 以zone的维度来查询cvm实例。
    respFilter.Name = "zone"
    respFilter.Values = ["ap-shanghai-1", "ap-shanghai-2"]
    req.Filters = [respFilter]  # Filters 是成员为Filter对象的列表

    # 这里还支持以标准json格式的string来赋值请求参数的方式。下面的代码跟上面的参数赋值是等效的。
    params = '''{
        "Filters": [
            {
Exemplo n.º 2
0
from tencentcloud.common.profile import client_profile
from tencentcloud.common.profile import http_profile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
# 导入对应产品模块的client models。
from tencentcloud.cvm.v20170312 import cvm_client, models
try:
    # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
    cred = credential.Credential(
        os.environ.get("TENCENTCLOUD_SECRET_ID"),
        os.environ.get("TENCENTCLOUD_SECRET_KEY"))

    # 实例化一个client选项,可选的,没有特殊需求可以跳过。
    hp = http_profile.HttpProfile()
    hp.reqMethod = "POST"
    cp = client_profile.ClientProfile()
    cp.signMethod = "TC3-HMAC-SHA256"
    cp.httpProfile = hp
    # 实例化要请求产品(以cvm为例)的client对象
    client = cvm_client.CvmClient(cred, "ap-guangzhou", cp)

    # 实例化一个请求对象
    req = models.DescribeZonesRequest()

    # 通过client对象调用想要访问的接口,需要传入请求对象
    resp = client.DescribeZones(req)
    # 输出json格式的字符串回包
    print(resp.to_json_string())

except TencentCloudSDKException as err:
    print(err)
Exemplo n.º 3
0
def getCvmclient(region):
    credential = getCredential()
    return cvm_client.CvmClient(credential, region)
Exemplo n.º 4
0
def _get_cvm_client():
    cred = credential.Credential(TENCENTCLOUD_SECRET_ID,
                                 TENCENTCLOUD_SECRET_KEY)
    return cvm_client.CvmClient(cred, REGION)
Exemplo n.º 5
0
 def api_url(self):
     client = cvm_client.CvmClient(self.isp, None)
     return client._endpoint
Exemplo n.º 6
0
 def get_available_region_os_list(self, region_code: str) -> List:
     client = cvm_client.CvmClient(self.isp, region_code)
     req = tc_models.DescribeImagesRequest()
     req.from_json_string('{"Limit":100}')
     resp = client.DescribeImages(req)
     return resp.ImageSet
Exemplo n.º 7
0
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
import json
import time

#import json data
with open('params.json', 'r') as f:
    params = json.load(f)
id = params["secret_id"]
key = params["secret_key"]
region = params["region"]

#
cred = credential.Credential(id, key)
vpc_client = vpc_client.VpcClient(cred, region)
cvm_client = cvm_client.CvmClient(cred, region)


def show_cvm_info(cvm_id):
    try:
        #cvm_params = {"InstanceIds.N": [cvm_id]}
        filter_params = {
            "Filters": [{
                "Name": "instance-id",
                "Values": [cvm_id]
            }]
        }
        req = cvm_models.DescribeInstancesRequest()
        req.from_json_string(json.dumps(filter_params))

        resp = cvm_client.DescribeInstances(req)
Exemplo n.º 8
0
 def __init__(self):
     super(ComputeHelper, self).__init__()
     self.client = cvm_client.CvmClient(self.cred, self.region)