从托管映像创建虚拟机
Create a virtual machine from a managed image
我已经使用 ruby sdk 成功创建了 azure VM,但我找不到任何从托管映像创建的示例。我想做这样的事情但是使用 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 and here。基本上我不知道如何构造 StorageProfile
或者我可能需要更多东西。因此,我将不胜感激用于创建此类 VM 的代码示例。
谢谢。
使用基于@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 and set the storage account type,但我认为这是多余的。
我已经使用 ruby sdk 成功创建了 azure VM,但我找不到任何从托管映像创建的示例。我想做这样的事情但是使用 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 and here。基本上我不知道如何构造 StorageProfile
或者我可能需要更多东西。因此,我将不胜感激用于创建此类 VM 的代码示例。
谢谢。
使用基于@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 and set the storage account type,但我认为这是多余的。