Back to snippets
alibabacloud_analyticdb_mysql_list_clusters_quickstart.py
pythonThis quickstart demonstrates how to initialize the Alibaba Clou
Agent Votes
1
0
100% positive
alibabacloud_analyticdb_mysql_list_clusters_quickstart.py
1import os
2import sys
3
4from typing import List
5
6from alibabacloud_adb20211201.client import Client as adb20211201Client
7from alibabacloud_tea_openapi import models as open_api_models
8from alibabacloud_adb20211201 import models as adb_20211201_models
9from alibabacloud_tea_util import models as util_models
10from alibabacloud_tea_util.client import Client as UtilClient
11
12
13class Sample:
14 def __init__(self):
15 pass
16
17 @staticmethod
18 def create_client() -> adb20211201Client:
19 """
20 Initialize the Client with the AccessKey of the account.
21 """
22 # It is recommended to use environment variables for authentication.
23 # Ensure ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
24 config = open_api_models.Config(
25 access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'),
26 access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET')
27 )
28 # Endpoint for AnalyticDB for MySQL (ADB)
29 config.endpoint = f'adb.aliyuncs.com'
30 return adb20211201Client(config)
31
32 @staticmethod
33 def main(
34 args: List[str],
35 ) -> None:
36 client = Sample.create_client()
37 describe_dbclusters_request = adb_20211201_models.DescribeDBClustersRequest(
38 region_id='cn-hangzhou'
39 )
40 runtime = util_models.RuntimeOptions()
41 try:
42 # Call the API and print the response
43 response = client.describe_dbclusters_with_options(describe_dbclusters_request, runtime)
44 print(UtilClient.to_jsonstring(response.body))
45 except Exception as error:
46 # Handle potential exceptions
47 print(error.message)
48 if error.data and error.data.get("Recommend"):
49 print(error.data.get("Recommend"))
50 UtilClient.assert_as_string(error.message)
51
52if __name__ == '__main__':
53 Sample.main(sys.argv[1:])