Revision 545716c4
Added by Marek Hulán about 8 years ago
app/models/compute_attribute.rb | ||
---|---|---|
before_save :update_name
|
||
|
||
def method_missing(method, *args, &block)
|
||
return super if method.to_s[-1]=="="
|
||
return super unless respond_to?(:vm_attrs)
|
||
return vm_attrs["#{method}"] if vm_attrs.keys.include?(method.to_s)
|
||
raise Foreman::Exception.new(N_('%s is an unknown attribute'), method)
|
||
method = method.to_s
|
||
return super if method[-1]=="="
|
||
return super if method == 'vm_attrs'
|
||
|
||
if vm_attrs.has_key?(method)
|
||
vm_attrs[method]
|
||
else
|
||
raise Foreman::Exception.new(N_('%s is an unknown attribute'), method)
|
||
end
|
||
end
|
||
|
||
def respond_to_missing?(method, include_private = false)
|
||
vm_attrs.has_key?(method.to_s) || super
|
||
end
|
||
|
||
def vm_interfaces
|
app/models/compute_resources/foreman/model/ovirt.rb | ||
---|---|---|
interfaces = nested_attributes_for :interfaces, attr[:interfaces_attributes]
|
||
interfaces.map{ |i| vm.interfaces << new_interface(i)}
|
||
volumes = nested_attributes_for :volumes, attr[:volumes_attributes]
|
||
volumes.map{ |v| vm.volumes << new_volume(v)}
|
||
volumes.map { |v| vm.volumes << new_volume(v) }
|
||
vm
|
||
end
|
||
|
||
... | ... | |
end
|
||
|
||
def new_volume(attr = {})
|
||
set_preallocated_attributes!(attr, attr[:preallocate])
|
||
Fog::Compute::Ovirt::Volume.new(attr)
|
||
end
|
||
|
||
... | ... | |
#add volumes
|
||
volumes = nested_attributes_for :volumes, attrs
|
||
volumes.map do |vol|
|
||
vol[:sparse] = "true"
|
||
vol[:format] = "raw" if vol[:preallocate] == "1"
|
||
vol[:sparse] = "false" if vol[:preallocate] == "1"
|
||
set_preallocated_attributes!(vol, vol[:preallocate])
|
||
#The blocking true is a work-around for ovirt bug fixed in ovirt version 3.1.
|
||
vm.add_volume({:bootable => 'false', :quota => ovirt_quota, :blocking => api_version.to_f < 3.1}.merge(vol)) if vol[:id].blank?
|
||
end
|
||
vm.volumes.reload
|
||
end
|
||
|
||
def set_preallocated_attributes!(volume_attributes, preallocate)
|
||
if preallocate == '1'
|
||
volume_attributes[:sparse] = 'false'
|
||
volume_attributes[:format] = 'raw'
|
||
else
|
||
volume_attributes[:sparse] = 'true'
|
||
end
|
||
end
|
||
|
||
def update_interfaces(vm, attrs)
|
||
interfaces = nested_attributes_for :interfaces, attrs
|
||
interfaces.each do |interface|
|
app/views/compute_resources_vms/form/ovirt/_volume.html.erb | ||
---|---|---|
<%= f.hidden_field :storage_domain if !new_host %>
|
||
<%= f.hidden_field :id %>
|
||
|
||
<%= checkbox_f f, :preallocate, { :checked => false, :help_inline => _('Uses thin provisioning if unchecked'), :label => _('Preallocate disk'), :label_size => "col-md-2" } %>
|
||
<%= checkbox_f f, :preallocate, { :checked => f.object.sparse == 'false', :help_inline => _('Uses thin provisioning if unchecked'), :label => _('Preallocate disk'), :label_size => "col-md-2" } %>
|
||
|
||
<%= field(f, :bootable, :label => _('Bootable'), :label_size => "col-md-2") do
|
||
radio_button_f f, :bootable, {:disabled => !new_host, :value=>'true', :checked => (f.object.bootable == 'true'), :onclick => 'bootable_radio(this)',
|
test/unit/models/ovirt_test.rb | ||
---|---|---|
require 'test_helper'
|
||
|
||
module Models
|
||
class OvirtTest < ActiveSupport::TestCase
|
||
setup do
|
||
User.current = users :admin
|
||
end
|
||
|
||
test "#new_volume should respect preallocate flag" do
|
||
ovirt = Foreman::Model::Ovirt.new
|
||
volume = ovirt.new_volume(:preallocate => '1')
|
||
assert_equal 'false', volume.sparse
|
||
assert_equal 'raw', volume.format
|
||
|
||
volume = ovirt.new_volume(:preallocate => '0')
|
||
assert_equal 'true', volume.sparse
|
||
|
||
volume = ovirt.new_volume
|
||
assert_equal 'true', volume.sparse
|
||
end
|
||
end
|
||
end
|
Also available in: Unified diff
Fixes #9932 - fix preallocate attribute mapping