Create storage profile for launching Azure VM via Ruby

743 Views Asked by At

I'm trying to create/delete VMs in Azure cloud using azure-sdk-for-ruby. I'm following the example in the compute API.

There is one part that I can't understand:

# create_storage_profile is hypothetical helper method which creates storage
# profile by means of ARM Storage SDK.
params.storage_profile = create_storage_profile

How would I go about creating a profile for the new VM?

I've looked through the storage API, but I didn't find anything.

2

There are 2 best solutions below

6
Peter Pan On BEST ANSWER

There is an offical sample code for create a Azure VM using Azure SDK for Ruby, which you can find the code you want about create_storage_profile and create_network_profile via the keywords storage_profile, storage_account, network_profile and create_vm.

Hope it helps.

4
user692942 On

Admittedly the RubyDocs aren't great, but just searching on ruby storage_profile was more than helpful.

The def for create_storage_profile can be found in virtual_machines_spec.rb

def create_storage_profile
  storage_profile = StorageProfile.new
  storage_profile.image_reference = get_image_reference
  storage = create_storage_account
  os_disk = OSDisk.new
  os_disk.caching = 'None'
  os_disk.create_option = 'fromImage'
  os_disk.name = 'Test'
  virtual_hard_disk = VirtualHardDisk.new
  virtual_hard_disk.uri = generate_os_vhd_uri storage.name
  os_disk.vhd = virtual_hard_disk
  storage_profile.os_disk = os_disk
  storage_profile
end

You don't necessarily need that either as the code snippet stated, it's a hypothetical helper method. It just needs a method to return a StorageProfile instance.