我已使用 ruby sdk 成功创建了 Azure 虚拟机但我找不到任何从托管镜像创建的示例。我想做这样的事情,但是使用 SDK:
az image create --name fedora-75-20180724 --resource-group myteam --source https://eastusimg.blob.core.windows.net/images/fedora-28-20180724.vhd --os-type linux
# create vm without option "--use-unmanaged-disk, --os-type, --storage-account"
az vm create -g myteam -n managed-master --image fedora28-20180724 --size Standard_DS2_V2 --nics managed-master --os-disk-size-gb 40 --public-ip-address-dns-name managed-master --os-disk-name managed-master
但我不清楚如何做到这一点,也找不到任何示例。我查看的示例是 here和 here 。基本上我不知道如何构建 StorageProfile
或者也许我需要更多东西。因此,我希望有一个用于创建此类虚拟机的代码示例。
谢谢。
使用基于@4c74356b41的答案的工作示例(除非我忘了什么)进行更新:
ComputeModels::StorageProfile.new.tap do |store_profile|
store_profile.image_reference = ComputeModels::ImageReference.new.tap do |ref|
# obtain `image` by `compute_client.images.list_by_resource_group`
# make sure they are in the same region though or you'll see 404
ref.id = image.id
end
store_profile.os_disk = ComputeModels::OSDisk.new.tap do |os_disk|
os_disk.name = "my-unique-disk-name"
os_disk.disk_size_gb = 42 # optionally change size
os_disk.caching = ComputeModels::CachingTypes::ReadWrite # this is a test machine
os_disk.create_option = ComputeModels::DiskCreateOptionTypes::FromImage
# setting `managed_disk` is optional
os_disk.managed_disk = ComputeModels::ManagedDiskParameters.new.tap do |params|
params.storage_account_type = StorageModels::SkuName::StandardLRS
end
end
end
最佳答案
好吧,我不是 ruby 人,我也无法找到任何合理的文档,但它应该是这样的:
store_profile.os_disk = ComputeModels::OSDisk.new.tap do |os_disk|
os_disk.name = "sample-os-disk-#{vm_name}"
os_disk.caching = ComputeModels::CachingTypes::None
os_disk.create_option = ComputeModels::DiskCreateOptionTypes::FromImage
end
或者您可能需要添加 managed disk option并设置存储帐户type ,但我认为这是多余的。
关于ruby - 从托管镜像创建虚拟机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51774632/