diff --git a/app/models/foreman_xen/xenserver.rb b/app/models/foreman_xen/xenserver.rb index d877976..1eb1543 100644 --- a/app/models/foreman_xen/xenserver.rb +++ b/app/models/foreman_xen/xenserver.rb @@ -62,8 +62,37 @@ def new_volume(attr={}) end def storage_pools - storages = client.storage_repositories.select { |sr| sr.type!= 'udev' && sr.type!= 'iso'} rescue [] - storages.sort { |a, b| a.name <=> b.name } + results = Array.new + + storages = client.storage_repositories.select { |sr| sr.type!= 'udev' && sr.type!= 'iso'} rescue [] + hosts = client.hosts + + storages.each do |sr| + subresults = Hash.new() + found = 0 + hosts.each do |host| + + if (sr.reference == host.suspend_image_sr) + found = 1 + subresults[:name] = sr.name + subresults[:display_name] = sr.name + '(' + host.hostname + ')' + subresults[:uuid] = sr.uuid + break + end + + end + + if (found==0) + subresults[:name] = sr.name + subresults[:display_name] = sr.name + subresults[:uuid] = sr.uuid + end + results.push(subresults) + end + + results.sort_by!{|item| item[:display_name] } + return results + end def interfaces @@ -198,7 +227,7 @@ def create_vm_from_custom(args) def create_vm_from_builtin(args) host = client.hosts.first - storage_repository = client.storage_repositories.find { |sr| sr.name == "#{args[:VBDs][:print]}" } + storage_repository = client.storage_repositories.find { |sr| sr.uuid == "#{args[:VBDs][:sr_uuid]}" } gb = 1073741824 #1gb in bytes size = args[:VBDs][:physical_size].to_i * gb diff --git a/app/views/compute_resources_vms/form/_templates.html.erb b/app/views/compute_resources_vms/form/_templates.html.erb index a9375ca..78f6770 100644 --- a/app/views/compute_resources_vms/form/_templates.html.erb +++ b/app/views/compute_resources_vms/form/_templates.html.erb @@ -9,11 +9,11 @@ %>
-
+
<%= selectable_f f, :custom_template_name,[[_("No template"), ""]] + compute_resource.custom_templates.map { |t| [t.name, t.name] }, {}, :class => 'form-control span2', :label => 'Custom Template' %>
-
+
<%= selectable_f f, :builtin_template_name,[[_("No template"), ""]] + compute_resource.builtin_templates.map { |t| [t.name, t.name] }, {}, :class => 'form-control span2', :label => 'Builtin Template' %>
diff --git a/app/views/compute_resources_vms/form/_volume.html.erb b/app/views/compute_resources_vms/form/_volume.html.erb index eca2c84..d558304 100644 --- a/app/views/compute_resources_vms/form/_volume.html.erb +++ b/app/views/compute_resources_vms/form/_volume.html.erb @@ -13,6 +13,7 @@ end end -%> - <%= selectable_f f, :print, compute_resource.storage_pools.map(&:name), { :selected => selected }, :class => "span2", :label => _("Storage Repository") %> + <%= selectable_f f, :sr_uuid, compute_resource.storage_pools.map{ |item| [item[:display_name], item[:uuid]]}, { :selected => selected }, :class => "span2", :label => _("Storage Repository") %> + <%= text_f f, :physical_size, :class => "input-mini", :label => _("Size (GB)"), :value => size %>
\ No newline at end of file diff --git a/app/views/compute_resources_vms/form/xenserver/_base.html.erb b/app/views/compute_resources_vms/form/xenserver/_base.html.erb index 1081160..a8984b3 100644 --- a/app/views/compute_resources_vms/form/xenserver/_base.html.erb +++ b/app/views/compute_resources_vms/form/xenserver/_base.html.erb @@ -40,9 +40,6 @@
- <%= new_child_fields_template(f, :VBDs, { - :object => compute_resource.new_volume, - :partial => 'compute_resources_vms/form/volume', :form_builder_attrs => { :compute_resource => compute_resource, :new => new } }) %> <%= field_set_tag 'Storage', :id => 'storage_volumes', :title => _('Storage') do -%> <%= f.fields_for :VBDs do |i| %> <%= render 'compute_resources_vms/form/volume', :f => i, :compute_resource => compute_resource, :new => new %> @@ -59,16 +56,8 @@
- <%= field_set_tag 'VM Startup Options', :id => 'vm_starup_options', :title => _('Power ON this machine') do -%> -
- -
-
- <% checked = params[:host] && params[:host][:compute_attributes] && params[:host][:compute_attributes][:start] || '1' %> - <%= checkbox_f f, :start, { :checked => (checked == '1')} if fields_enabled %> -
-
-
+ <%= field_set_tag 'VM Startup Options', :id => 'vm_starup_options', :title => _('Power ON this VM') do -%> + <%= checkbox_f f, :start, :checked => true, :label => _("Power ON this VM") %> <% end -%>
@@ -130,8 +119,8 @@ $(document).off('change.xenserver', '#host_compute_attributes_builtin_template_name'); $(document).on('change.xenserver', '#host_compute_attributes_builtin_template_name', function (data) { - $('.xenserver-raw').show(1000); - $('.buildin_templates').prop("disabled", false); + $('.xenserver-raw').show(1000); + $('.buildin_templates').prop("disabled", false); $('#host_compute_attributes_builtin_template_name').removeAttr('disabled'); }) \ No newline at end of file