[FOREMAN] fixes #11577 - Add additional volume to Openstack

Hello,

When creating a new virtual machine using OpenStack compute resource we
wanted to be able to add a second volume to it "/dev/vdb" in addition to
the boot volume. The second volume will only be created in case the size
value is > 0.

I already implemented and tested this feature in our Lab, and I will be
committing the code change to Github right after I create this issue.

Any feedback on this change is appreciated.

Thanks!

Andre

diff --git a/app/models/compute_resources/foreman/model/openstack.rb b/app/models/compute_resources/foreman/model/openstack.rb
index 8c4c2a1…be06670 100644
— a/app/models/compute_resources/foreman/model/openstack.rb
+++ b/app/models/compute_resources/foreman/model/openstack.rb
@@ -73,8 +73,27 @@ def boot_from_volume(args = {})
} ]
end

  • def new_volume(attr = { })
  •  volume_client.volumes.new attr.merge(:size => 0)
    
  • end
··· + + def create_additional_volume(args) + vm_name = args[:name] + add_vol = volume_client.volumes.create( { :display_name => "#{vm_name}-vol1", :volumeType => "Volume", :size => args[:volumes][:size].to_i } ) + @add_vol_id = add_vol.id.tr('"', '') + add_vol.wait_for { status == 'available' } + args[:block_device_mapping_v2] < 1, + :uuid => @add_vol_id, + :source_type => "volume", + :destination_type => "volume", + :delete_on_termination => true + } + end + def create_vm(args = {}) boot_from_volume(args) if Foreman::Cast.to_bool(args[:boot_from_volume]) + create_additional_volume(args) if args[:volumes][:size].to_i > 0 network = args.delete(:network) # fix internal network format for fog. args[:nics].delete_if(&:blank?) @@ -90,6 +109,7 @@ def create_vm(args = {}) logger.warn "failed to create vm: #{message}" destroy_vm vm.id if vm volume_client.volumes.delete(@boot_vol_id) if args[:boot_from_volume] + volume_client.volumes.delete(@add_vol_id) if args[:volumes][:size].to_i > 0 raise message end

diff --git a/app/views/compute_resources_vms/form/openstack/_volume.html.erb b/app/views/compute_resources_vms/form/openstack/_volume.html.erb
new file mode 100644
index 0000000…d15247c
— /dev/null
+++ b/app/views/compute_resources_vms/form/openstack/_volume.html.erb
@@ -0,0 +1 @@
+<%= text_f f, :size, { :label => _(“Additional volume size (GB)”), :help_inline => _(""), :value => 0 } %>
\ No newline at end of file