示例#1
0
def DescribeRegions():
    clt = client.AcsClient(accesskey['accesskeyid'],
                           accesskey['accesskeysecret'])
    request = DescribeRegionsRequest.DescribeRegionsRequest()
    request.set_accept_format('json')
    response = clt.do_action_with_exception(request)
    response = json.loads(response)
    return response['Regions']['Region']
示例#2
0
 def getAllRegions(self):
     request = DescribeRegionsRequest.DescribeRegionsRequest()
     try:
         result = self.clt.do_action_with_exception(request)
         result = json.loads(result)
         return True, result['Regions']['Region']
     except Exception, ex:
         return False, str(ex)
示例#3
0
 def get_regions(self):
     """
     可用区查询:
     """
     request = DescribeRegionsRequest.DescribeRegionsRequest()
     request.set_accept_format("json")
     result = json.loads(self.clt.do_action(request))
     print(result)
     return result
示例#4
0
 def get_regions(self):
     clt = client.AcsClient(self.AccessKeyId, self.AccessKeySecret,
                            'cn-hangzhou')
     request = DescribeRegionsRequest.DescribeRegionsRequest()
     request.set_accept_format('json')
     json_response = json.loads(clt.do_action_with_exception(request))
     for regions in json_response['Regions']['Region']:
         self.regions_list.append(regions['RegionId'])
     return self.regions_list
示例#5
0
def getRegion():
    clt = client.AcsClient(config.ALIYUN_ID, config.ALIYUN_SECRET)
    request = DescribeRegionsRequest.DescribeRegionsRequest()
    request.set_accept_format('json')
    response = clt.do_action(request)
    result = json.loads(response)
    regionList = []
    for region in result['Regions']['Region']:
        regionList.append(region['RegionId'])

    return regionList
示例#6
0
def ecs_region_list_request():
    """ECS封装API-获取地域列表
    - Data['Regions']
        -
        - Data['Regions']['Region'][0]['LocalName']
    - Data['RequestId']
    """
    # 创建 request,并设置参数
    request = DescribeRegionsRequest.DescribeRegionsRequest()
    # 发起 API 请求并返回数据
    return _do_action(_get_config(), request)
示例#7
0
def getRegion():
    clt = client.AcsClient('LTAImtKD9oSsQJyQ',
                           'xazFiaIri1fHXDoPFV2yPtZIsnQXRy')
    request = DescribeRegionsRequest.DescribeRegionsRequest()
    request.set_accept_format('json')
    response = clt.do_action(request)
    result = json.loads(response)
    regionList = []
    for region in result['Regions']['Region']:
        regionList.append(region['RegionId'])

    return regionList
示例#8
0
    def get_region_ids(self):
        self.connect()

        request = DescribeRegionsRequest.DescribeRegionsRequest()
        request.set_accept_format("json")
        try:
            response_string = self.clt.do_action_with_exception(request)
        except Exception as e:
            return e.args, False
        else:
            response_obj = json.loads(response_string)
            return response_obj['Regions']['Region'], True
示例#9
0
    def _list_regions(self) -> []:
        req = DescribeRegionsRequest.DescribeRegionsRequest()
        response = parse_response(
            self.acs_client.do_action_with_exception(req))
        region_ids = []

        for region in response.get("Regions").get("Region"):
            region_id = region.get("RegionId")
            if region_id != self.region:
                region_ids.append(region_id)

        return region_ids
示例#10
0
    def __getRegionList(self):
        request = DescribeRegionsRequest.DescribeRegionsRequest()

        request.set_accept_format(u'json')
        try:
            result = self.__client.do_action(request)
            result_data = json.loads(result)
        except Exception as e:
            print "exception arised "
            print e
            return 1

        return 0
示例#11
0
    def do_avail_regions(self):
        client = AcsClient(self.aliyun_token['id'], self.aliyun_token['secret'])
        describeRegionRequest = DescribeRegionsRequest.DescribeRegionsRequest()
        describeRegionRequest.set_accept_format('json')

        resp = json_decode(client.do_action(describeRegionRequest))
        result = {}
        result['text'] = 'avail regions'
        result['attachments'] = []
        for i in resp['Regions']['Region']:
            result['attachments'].append({"title": "%s" % i['LocalName'], "text": "%s" % i['RegionId']})

        return result
示例#12
0
文件: ecs.py 项目: jokimina/aliyunpy
 def get_regions(self, id_only=False):
     """
     获取支持的region列表
     https://help.aliyun.com/document_detail/25609.html
     :param id_only: 是否只返回region id列表
     :return:
     """
     request = DescribeRegionsRequest.DescribeRegionsRequest()
     result = self.client.do_action(request)
     result_list = result.get('Regions', {}).get('Region', [])
     if id_only:
         # pylint: disable=R1718
         result_list = list(set([x.get('RegionId') for x in result_list]))
     return result_list
示例#13
0
def list_regions():

    cache_key = 'list_regions'
    r = cache.get(cache_key)
    if r is None:
        client = create_acs_client()

        request = DescribeRegionsRequest.DescribeRegionsRequest()
        request.set_action_name('DescribeRegions')
        response = client.do_action_with_exception(request)
        r = json.loads(response.decode())
        log.debug(r)
        cache.set(cache_key, r)
    return r
示例#14
0
    def get_available_regions_list(self):
        request = DescribeRegionsRequest.DescribeRegionsRequest()
        response = self.handle_request(request)
        region_list = response["Regions"].get("Region", [])

        region_dict_list = [
            vps_schema.VpsSpecRegionSchema(
                name=region_data["LocalName"],
                region_code=region_data["RegionId"],
                plan_codes=self.get_available_region_plan_list(
                    region_data["RegionId"]),
                features=None,
            ).dict() for region_data in region_list
            if self.get_available_region_plan_list(region_data["RegionId"])
        ]

        return region_dict_list
示例#15
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)
示例#16
0
#coding:utf-8

import json
from config import access_id, access_key_secret

from aliyunsdkcore import client
from aliyunsdkecs.request.v20140526 import DescribeRegionsRequest,CreateInstanceRequest,DescribeImagesRequest, \
AllocatePublicIpAddressRequest,StartInstanceRequest,ModifyInstanceNetworkSpecRequest,DeleteInstanceRequest,StopInstanceRequest, \
AllocateEipAddressRequest,AssociateEipAddressRequest,CreateVpcRequest,CreateVSwitchRequest

clt = client.AcsClient(access_id, access_key_secret, 'cn-hongkong')

print "##########DescribeRegions###########"
request = DescribeRegionsRequest.DescribeRegionsRequest()
request.set_accept_format('json')

result = clt.do_action(request)
'''
status, headers, body = clt.get_response(request)
print status
result = json.loads(body)
for key,value in result.items():
    print key,value 
'''

print result
#print json.loads(result)['RequestId']
for i in json.loads(result)['Regions']['Region']:
    print i['LocalName'], i['RegionId']

print "#########DescribeImages############"
def get_regions(client):
    request = DescribeRegionsRequest.DescribeRegionsRequest()
    result = do_action(client, request)
    return result['Regions']['Region']
示例#18
0
 def getRegions(self):
     req = DescribeRegionsRequest.DescribeRegionsRequest()
     req.set_accept_format('json')
     res = self.client.do_action(req)
     return json.loads(res)