OpenStack - Boot Instance from Volume


#1

Hi all,

Just want to share some of my experiences using Nova’s block_device_mapping_v2 option for enabling an instance to boot from a volume, and creating a bootable volume. There’s some documentation on block device mapping in Nova here: http://docs.openstack.org/developer/nova/block_device_mapping.html. I’ve tested these methods using the RDO Liberty OpenStack release.

I’ve implemented all of the examples below in my openstack_PreProvision method, over-ridden from the “ManageIQ / Cloud / VM / Provisioning / StateMachines / Methods” namespace.

To enable a VM to boot from an existing, bootable volume, you can use the following. The ‘uuid’ is the OpenStack reference to the bootable volume.

prov = $evm.root['miq_provision']
prov.set_option(
  :clone_options, {
    :image_ref => "",
    :block_device_mapping_v2 => [{
      :boot_index => 0,
      :uuid => "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
      :device_name => "vda",
      :source_type => "volume",
      :destination_type => "volume",
      :volume_size => 0,
      :delete_on_termination => false
    }]
  }
)  

I’ve seen some examples setting “image_ref” to “nil”; I found with the Liberty release that Nova raised an error for this. The work-around is to set the image_ref to an empty string and the volume_size to any integer (Nova ignores this, though complains if it isn’t in the request).

You can also create a bootable volume and enable an instance to boot from it using block_device_mapping_v2. Here, the ‘uuid’ is the OpenStack reference to the image template.

prov = $evm.root['miq_provision']
prov.set_option(
  :clone_options, {
    :image_ref => "",
    :block_device_mapping_v2 => [{
      :boot_index => 0,
      :uuid => "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
      :device_name => "vda",
      :source_type => "image",
      :destination_type => "volume",
      :volume_size => 1,
      :delete_on_termination => false
    }]
  }
) 

Again, Nova complains if the “image_ref” parameter is set to “nil”, so I pass an empty string. The volume_size is changed to the required volume size (in GB), and the source_type is changed to “image”.

Hope this helps someone else out.


#2

Thanks @jockey10 for sharing and adding to the ManageIQ knowledge-base. :smile: