码迷,mamicode.com
首页 > 编程语言 > 详细

华为云 获取 弹性云服务器 信息 python版本

时间:2019-02-12 18:52:05      阅读:426      评论:0      收藏:0      [点我收藏+]

标签:setup.py   python3   xxxxx   pip   huawei   username   git   limit   rem   

华为云 获取 弹性云服务器 信息

安装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()

华为云 获取 弹性云服务器 信息 python版本

标签:setup.py   python3   xxxxx   pip   huawei   username   git   limit   rem   

原文地址:http://blog.51cto.com/hequan/2349473

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!