Esempio n. 1
0
def desc_instance_types():
    """
    查询云服务器 ECS 提供的实例规格资源
    :return:
    """
    request = DescribeInstanceTypesRequest.DescribeInstanceTypesRequest()
    return request
Esempio n. 2
0
 def getAllTypes(self):
     request = DescribeInstanceTypesRequest.DescribeInstanceTypesRequest()
     try:
         result = self.clt.do_action_with_exception(request)
         result = json.loads(result)
         data = result['InstanceTypes']['InstanceType']
         return True, data
     except Exception, ex:
         return False, str(ex)
Esempio n. 3
0
    def get_instance_type(self):
        """
        获取阿里云类型列表
        """
        from aliyunsdkecs.request.v20140526 import DescribeInstanceTypesRequest

        request = DescribeInstanceTypesRequest.DescribeInstanceTypesRequest()
        connect = self.aliyun_connect(request)
        tmp = eval(connect)

        return tmp['InstanceTypes']['InstanceType']
Esempio n. 4
0
 def describeinstancetypes(self, instancetypefamily=None):
     '''查询 ECS 所提供的实例资源规格CPU/Mem'''
     request = DescribeInstanceTypesRequest.DescribeInstanceTypesRequest()
     values = {"Action": "DescribeInstanceTypes"}
     if instancetypefamily:
         values = {
             "Action": "DescribeInstanceTypes",
             "InstanceTypeFamily": instancetypefamily
         }
     info = self.request_api(request,
                             values)['InstanceTypes']['InstanceType']
     ecs_types = []
     for ecs_type in info:
         ecs_types.append({
             ecs_type['InstanceTypeId']:
             [ecs_type['CpuCoreCount'], ecs_type['MemorySize']]
         })
     return ecs_types
Esempio n. 5
0
    def get_available_plans_list(self):
        # TODO:query price when aliyun enable price query support
        request = DescribeInstanceTypesRequest.DescribeInstanceTypesRequest()
        response = self.handle_request(request)

        plan_list = [
            vps_schema.VpsSpecPlanSchema(
                plan_code=plan["InstanceTypeId"],
                name=
                f"{plan['InstanceTypeFamily']}-{plan['MemorySize']}GB RAM-{plan['CpuCoreCount']} 核CPU",
                vcpu=plan["CpuCoreCount"],
                ram=plan["MemorySize"],
                disk=0,
                bandwidth=0,
                price_monthly=0,
                region_codes=[],
            ).dict()
            for plan in response["InstanceTypes"].get("InstanceType", [])
        ]
        return plan_list
Esempio n. 6
0
    def query(self):
        query_result = {}

        instance_type_resquest = DescribeInstanceTypesRequest.DescribeInstanceTypesRequest()
        instance_type_resquest.set_accept_format('json')
        result = json.loads(self.__clt.do_action(instance_type_resquest))
        query_result['InstanceTypes'] = result['InstanceTypes']

        region_request = DescribeRegionsRequest.DescribeRegionsRequest()
        region_request.set_accept_format('json')
        result = json.loads(self.__clt.do_action(region_request))
        query_result['Regions'] = result['Regions']

        # zone_request = DescribeZonesRequest.DescribeZonesRequest()
        # zone_request.set_accept_format('json')
        # self.__clt.do_action(zone_request)

        return query_result
    # def startInstance(self):
    #     request = StartInstanceRequest.StartInstanceRequest()
    #     return self.__clt.do_action(request)
    #
    # def stopInstance(self):
    #     request = StopInstanceRequest.StopInstanceRequest()
    #     return self.__clt.do_action(request)
    #
    # def rebootInstance(self):
    #     request = RebootInstanceRequest.RebootInstanceRequest()
    #     return self.__clt.do_action(request)
    #
    # def describeInstanceStatus(self):
    #     request = DescribeInstanceStatusRequest.DescribeInstanceStatusRequest()
    #     return self.__clt.do_action(request)
    #
    # def describeInstances(self):
    #     request = DescribeInstancesRequest.DescribeInstancesRequest()
    #     return self.__clt.do_action(request)
    #
    # def deleteInstance(self):
    #     request = DeleteInstanceRequest.DeleteInstanceRequest()
    #     return self.__clt.do_action(request)
Esempio n. 7
0
# zone
req = DescribeZonesRequest.DescribeZonesRequest()
body = client.do_action_with_exception(req)
pp.pprint(json.loads(body.decode("utf-8")))

# SecurityGroup
req = DescribeSecurityGroupsRequest.DescribeSecurityGroupsRequest()
req.set_query_params({'PageSize': 50})
body = client.do_action_with_exception(req)
pp.pprint(json.loads(body.decode("utf-8")))

# SecurityGroup id
req = DescribeSecurityGroupAttributeRequest.DescribeSecurityGroupAttributeRequest(
)
req.set_SecurityGroupId("")
body = client.do_action_with_exception(req)
pp.pprint(json.loads(body.decode("utf-8")))

# InstanceType
req = DescribeInstanceTypesRequest.DescribeInstanceTypesRequest()
req.set_query_params({'PageSize': 50})
body = client.do_action_with_exception(req)
pp.pprint(json.loads(body.decode("utf-8")))

# ImageId
req = DescribeImagesRequest.DescribeImagesRequest()
req.set_query_params({'PageSize': 10})
req.set_query_params({'ImageId': ""})
body = client.do_action_with_exception(req)
pp.pprint(json.loads(body.decode("utf-8")))
Esempio n. 8
0
 def get_ecs_type(self, family_id):
     request = DescribeInstanceTypesRequest.DescribeInstanceTypesRequest()
     request.set_InstanceTypeFamily(family_id)
     response = self.client.do_action_with_exception(request)
     return json.loads(
         response.decode('utf-8'))['InstanceTypes']['InstanceType']
Esempio n. 9
0
 def get_server_type_list(self):
     client = AcsClient(access_key_id, access_key_secret,region_id)
     request = DescribeInstanceTypesRequest.DescribeInstanceTypesRequest()
     response = client.do_action_with_exception(request)
     json_result = json.loads(response)
     return json_result