简体   繁体   English

使用Azure Python SDK获取VM状态

[英]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.

相关问题 如何使用Azure Python SDK获取Azure VM正常运行时间/运行时(运行状态的时间) - How to get Azure VM uptime/runtime (time in running status) with Azure Python SDK 通过Azure Python SDK获取Azure VM硬件配置文件 - get Azure VM hardware profile via Azure Python SDK 创建VM之前如何获取Azure SDK Python的公共地址 - How to get an public address for Azure SDK Python, before VM creation 使用 Python SDK 从字符串推断 Azure VM 属性 - Inferring Azure VM properties from string using Python SDK 如何使用azure-sdk-for-python创建具有自定义映像的VM? - How to create a VM with a custom image using azure-sdk-for-python? 使用 Python SDK 的 Azure 经典 VM 实例未出现 - Classic VM instances from Azure using Python SDK are not appearing 如何使用 Azure 中的 Python SDK 将 LogAnalyticsWorkSpace 扩展添加到 VM - how to add LogAnalyticsWorkSpace extension to VM using Python SDK in Azure 如何使用 python SDK 创建带有 VM 扩展的 Azure 虚拟机 - How to create Azure Virtual machine with VM Extension using the python SDK 有没有办法找出给定 VM 的资源组,然后使用 Python sdk 在 Azure 中找出 VM 的详细信息 - Is there a way to find out Resource group for a given VM and then find out details of VM in Azure using Python sdk 如何在VM实例上授权Azure Python SDK? - How to authorize Azure Python SDK on VM instance?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM