【Python】阿里雲python sdk快速入門

小亮520cl發表於2018-08-10

1 示列程式碼如下

# -*- coding: utf8 -*-
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkecs.request.v20140526 import DescribeInstancesRequest
from aliyunsdkecs.request.v20140526 import StopInstanceRequest
from aliyunsdkrds.request.v20140815 import DescribeDBInstancesRequest
# 建立 AcsClient 例項
client = AcsClient(
"XXXXXXXXXX", 
"XXXXXXXXXXXXX",
"XXXXXXXXX"
);
# 建立 request,並設定引數
request = DescribeDBInstancesRequest.DescribeDBInstancesRequest()
request.set_PageSize(10)
# 發起 API 請求並列印返回
response = client.do_action_with_exception(request)
print response


返回結果

{
    "Items": {
        "DBInstance": [
            {
                "LockMode": "Unlock", 
                "DBInstanceNetType": "Intranet", 
                "DBInstanceClass": "mysql.n2.medium.1", 
                "ResourceGroupId": "rg-acfnsgk4qv2czbi", 
                "DBInstanceId": "rm-6gjs5qm4oo40cvnij", 
                "VpcCloudInstanceId": "xxxxxx", 
                "ZoneId": "ap-south-1a", 
                "ReadOnlyDBInstanceIds": {
                    "ReadOnlyDBInstanceId": [ ]
                }, 
                "InstanceNetworkType": "VPC", 
                "DBInstanceDescription": "xxxxxxxxxx", 
                "ConnectionMode": "Standard", 
                "VSwitchId": "xxxxxxxxx", 
                "VpcId": "xxxxxxxx", 
                "Engine": "MySQL", 
                "MutriORsignle": false, 
                "InsId": 1, 
                "ExpireTime": "", 
                "CreateTime": "2018-08-06T15:35Z", 
                "DBInstanceType": "Primary", 
                "RegionId": "ap-south-1", 
                "EngineVersion": "5.7", 
                "LockReason": "", 
                "DBInstanceStatus": "Running", 
                "PayType": "Postpaid"
            }, 
            {
                "LockMode": "Unlock", 
                "DBInstanceNetType": "Intranet", 
                "DBInstanceClass": "rds.mysql.s2.large", 
                "ResourceGroupId": "rg-acfnsgk4qv2czbi", 
                "DBInstanceId": "rm-6gjie25ei5u6sd588", 
                "VpcCloudInstanceId": "rm-6gjie25ei5u6sd588", 
                "ZoneId": "ap-south-1a", 
                "ReadOnlyDBInstanceIds": {
                    "ReadOnlyDBInstanceId": [ ]
                }, 
                "InstanceNetworkType": "VPC", 
                "DBInstanceDescription": "xxxxxxxxx", 
                "ConnectionMode": "Safe", 
                "VSwitchId": "vsw-a2d94448xglixxx85czqq208lne", 
                "VpcId": "vpc-a2dqe44k2xxk0ci69aewq27vx", 
                "Engine": "MySQL", 
                "MutriORsignle": false, 
                "InsId": 1, 
                "ExpireTime": "2018-08-24T16:00:00Z", 
                "CreateTime": "2018-07-24T21:40Z", 
                "DBInstanceType": "Primary", 
                "RegionId": "ap-south-1", 
                "EngineVersion": "5.6", 
                "LockReason": "", 
                "DBInstanceStatus": "Running", 
                "PayType": "Prepaid"
            }
        ]
    }, 
    "TotalRecordCount": 2, 
    "PageNumber": 1, 
    "RequestId": "DF7ECC24-F87E-4834-83A4-885DA62825E1", 
    "PageRecordCount": 2
}



具體怎麼使用參考如下:

 (sdk使用)

  (rds的api介面)


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-2199788/,如需轉載,請註明出處,否則將追究法律責任。

相關文章