Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
1. Fixed creating VM using local storage
2. Fixed UI issue when "Local Storages" doesn't present to which host in
POOL its connected
3. VM creates on SR based on UUID and not based  on name as before
  • Loading branch information
oovoo committed May 26, 2015
1 parent 6677f53 commit 46117cc
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
35 changes: 32 additions & 3 deletions app/models/foreman_xen/xenserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/views/compute_resources_vms/form/_templates.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
%>

<div id='templates' class=''>
<div class="form-group custom_templates">
<div class="form-group">
<%= 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' %>
</div>

<div class="form-group buildin_templates">
<div class="form-group ">
<%= 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' %>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/views/compute_resources_vms/form/_volume.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
</div>
19 changes: 4 additions & 15 deletions app/views/compute_resources_vms/form/xenserver/_base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@

<!--Storage-->
<div class="children_fields xenserver-raw" id="xenserver-storage" style="<%= hide_raw %>">
<%= 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 %>
Expand All @@ -59,16 +56,8 @@
</div>

<div class="children_fields" id="xenserver-vm-start" style="<%= hide_raw %>">
<%= field_set_tag 'VM Startup Options', :id => 'vm_starup_options', :title => _('Power ON this machine') do -%>
<div class="form-group">
<label class="col-md-2 control-label" for="xenserver-vm-start-params">Power ON this VM</label>
<div class="col-md-4">
<div class="controls">
<% checked = params[:host] && params[:host][:compute_attributes] && params[:host][:compute_attributes][:start] || '1' %>
<%= checkbox_f f, :start, { :checked => (checked == '1')} if fields_enabled %>
</div>
</div>
</div>
<%= 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 -%>
</div>

Expand Down Expand Up @@ -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');
})
</script>

0 comments on commit 46117cc

Please sign in to comment.