Beispiel #1
0
 def request_get_page_number(self):
     request = DescribeDBInstancesRequest.DescribeDBInstancesRequest()
     request.add_query_param('PageNumber', 1)
     request.add_query_param('PageSize', 30)
     try:
         response = self.clt.do_action_with_exception(request)
     except:
         return {}
     result = self.get_json_results(response)
     return int(result.get('TotalCount') / settings.ALIYUN_PAGESIZE) + 1
Beispiel #2
0
 def request_get_instance(self, instance_id):
     request = DescribeDBInstancesRequest.DescribeDBInstancesRequest()
     self.request_to_json(request)
     request.add_query_param('RegionId', 'cn-hangzhou')
     request.add_query_param('DBInstanceIds', instance_id)
     try:
         response = self.clt.do_action_with_exception(request)
     except:
         return {}
     return self.get_json_results(response).get('DBInstances').get(
         'DBInstance')[0]
Beispiel #3
0
 def request_get_instances(self, page):
     request = DescribeDBInstancesRequest.DescribeDBInstancesRequest()
     self.request_to_json(request)
     request.add_query_param('RegionId', 'cn-hangzhou')
     request.add_query_param('PageNumber', page)
     request.add_query_param('PageSize', settings.ALIYUN_PAGESIZE)
     try:
         response = self.clt.do_action_with_exception(request)
     except:
         return {}
     return self.get_json_results(response).get('DBInstances').get(
         'DBInstance')
    def getAliMongoInstanceid(self):
        # 设置初始页码
        pageNumber = 1

        request = DescribeDBInstancesRequest.DescribeDBInstancesRequest()
        request.set_accept_format('json')
        request.set_PageSize(30)
        request.set_PageNumber(pageNumber)

        # 发起API请求并显示返回值
        response = self.client.do_action_with_exception(request)
        response_dict = json.loads(response)

        # 生成生成器
        while response_dict.get('DBInstances').get('DBInstance'):
            yield response_dict.get('DBInstances').get('DBInstance')
            pageNumber += 1
            request.set_PageNumber(pageNumber)
            response = self.client.do_action_with_exception(request)
            response_dict = json.loads(response)
 def mongodb_info(self) -> GaugeMetricFamily:
     req = Mongodb.DescribeDBInstancesRequest()
     return self.info_template(
         req,
         'aliyun_meta_mongodb_info',
         to_list=lambda data: data['DBInstances']['DBInstance'])
Beispiel #6
0
            dts_list = response['SynchronizationInstances']
            save_dts(dts_list)


if __name__ == '__main__':
    conn = pymysql.connect(user=dbUser,
                           passwd=dbPass,
                           host=dbHost,
                           db=dbName,
                           use_unicode=True,
                           charset="utf8")
    cur = conn.cursor()

    regions = [
        "cn-qingdao", "cn-hangzhou", "cn-beijing", "cn-shanghai",
        "cn-shenzhen", "cn-zhangjiakou"
    ]
    for region in regions:
        # 获得cn-qingdao MongoDB列表
        clt = client.AcsClient(accessKey, accessSecret, region)
        clt_dts = client.AcsClient(accessKey, accessSecret)
        request_mongodb = DescribeInstancesRequest.DescribeInstancesRequest()
        request_redis = DescribeDBInstancesRequest.DescribeDBInstancesRequest()
        request_dts = DescribeSynchronizationJobsRequest.DescribeSynchronizationJobsRequest(
        )
        mongoDB(request_redis)
        redis(request_mongodb)
        dts(request_dts)

    cur.close()
    conn.close()