华为云 获取 弹性云服务器 信息
安装SDK
SDK 下载地址 https://github.com/huaweicloud/huaweicloud-sdk-python
cd
pip install -r requirements.txt
python3.6 setup.py install
代码
from openstack import connection
# create connection
username = "hequan"
password = "hequan"
projectId = "xxxxxxxxxxxxxxxxxxxxxxxxx" # tenant ID
userDomainId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # user account ID
auth_url = "https://iam.cn-north-1.myhuaweicloud.com" # endpoint url https://ecs.cn-north-1.myhuaweicloud.com
conn = connection.Connection(auth_url=auth_url,
user_domain_id=userDomainId,
project_id=projectId,
username=username,
password=password)
# get list of server
def list_servers():
servers = conn.compute.servers(limit=1)
for server in servers:
print(server)
if __name__ == "__main__":
list_servers()
原文地址:http://blog.51cto.com/hequan/2349473
时间: 2024-10-08 13:05:17