Пример #1
0
def search(secu_id, secu_key, region, cpu, memory):
    try:
        # 连接数据库获取区域代码
        region_data = ZoneCode.objects.get(zone=region).code

        cred = credential.Credential(secu_id, secu_key)
        httpProfile = HttpProfile()
        httpProfile.endpoint = "cvm.tencentcloudapi.com"

        clientProfile = ClientProfile()
        clientProfile.httpProfile = httpProfile
        client = cvm_client.CvmClient(cred, region_data, clientProfile)

        req = models.DescribeInstanceTypeConfigsRequest()
        # 过滤实例机型,S1,M1等
        params = '{}'
        req.from_json_string(params)

        # 腾讯云返回结果
        resp = client.DescribeInstanceTypeConfigs(req)

        # json转字典
        instance_type_set = json.loads(resp.to_json_string())
        # 查询出满足cpu,memory配置的机型地区zone,实例类型名称放入列表中,防止重复的无法放入
        zone = []
        ins_type = []
        for ins in instance_type_set['InstanceTypeConfigSet']:
            if ins['CPU'] == int(cpu) and ins['Memory'] == int(memory):
                zone.append(ins['Zone'])
                ins_type.append(ins['InstanceType'])
        # 返回地区和类型,一一对应
        return zone, ins_type

    except TencentCloudSDKException as err:
        raise err
Пример #2
0
def avail_sizes(call=None):
    """
    Return Tencent Cloud available instance type

    CLI Example:

    .. code-block:: bash

        salt-cloud --list-sizes my-tencentcloud-config
        salt-cloud -f avail_sizes my-tencentcloud-config
    """
    if call == "action":
        raise SaltCloudSystemExit(
            "The avail_sizes function must be called with "
            "-f or --function, or with the --list-sizes option"
        )

    client = get_provider_client("cvm_client")
    req = cvm_models.DescribeInstanceTypeConfigsRequest()
    resp = client.DescribeInstanceTypeConfigs(req)

    ret = {}
    for typeConfig in resp.InstanceTypeConfigSet:
        ret[typeConfig.InstanceType] = {
            "Zone": typeConfig.Zone,
            "InstanceFamily": typeConfig.InstanceFamily,
            "Memory": "{}GB".format(typeConfig.Memory),
            "CPU": "{}-Core".format(typeConfig.CPU),
        }
        if typeConfig.GPU:
            ret[typeConfig.InstanceType]["GPU"] = "{}-Core".format(typeConfig.GPU)

    return ret
Пример #3
0
 def get_instancesType(self,region):
     try:
         cred = self.get_cred()
         self.hp.endpoint = "cvm.tencentcloudapi.com"
         self.cp.httpProfile = self.hp
         client = cvm_client.CvmClient(cred,region,self.cp)
         req = models.DescribeInstanceTypeConfigsRequest()
         params = '{}'
         req.from_json_string(params)
         resp = client.DescribeInstanceTypeConfigs(req)
         return resp.to_json_string()
     except TencentCloudSDKException as e:
         return None
Пример #4
0
    def des_insconfig(self, zone):
        """
        查询实例所至此的类型
        :param config_dict:
        :return:
        """

        des_req = cvm_models.DescribeInstanceTypeConfigsRequest()
        des_req.Filters = [{"Name": 'zone', "Values": [zone]}]
        try:
            response = self.cvm_helper.DescribeInstanceTypeConfigs(des_req)
            result_content = json.loads(response.to_json_string())
            return result_content
        except TencentCloudSDKException as err:
            print(err)
try:
    # 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
    cred = credential.Credential("AKIDylMjqkOq7Azay9Nq8D5kCSVM1Sfft4Sd",
                                 "K8lBONAk7IEzXt30kGXcS5UfbJm0zkG4")

    httpProfile = HttpProfile()
    httpProfile.endpoint = "cvm.api3.test.403a.tcecqpoc.fsphere.cn"
    clientProfile = ClientProfile()
    clientProfile.httpProfile = httpProfile

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

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

    # 这里还支持以标准json格式的string来赋值请求参数的方式。下面的代码跟上面的参数赋值是等效的。
    params = '{"Filters.0.Name":["zone"],"Filters.0.Values.0":["ap-guangzhou-2"],"Filters.0.Name":["instance-family"],"Filters.1.Values.0":["I1"]}'
    req.from_json_string(params)

    # 通过client对象调用DescribeInstances方法发起请求。注意请求方法名与请求对象是对应的。
    # 返回的resp是一个DescribeInstancesResponse类的实例,与请求对象对应。
    resp = client.DescribeInstanceTypeConfigs(req)

    # 输出json格式的字符串回包
    print(resp.to_json_string())

    # 也可以取出单个值。
    # 你可以通过官网接口文档或跳转到response对象的定义处查看返回字段的定义。
    # print(resp.TotalCount)