使用 python 在 Azure 上使用自定义映像创建 VM [英] Create VM on Azure with custom image using python

查看:30
本文介绍了使用 python 在 Azure 上使用自定义映像创建 VM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Azure 中使用市场映像启动 VM 非常简单.

Launching a VM using a marketplace image in Azure is pretty straight forward.

这是相关的一段代码.

def create_vm(network_client, compute_client):

def create_vm(network_client, compute_client):

vm_parameters = {
    'storage_profile': {
        'image_reference': {
            'publisher': 'MicrosoftWindowsServer',
            'offer': 'WindowsServer',
            'sku': '2012-R2-Datacenter',
            'version': 'latest'
        }
    },

vm = compute_client.virtual_machines.create_or_update(
    GROUP_NAME, 
    VM_NAME, 
    vm_parameters
)

(显然实际代码中还有更多,这是我认为最相关的部分)

(Clearly there is more in the actual code, this is the part that I think is most relevant)

所以在这种情况下,图像参考指向市场.

So in this case the image reference points to the marketplace.

我使用以下文档来创建自定义图像.

I used the following doc to create a custom image.

https://docs.microsoft.com/en-us/azure/virtual-machines/windows/create-vm-generalized-managed?toc=%2fazure%2fvirtual-machines%2fwindows%2ftoc.json

我想根据我创建的新自定义映像创建一个 VM.我认为 image_reference 应该指向其他东西,但我不清楚它应该是什么.有人可以帮忙吗?

I would like to create a VM based on the new custom image that I created. It is my perception that image_reference should point to something else but it isn't clear to me what it should be. Can anybody help here?

谢谢!

推荐答案

事实上,Azure Python SDK 使用 Azure Rest API.您可以查看此 示例.

In fact, Azure Python SDK uses Azure Rest API. You could check this example.

所以,你可以像下面这样修改你的脚本:

So, you could modify your script like below:

vm_parameters = {
    'storage_profile': {
        'image_reference': {
            'id' : '/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/{existing-custom-image-name}'
        }
    },

这篇关于使用 python 在 Azure 上使用自定义映像创建 VM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆