如何从vm中的azure-cli获取当前的vm名称/ id?

时间:2019-06-06 07:42:28

标签: azure azure-devops azure-cli

如何从azure-cli中的VM(Linux)中判断当前的VM是谁? 我试图从UUID理解它,我可以从https://azure.microsoft.com/en-us/blog/accessing-and-using-azure-vm-unique-id/看到UUID,但是如何通过列表命令az vm list -d -g resource_name将其连接到VM,但是输出不包括UUID或如何获取VM CLI的名称?

1 个答案:

答案 0 :(得分:1)

您最好的选择是只使用元数据终结点:

results = solrcon.search('*:*', **{
    'rows': 100000,
    'fl': 'id, title, score' 
})

这将返回类似的json:

curl -H Metadata:true "http://169.254.169.254/metadata/instance/compute?api-version=2017-08-01"

阅读:https://docs.microsoft.com/en-us/azure/virtual-machines/windows/instance-metadata-service#example-scenarios-for-usage

如果您查询{ "compute": { "location": "CentralUS", "name": "IMDSCanary", <<< VM Name "offer": "RHEL", "osType": "Linux", "platformFaultDomain": "0", "platformUpdateDomain": "0", "publisher": "RedHat", "sku": "7.2", "version": "7.2.20161026", "vmId": "5c08b38e-4d57-4c23-ac45-aca61037f084", "vmSize": "Standard_DS2" } } 端点,您还将获得订阅ID,虚拟机ID,资源组等