Python SDK
This topic describes how to install the Cloud Managed Network Python software development kit (SDK) and use it to perform common operations.
Prerequisites
You have activated Cloud Managed Network. For more information, see Activate Cloud Managed Network.
You have created and obtained an AccessKey pair. For more information, see AccessKey pair.
You have installed a Python development environment.
The Cloud Managed Network Python SDK supports Python 3.6 or later. You can run the
python --versioncommand to check your Python version. If Python is not installed, download the installation package from the official Python website and install it.
Install the SDK
You can use pip to install the Cloud Managed Network Python SDK. If pip is not installed, see Install pip.
pip install alibabacloud_cmn20200825Use the SDK
The following code shows the three main steps for calling the Cloud Managed Network Python SDK. This example retrieves a paginated list of all network devices in Resource Management.
Create a Client instance.
Create an API request and set its parameters.
Initiate the request and handle the response.
from alibabacloud_cmn20200825.client import Client
from alibabacloud_tea_openapi.models import Config
from alibabacloud_cmn20200825.models import ListDevicesRequest
from alibabacloud_credentials.client import Client as CredClient
'''
An Alibaba Cloud account AccessKey has full access permissions to all APIs. For better security, use a Resource Access Management (RAM) user for API calls or daily O&M.
Do not hard-code your AccessKey ID and AccessKey secret in your project code. Hard-coding your AccessKey pair may cause the pair to be leaked and threaten the security of all resources in your account.
This example uses the Alibaba Cloud Credentials tool to manage the AccessKey pair for identity verification. For more information about how to configure the tool or set environment variables, see https://help.aliyun.com/document_detail/378659.html.
'''
cred = CredClient()
accesskeyid = cred.get_access_key_id()
accesskeysecret = cred.get_access_key_secret()
config = Config(
access_key_id = accesskeyid,
access_key_secret = accesskeysecret,
endpoint = "cmn.cn-hangzhou.aliyuncs.com",
region_id = "cn-hangzhou",
type='access_key'
)
request = ListDevicesRequest(
device_form_name="Network Device",
max_results=10
)
client = Client(config)
response = client.list_devices(request)
print(response)