Пример #1
0
def _test_describe_instances(http_method, sign_method, unsigned_payload=False):
    cred = credential.Credential(os.environ.get("TENCENTCLOUD_SECRET_ID"),
                                 os.environ.get("TENCENTCLOUD_SECRET_KEY"))

    httpProfile = HttpProfile()
    httpProfile.reqMethod = http_method

    clientProfile = ClientProfile()
    clientProfile.signMethod = sign_method
    clientProfile.unsignedPayload = unsigned_payload
    clientProfile.httpProfile = httpProfile

    client = cvm_client.CvmClient(cred, "ap-guangzhou", clientProfile)
    req = models.DescribeInstancesRequest()
    headers = {
        "X-TC-TraceId": "ffe0c072-8a5d-4e17-8887-a8a60252abca",
    }
    req.headers = headers

    fzone = models.Filter()
    fzone.Name = "zone"
    fzone.Values = ["ap-guangzhou-1", "ap-guangzhou-2"]
    fname = models.Filter()
    fname.Name = "instance-name"
    fname.Values = [u"中文", u"测试"]
    req.Filters = [fzone, fname]
    resp = client.DescribeInstances(req)
    assert resp.TotalCount >= 0
Пример #2
0
def describeIns(cred):
    try:
        # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
        # cred = credential.Credential(
        #     os.environ.get("TENCENTCLOUD_SECRET_ID"),
        #     os.environ.get("TENCENTCLOUD_SECRET_KEY"))
        client = new_cvm_client(cred=cred, method="GET")

        req = cvm_models.DescribeInstancesRequest()

        respFilter = cvm_models.Filter()
        respFilter.Name = "zone"
        respFilter.Values = ['ap-guangzhou-3', 'ap-guangzhou-2']

        resp = client.DescribeInstances(req)

        if os.getenv('API_JSON_INFO'):
            apiinfo("Json Response")
            print(resp.to_json_string())
        # return(resp.to_json_string())
        return (resp)

    except TencentCloudSDKException as err:
        # print(err)
        pass
Пример #3
0
def getInstanceAttribute(InstanceId):
    req = models.DescribeInstancesRequest()
    respFilter = models.Filter()
    respFilter.Name = "instance-id"
    respFilter.Values = [InstanceId]
    req.Filters = [respFilter]
    resp = client.DescribeInstances(req)
    return resp.InstanceSet[0] if resp.TotalCount > 0 else None
Пример #4
0
def getInstanceIdByPrivateIpAddress(PrivateIpAddress):
    req = models.DescribeInstancesRequest()
    respFilter = models.Filter()
    respFilter.Name = "private-ip-address"
    respFilter.Values = [PrivateIpAddress]
    req.Filters = [respFilter]
    resp = client.DescribeInstances(req)
    return resp.InstanceSet[0].InstanceId
Пример #5
0
    # 实例化一个client选项,可选的,没有特殊需求可以跳过。
    clientProfile = ClientProfile()
    clientProfile.signMethod = "TC3-HMAC-SHA256"  # 指定签名算法
    clientProfile.language = "en-US"
    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": [
            {
                "Name": "zone",
                "Values": ["ap-shanghai-1", "ap-shanghai-2"]
            }
        ]
    }'''
    req.from_json_string(params)
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
try:
    cred = credential.Credential(os.environ.get("TENCENTCLOUD_SECRET_ID"),
                                 os.environ.get("TENCENTCLOUD_SECRET_KEY"))

    httpProfile = HttpProfile()
    httpProfile.reqMethod = "GET"
    httpProfile.reqTimeout = 30
    httpProfile.endpoint = "cvm.ap-shanghai.tencentcloudapi.com"

    clientProfile = ClientProfile()
    clientProfile.signMethod = "TC3-HMAC-SHA256"
    clientProfile.language = "en-US"
    clientProfile.httpProfile = httpProfile

    client = cvm_client.CvmClient(cred, "ap-shanghai", clientProfile)

    req = models.DescribeInstancesRequest()

    respFilter = models.Filter()
    respFilter.Name = "zone"
    respFilter.Values = ["ap-shanghai-1", "ap-shanghai-2"]
    req.Filters = [respFilter]

    resp = client.DescribeInstances(req)

    print(resp.to_json_string(indent=2))
except TencentCloudSDKException as err:
    print(err)