获取使用Azure的Python的SDK VM状态 [英] Get VM status using Azure Python SDK
问题描述
我有虚拟机列表,我想获得每个VM的状态(ReadyRole /停止/ StoppedDeallocated)使用的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.
我在bash终端使用蔚蓝CLI
命令和组合做到了这一点 grep的,尾巴
键,这样的utils的,但我想,在Python脚本使用的Azure的SDK做的。
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.
使用蔚蓝CLI
我在shell脚本运行蔚蓝的虚拟机列表
,然后的帮助下的grep
我的方式来获取虚拟机的状态。
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.
我一直在寻找到 servicemanagementservice.py
的Azure SDK的,但我无法找到像 get_role_status函数()
。 list_hosted_services()
和 get_hosted_service_properties
似乎没有提供我想要的信息,除非我失去了一些东西。
I've been looking into servicemanagementservice.py
of Azure SDK but I can't find a function like 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.
任何人都可以点我朝着一个解决方案?
Can anyone point me towards a solution?
推荐答案
基础上我的经验,我们可以得到利用一切实例状态的 Azure的REST API。
因此,对于蟒蛇的Azure SDK应该有类似的方法,因为在Azure的SDK中的函数使用相同的URL REST API。结果
我试图用这个方法 get_deployment_by_name
来获得实例的状态:
Base on my experience, we can get every instances status using 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.
I tried to use this method get_deployment_by_name
to get the instances status:
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:
这篇关于获取使用Azure的Python的SDK VM状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!