官方SDK文档:https://support.huaweicloud.com/devg-sdk/zh-cn_topic_0070637133.html
安装
pip install huaweicloud-sdk-python
使用
# -*- coding:utf-8 -*-
from openstack import connection
# create connection
username = "replace-with-your-username" #用户名称
password = "replace-with-your-password" #用户密码
projectId = "replace-with-your-projectId" #项目ID
userDomainId = "replace-with-your-domainId" #账户ID
auth_url = "https://iam.example.com/v3" # endpoint url
conn = connection.Connection(auth_url=auth_url,
user_domain_id=userDomainId,
project_id=projectId,
username=username,
password=password)
# set parameters
limit = 5
# define function for listing servers
def list_servers():
# get server list with params
servers = conn.compute.servers(limit=limit)
# iterate servers list
for server in servers:
print(server)
# visit API
list_servers()