使用Azure Python SDK获取VM状态

时间:2015-07-14 09:28:58

标签: python azure

我有一个虚拟机列表,我希望使用Azure的Python SDK获取每个虚拟机的状态(ReadyRole / Stopped / StoppedDeallocated)。

我在bash终端中使用azure cli命令以及grep,tail和这样的utils的组合完成了这个,但我想在使用Azure SDK的python脚本中这样做

azure cli的帮助下,我在shell脚本azure vm list中运行,然后以grep的方式运行以获取VM的状态。

我一直在研究Azure SDK的servicemanagementservice.py,但我找不到像get_role_status()这样的功能。除非我遗漏了某些内容,否则list_hosted_services()get_hosted_service_properties似乎无法提供我想要的信息。

有人能指出我的解决方案吗?

1 个答案:

答案 0 :(得分:2)

根据我的经验,我们可以使用Azure REST API.获取每个实例的状态 所以Azure SDK for python应该有类似的方法,因为Azure SDK中的函数使用与REST API相同的URL 我尝试使用此方法get_deployment_by_name来获取实例状态:

subscription_id = '****-***-***-**'
certificate_path = 'CURRENT_USER\\my\\***'
sms = ServiceManagementService(subscription_id, certificate_path)
result=sms.get_deployment_by_name("your service name","your deployment name")

您可以获取角色列表并查看每个角色属性,请看这张图片: enter image description here

相关问题