[英]Get VM status using Azure Python SDK
I have a list of VMs and I'd like to get each VM's status (ReadyRole/Stopped/StoppedDeallocated) using Azure's Python SDK. 我有一个虚拟机列表,我想使用Azure的Python SDK获得每个虚拟机的状态(ReadyRole / Stopped / StoppedDeallocated)。
I have done this in a bash terminal using azure cli
commands and a combination of grep,tail
and such utils but I'd like to do that in python script using Azure's SDK. 我已经在bash终端中使用
azure cli
命令以及grep,tail
和此类utils的组合来完成此操作,但我想使用Azure的SDK在python脚本中执行此操作。
With the help of azure cli
I run in a shell script azure vm list
and then grep
my way to get the status of the VMs. 借助
azure cli
我在shell脚本azure vm list
,然后grep
我的方式获取VM的状态。
I've been looking into servicemanagementservice.py
of Azure SDK but I can't find a function like get_role_status()
. 我一直在研究Azure SDK的
servicemanagementservice.py
,但找不到类似get_role_status()
的函数。 list_hosted_services()
and get_hosted_service_properties
don't seem to provide the info I want, unless I'm missing something. list_hosted_services()
和get_hosted_service_properties
似乎没有提供我想要的信息,除非我丢失了一些东西。
Can anyone point me towards a solution? 谁能指出我的解决方案?
Base on my experience, we can get every instances status using Azure REST API. 根据我的经验,我们可以使用Azure REST API获得每个实例的状态。 So Azure SDK for python should have similar method, because the functions in Azure SDK use the same URL as REST API.
因此,适用于python的Azure SDK应该具有类似的方法,因为Azure SDK中的功能使用与REST API相同的URL。
I tried to use this method get_deployment_by_name
to get the instances status: 我试图使用此方法
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")
You can get the role list and check the every role property, please see this picture: 您可以获取角色列表并检查每个角色属性,请参见此图:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.