官方SDK文档:https://support.huaweicloud.com/devg-sdk/zh-cn_topic_0070637133.html

安装

  1. pip install huaweicloud-sdk-python

使用

  1. # -*- coding:utf-8 -*-
  2. from openstack import connection
  3. # create connection
  4. username = "replace-with-your-username" #用户名称
  5. password = "replace-with-your-password" #用户密码
  6. projectId = "replace-with-your-projectId" #项目ID
  7. userDomainId = "replace-with-your-domainId" #账户ID
  8. auth_url = "https://iam.example.com/v3" # endpoint url
  9. conn = connection.Connection(auth_url=auth_url,
  10. user_domain_id=userDomainId,
  11. project_id=projectId,
  12. username=username,
  13. password=password)
  14. # set parameters
  15. limit = 5
  16. # define function for listing servers
  17. def list_servers():
  18. # get server list with params
  19. servers = conn.compute.servers(limit=limit)
  20. # iterate servers list
  21. for server in servers:
  22. print(server)
  23. # visit API
  24. list_servers()