vagrant-ovirt4 1.2.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +5 -5
  2. data/.github/FUNDING.yml +3 -0
  3. data/.github/workflows/release.yml +20 -0
  4. data/.gitignore +1 -1
  5. data/CHANGELOG +31 -0
  6. data/Dockerfile +11 -0
  7. data/Gemfile +6 -7
  8. data/Gemfile.lock +98 -87
  9. data/README.md +27 -3
  10. data/Rakefile +1 -7
  11. data/SECURITY.md +23 -0
  12. data/lib/vagrant-ovirt4.rb +4 -0
  13. data/lib/vagrant-ovirt4/action.rb +29 -9
  14. data/lib/vagrant-ovirt4/action/connect_ovirt.rb +19 -6
  15. data/lib/vagrant-ovirt4/action/create_network_interfaces.rb +57 -43
  16. data/lib/vagrant-ovirt4/action/create_vm.rb +87 -7
  17. data/lib/vagrant-ovirt4/action/destroy_vm.rb +14 -1
  18. data/lib/vagrant-ovirt4/action/disconnect_ovirt.rb +25 -0
  19. data/lib/vagrant-ovirt4/action/halt_vm.rb +11 -0
  20. data/lib/vagrant-ovirt4/action/read_ssh_info.rb +6 -1
  21. data/lib/vagrant-ovirt4/action/read_state.rb +7 -1
  22. data/lib/vagrant-ovirt4/action/resize_disk.rb +18 -17
  23. data/lib/vagrant-ovirt4/action/snapshot_list.rb +15 -19
  24. data/lib/vagrant-ovirt4/action/start_vm.rb +37 -23
  25. data/lib/vagrant-ovirt4/action/wait_til_suspended.rb +1 -1
  26. data/lib/vagrant-ovirt4/action/wait_till_down.rb +13 -2
  27. data/lib/vagrant-ovirt4/action/wait_till_up.rb +35 -6
  28. data/lib/vagrant-ovirt4/config.rb +60 -2
  29. data/lib/vagrant-ovirt4/errors.rb +20 -0
  30. data/lib/vagrant-ovirt4/plugin.rb +3 -3
  31. data/lib/vagrant-ovirt4/version.rb +1 -1
  32. data/locales/en.yml +17 -1
  33. data/spec/vagrant-ovirt4/config_spec.rb +33 -8
  34. data/templates/Vagrantfile.erb +199 -0
  35. data/tools/prepare_redhat_for_box.sh +6 -1
  36. data/vagrant-ovirt4.gemspec +2 -1
  37. metadata +26 -15
  38. data/lib/vagrant-ovirt4/action/sync_folders.rb +0 -69
  39. data/lib/vagrant-ovirt4/cap/nic_mac_addresses.rb +0 -15
  40. data/test.rb +0 -3
@@ -14,7 +14,20 @@ module VagrantPlugins
14
14
  env[:ui].info(I18n.t("vagrant_ovirt4.destroy_vm"))
15
15
 
16
16
  vm_service = env[:vms_service].vm_service(env[:machine].id)
17
- vm_service.remove
17
+ begin
18
+ vm_service.remove
19
+ rescue OvirtSDK4::Error => e
20
+ fault_message = /Fault detail is \"\[?(.+?)\]?\".*/.match(e.message)[1] rescue e.message
21
+ retry if e.message =~ /Please try again/
22
+
23
+ if config.debug
24
+ raise e
25
+ else
26
+ raise Errors::RemoveVMError,
27
+ :error_message => fault_message
28
+ end
29
+ end
30
+
18
31
  env[:machine].id = nil
19
32
 
20
33
  @app.call(env)
@@ -0,0 +1,25 @@
1
+ require 'log4r'
2
+ require 'ovirtsdk4'
3
+
4
+ module VagrantPlugins
5
+ module OVirtProvider
6
+ module Action
7
+ class DisconnectOVirt
8
+ def initialize(app, env)
9
+ @logger = Log4r::Logger.new("vagrant_ovirt4::action::disconnect_ovirt")
10
+ @app = app
11
+ end
12
+
13
+ def call(env)
14
+
15
+ # Get config options for ovirt provider.
16
+ @logger.info("Disconnecting oVirt connection")
17
+ env[:connection].close()
18
+
19
+ @app.call(env)
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+ end
@@ -12,6 +12,17 @@ module VagrantPlugins
12
12
  def call(env)
13
13
  env[:ui].info(I18n.t("vagrant_ovirt4.halt_vm"))
14
14
 
15
+ # Halt via OS capability
16
+ begin
17
+ if env[:machine].guest.capability?(:halt)
18
+ env[:machine].guest.capability(:halt)
19
+ # Give the VM a chance to shutdown gracefully..."
20
+ sleep 10
21
+ end
22
+ rescue
23
+ env[:ui].info("Failed to shutdown guest gracefully.")
24
+ end
25
+
15
26
  machine = env[:vms_service].vm_service(env[:machine].id)
16
27
  machine.stop rescue nil #todo dont rescue
17
28
 
@@ -36,7 +36,12 @@ module VagrantPlugins
36
36
 
37
37
  nics_service = server.nics_service
38
38
  nics = nics_service.list
39
- ip_addr = nics.collect { |nic_attachment| env[:connection].follow_link(nic_attachment).reported_devices.collect { |dev| dev.ips.collect { |ip| ip.address if ip.version == 'v4' } } }.flatten.reject { |ip| ip.nil? }.first rescue nil
39
+ begin
40
+ ip_addr = nics.collect { |nic_attachment| env[:connection].follow_link(nic_attachment.reported_devices).collect { |dev| dev.ips.collect { |ip| ip.address if ip.version == 'v4' } unless dev.ips.nil? } }.flatten.reject { |ip| ip.nil? }.first
41
+ rescue
42
+ # for backwards compatibility with ovirt 4.3
43
+ ip_addr = nics.collect { |nic_attachment| env[:connection].follow_link(nic_attachment).reported_devices.collect { |dev| dev.ips.collect { |ip| ip.address if ip.version == 'v4' } unless dev.ips.nil? } }.flatten.reject { |ip| ip.nil? }.first rescue nil
44
+ end
40
45
 
41
46
  # Return the info
42
47
  # TODO: Some info should be configurable in Vagrantfile
@@ -33,7 +33,13 @@ module VagrantPlugins
33
33
  end
34
34
  nics_service = server.nics_service
35
35
  nics = nics_service.list
36
- ip_addr = nics.collect { |nic_attachment| env[:connection].follow_link(nic_attachment).reported_devices.collect { |dev| dev.ips.collect { |ip| ip.address if ip.version == 'v4' } } }.flatten.reject { |ip| ip.nil? }.first rescue nil
36
+ begin
37
+ ip_addr = nics.collect { |nic_attachment| env[:connection].follow_link(nic_attachment.reported_devices).collect { |dev| dev.ips.collect { |ip| ip.address if ip.version == 'v4' } unless dev.ips.nil? } }.flatten.reject { |ip| ip.nil? }.first
38
+ rescue
39
+ # for backwards compatibility with ovirt 4.3
40
+ ip_addr = nics.collect { |nic_attachment| env[:connection].follow_link(nic_attachment).reported_devices.collect { |dev| dev.ips.collect { |ip| ip.address if ip.version == 'v4' } unless dev.ips.nil? } }.flatten.reject { |ip| ip.nil? }.first rescue nil
41
+ end
42
+
37
43
  unless ip_addr.nil?
38
44
  env[:ip_address] = ip_addr
39
45
  @logger.debug("Got output #{env[:ip_address]}")
@@ -24,36 +24,37 @@ module VagrantPlugins
24
24
 
25
25
  # Get machine first.
26
26
  begin
27
- machine = OVirtProvider::Util::Collection.find_matching(
28
- env[:ovirt_compute].servers.all, env[:machine].id.to_s)
27
+ vm_service = env[:vms_service].vm_service(env[:machine].id.to_s)
29
28
  rescue => e
30
- raise Errors::NoVMError,
31
- :vm_name => env[:machine].id.to_s
29
+ raise Errors::NoVMError, :vm_id => env[:machine].id
32
30
  end
33
31
 
32
+ disk_attachments_service = vm_service.disk_attachments_service
33
+ disk_attachments = disk_attachments_service.list
34
+ disk = disk_attachments.first.disk
35
+
34
36
  # Extend disk size if necessary
35
37
  begin
36
- machine.update_volume(
37
- :id => machine.volumes.first.id,
38
- :size => config.disk_size*1024*1024*1024,
38
+ disk_attachment_service = disk_attachments_service.attachment_service(disk.id)
39
+ disk_attachment = disk_attachment_service.update(
40
+ OvirtSDK4::DiskAttachment.new(disk: {provisioned_size: config.disk_size})
39
41
  )
40
42
  rescue => e
41
43
  raise Errors::UpdateVolumeError,
42
44
  :error_message => e.message
43
45
  end
44
46
 
45
- # Wait till all volumes are ready.
47
+ # Wait until resize operation has finished.
48
+ disks_service = env[:connection].system_service.disks_service
49
+ disk_service = disks_service.disk_service(disk.id)
46
50
  env[:ui].info(I18n.t("vagrant_ovirt4.wait_for_ready_volume"))
47
- for i in 0..10
48
- ready = true
49
- machine = env[:ovirt_compute].servers.get(env[:machine].id.to_s)
50
- machine.volumes.each do |volume|
51
- if volume.status != 'ok'
52
- ready = false
53
- break
54
- end
51
+ ready = false
52
+ for i in 0..120
53
+ disk = disk_service.get
54
+ if disk.status == OvirtSDK4::DiskStatus::OK
55
+ ready = true
56
+ break
55
57
  end
56
- break if ready
57
58
  sleep 2
58
59
  end
59
60
 
@@ -14,34 +14,30 @@ module VagrantPlugins
14
14
 
15
15
  system_service = env[:connection].system_service
16
16
 
17
- # Find all the virtual machines and store the id and name in a
17
+ #Find all storage domains and store the id and name in a
18
18
  # hash, so that looking them up later will be faster:
19
- vms_map = Hash[env[:vms_service].list.map { |vm| [vm.id, vm.name] }]
20
-
21
- # Same for storage domains:
22
19
  sds_service = system_service.storage_domains_service
23
20
  sds_map = Hash[sds_service.list.map { |sd| [sd.id, sd.name] }]
24
21
 
25
22
  # For each virtual machine find its snapshots, then for each snapshot
26
23
  # find its disks:
27
24
  xs = [['id', 'description', 'date']]
28
- vms_map.each do |vm_id, vm_name|
29
- vm_service = env[:vms_service].vm_service(vm_id)
30
- snaps_service = vm_service.snapshots_service
31
- snaps_map = Hash[snaps_service.list.map { |snap| [snap.id, { description: snap.description, date: snap.date }] }]
32
- snaps_map.each do |snap_id, metadata|
33
- snap_description = metadata[:description]
34
- snap_date = metadata[:date]
35
- snap_service = snaps_service.snapshot_service(snap_id)
36
- disks_service = snap_service.disks_service
37
- disks_service.list.each do |disk|
38
- next unless disk.storage_domains.any?
39
- sd_id = disk.storage_domains.first.id
40
- sd_name = sds_map[sd_id]
41
- xs.push([snap_id, snap_description, snap_date.to_s])
42
- end
25
+ vm_service = env[:vms_service].vm_service(env[:machine].id)
26
+ snaps_service = vm_service.snapshots_service
27
+ snaps_map = Hash[snaps_service.list.map { |snap| [snap.id, { description: snap.description, date: snap.date }] }]
28
+ snaps_map.each do |snap_id, metadata|
29
+ snap_description = metadata[:description]
30
+ snap_date = metadata[:date]
31
+ snap_service = snaps_service.snapshot_service(snap_id)
32
+ disks_service = snap_service.disks_service
33
+ disks_service.list.each do |disk|
34
+ next unless disk.storage_domains.any?
35
+ sd_id = disk.storage_domains.first.id
36
+ sd_name = sds_map[sd_id]
37
+ xs.push([snap_id, snap_description, snap_date.to_s])
43
38
  end
44
39
  end
40
+
45
41
  widths = xs.transpose.map { |column_arr| column_arr.map(&:size).max }
46
42
  env[:machine_snapshot_list] =
47
43
  xs.map { |row_arr|
@@ -25,22 +25,36 @@ module VagrantPlugins
25
25
  :vm_name => env[:machine].id.to_s
26
26
  end
27
27
 
28
- iface_options = nil
29
- env[:machine].config.vm.networks.each do |config|
30
- type, options = config
31
- next unless [:private_network].include? type
28
+ # FIX MULTIPLE NETWORK INTERFACES
29
+ hostname = env[:machine].config.vm.hostname
30
+ hostname = 'vagrant' if hostname.nil?
31
+
32
+ initialization = {
33
+ host_name: hostname,
34
+ nic_configurations: [],
35
+ custom_script: config.cloud_init,
36
+ }
37
+
38
+ configured_ifaces_options = []
39
+ env[:machine].config.vm.networks.each do |network|
40
+ type, options = network
41
+ next unless type == :private_network
32
42
 
33
- iface_options = scoped_hash_override(options, :ovirt)
43
+ configured_ifaces_options << scoped_hash_override(options, :ovirt)
34
44
  end
35
45
 
36
- hostname = env[:machine].config.vm.hostname
37
- hostname = 'vagrant' if hostname.nil?
46
+ (0...configured_ifaces_options.length()).each do |iface_index|
47
+ iface_options = configured_ifaces_options[iface_index]
48
+
49
+ if iface_options[:interface_name] != nil then
50
+ iface_name = iface_options[:interface_name]
51
+ else
52
+ iface_name = "eth#{iface_index}"
53
+ end
38
54
 
39
- nic_configuration = nil
40
- unless iface_options.nil?
41
55
  if iface_options[:ip] then
42
56
  nic_configuration = {
43
- name: 'eth0',
57
+ name: iface_name,
44
58
  on_boot: true,
45
59
  boot_protocol: OvirtSDK4::BootProtocol::STATIC,
46
60
  ip: {
@@ -52,21 +66,17 @@ module VagrantPlugins
52
66
  }
53
67
  else
54
68
  nic_configuration = {
55
- name: 'eth0',
69
+ name: iface_name,
56
70
  on_boot: true,
57
71
  boot_protocol: OvirtSDK4::BootProtocol::DHCP,
58
72
  }
59
73
  end
60
74
 
61
- initialization = {
62
- host_name: hostname,
63
- nic_configurations: [nic_configuration],
64
- custom_script: config.cloud_init,
65
- }
66
-
75
+ initialization[:nic_configurations] << nic_configuration
67
76
  initialization[:dns_servers] = iface_options[:dns_servers] unless iface_options[:dns_servers].nil?
68
77
  initialization[:dns_search] = iface_options[:dns_search] unless iface_options[:dns_search].nil?
69
78
  end
79
+ # END FIX MULTIPLE NETWORK INTERFACES
70
80
 
71
81
  vm_configuration = {
72
82
  initialization: initialization,
@@ -85,12 +95,16 @@ module VagrantPlugins
85
95
  vm: vm_configuration
86
96
  )
87
97
  rescue OvirtSDK4::Error => e
88
- if config.debug
89
- raise e
90
- else
91
- fault_message = /Fault detail is \"\[?(.+?)\]?\".*/.match(e.message)[1] rescue e.message
92
- raise Errors::StartVMError,
93
- :error_message => fault_message
98
+ fault_message = /Fault detail is \"\[?(.+?)\]?\".*/.match(e.message)[1] rescue e.message
99
+ retry if e.message =~ /Please try again/
100
+
101
+ if e.message !~ /VM is running/
102
+ if config.debug
103
+ raise e
104
+ else
105
+ raise Errors::StartVMError,
106
+ :error_message => fault_message
107
+ end
94
108
  end
95
109
 
96
110
  end
@@ -20,7 +20,7 @@ module VagrantPlugins
20
20
  for i in 1..300
21
21
  ready = true
22
22
  if vm_service.get == nil
23
- raise NoVMError, :vm_name => ''
23
+ raise NoVMError, :vm_id => env[:machine].id
24
24
  end
25
25
 
26
26
  if vm_service.get.status.to_sym != :suspended
@@ -21,10 +21,21 @@ module VagrantPlugins
21
21
  env[:ui].info(I18n.t("vagrant_ovirt4.wait_till_down"))
22
22
  for i in 1..300
23
23
  ready = true
24
- if vm_service.get == nil
25
- raise NoVMError, :vm_name => ''
24
+ begin
25
+ if vm_service.get == nil
26
+ raise NoVMError, :error_message => '', :vm_id => env[:machine].id
27
+ end
28
+ rescue OvirtSDK4::Error => e
29
+ fault_message = /Fault detail is \"\[?(.+?)\]?\".*/.match(e.message)[1] rescue e.message
30
+ if config.debug
31
+ raise e
32
+ else
33
+ raise Errors::NoVMError, :error_message => fault_message, :vm_id => env[:machine].id
34
+ end
26
35
  end
27
36
 
37
+
38
+
28
39
  if vm_service.get.status.to_sym != :down
29
40
  ready = false
30
41
  end
@@ -1,6 +1,8 @@
1
1
  require 'log4r'
2
2
  require 'vagrant-ovirt4/util/timer'
3
3
  require 'vagrant/util/retryable'
4
+ require 'socket'
5
+ require 'timeout'
4
6
 
5
7
  module VagrantPlugins
6
8
  module OVirtProvider
@@ -16,6 +18,23 @@ module VagrantPlugins
16
18
  @app = app
17
19
  end
18
20
 
21
+ def port_open?(ip, port, seconds=10)
22
+ # => checks if a port is open or not on a remote host
23
+ Timeout::timeout(seconds) do
24
+ begin
25
+ TCPSocket.new(ip, port).close
26
+ @logger.info("SSH Check OK for IP: #{ip}")
27
+ true
28
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, SocketError => e
29
+ @logger.info("SSH Connection Failed for IP #{ip}: #{e}")
30
+ false
31
+ end
32
+ end
33
+ rescue Timeout::Error
34
+ @logger.info("SSH Connection Failed: Timeout for IP: #{ip}" )
35
+ false
36
+ end
37
+
19
38
  def call(env)
20
39
  # Initialize metrics if they haven't been
21
40
  env[:metrics] ||= {}
@@ -33,23 +52,33 @@ module VagrantPlugins
33
52
  # Get VM.
34
53
  server = env[:vms_service].vm_service(env[:machine].id)
35
54
  if server == nil
36
- raise NoVMError, :vm_name => ''
55
+ raise Errors::NoVMError, :vm_id => env[:machine].id
37
56
  end
38
57
 
39
58
  nics_service = server.nics_service
40
59
  nics = nics_service.list
41
- ip_addr = nics.collect { |nic_attachment| env[:connection].follow_link(nic_attachment).reported_devices.collect { |dev| dev.ips.collect { |ip| ip.address if ip.version == 'v4' } } }.flatten.reject { |ip| ip.nil? }.first rescue nil
60
+ begin
61
+ ip_addr = nics.collect { |nic_attachment| env[:connection].follow_link(nic_attachment.reported_devices).collect { |dev| dev.ips.collect { |ip| ip.address if ip.version == 'v4' } unless dev.ips.nil? } }.flatten.reject { |ip| ip.nil? }.first
62
+ rescue
63
+ # for backwards compatibility with ovirt 4.3
64
+ ip_addr = nics.collect { |nic_attachment| env[:connection].follow_link(nic_attachment).reported_devices.collect { |dev| dev.ips.collect { |ip| ip.address if ip.version == 'v4' } unless dev.ips.nil? } }.flatten.reject { |ip| ip.nil? }.first rescue nil
65
+ end
66
+
42
67
  unless ip_addr.nil?
43
- env[:ip_address] = ip_addr
44
- break
45
- @logger.debug("Got output #{env[:ip_address]}")
68
+ env[:ui].info("Got IP: #{ip_addr}")
69
+ # Check if SSH-Server is up
70
+ if port_open?(ip_addr, 22)
71
+ env[:ip_address] = ip_addr
72
+ break
73
+ @logger.debug("Got output #{env[:ip_address]}")
74
+ end
46
75
  end
47
76
  sleep 5
48
77
  end
49
78
  end
50
79
  terminate(env) if env[:interrupted]
51
80
  if env[:ip_address].nil?
52
- raise NoIPError
81
+ raise Errors::NoIPError
53
82
  else
54
83
  @logger.info("Got IP address #{env[:ip_address]}")
55
84
  @logger.info("Time for getting IP: #{env[:metrics]["instance_ip_time"]}")
@@ -11,6 +11,8 @@ module VagrantPlugins
11
11
  attr_accessor :password
12
12
  attr_accessor :insecure
13
13
  attr_accessor :debug
14
+ attr_accessor :disk_size
15
+ attr_accessor :filtered_api
14
16
  attr_accessor :cpu_cores
15
17
  attr_accessor :cpu_sockets
16
18
  attr_accessor :cpu_threads
@@ -23,6 +25,11 @@ module VagrantPlugins
23
25
  attr_accessor :cloud_init
24
26
  attr_accessor :affinity
25
27
  attr_accessor :placement_host
28
+ attr_accessor :bios_serial
29
+ attr_accessor :optimized_for
30
+ attr_accessor :description
31
+ attr_accessor :comment
32
+ attr_accessor :disks
26
33
 
27
34
  def initialize
28
35
  @url = UNSET_VALUE
@@ -30,6 +37,8 @@ module VagrantPlugins
30
37
  @password = UNSET_VALUE
31
38
  @insecure = UNSET_VALUE
32
39
  @debug = UNSET_VALUE
40
+ @disk_size = UNSET_VALUE
41
+ @filtered_api = UNSET_VALUE
33
42
  @cpu_cores = UNSET_VALUE
34
43
  @cpu_sockets = UNSET_VALUE
35
44
  @cpu_threads = UNSET_VALUE
@@ -42,37 +51,86 @@ module VagrantPlugins
42
51
  @cloud_init = UNSET_VALUE
43
52
  @affinity = UNSET_VALUE
44
53
  @placement_host = UNSET_VALUE
54
+ @bios_serial = UNSET_VALUE
55
+ @optimized_for = UNSET_VALUE
56
+ @description = UNSET_VALUE
57
+ @comment = UNSET_VALUE
58
+ @disks = []
45
59
 
46
60
  end
47
61
 
62
+ def storage(storage_type, options = {})
63
+ if storage_type == :file
64
+ _handle_disk_storage(options)
65
+ end
66
+ end
67
+
68
+ def _handle_disk_storage(options ={})
69
+ options = {
70
+ name: "storage_disk_#{@disks.length + 1}",
71
+ type: 'qcow2',
72
+ size: Filesize.from('8G').to_f('B').to_i,
73
+ bus: 'virtio'
74
+ }.merge(options)
75
+
76
+ disk = {
77
+ name: options[:name],
78
+ device: options[:device],
79
+ type: options[:type],
80
+ size: Filesize.from(options[:size]).to_f('B').to_i,
81
+ storage_domain: options[:storage_domain],
82
+ bus: options[:bus]
83
+ }
84
+
85
+ @disks << disk # append
86
+ end
87
+
48
88
  def finalize!
49
89
  @url = nil if @url == UNSET_VALUE
50
90
  @username = nil if @username == UNSET_VALUE
51
91
  @password = nil if @password == UNSET_VALUE
52
92
  @insecure = false if @insecure == UNSET_VALUE
53
93
  @debug = false if @debug == UNSET_VALUE
94
+ @disk_size = nil if @disk_size == UNSET_VALUE
95
+ @filtered_api = false if @filtered_api == UNSET_VALUE
54
96
  @cpu_cores = 1 if @cpu_cores == UNSET_VALUE
55
97
  @cpu_sockets = 1 if @cpu_sockets == UNSET_VALUE
56
98
  @cpu_threads = 1 if @cpu_threads == UNSET_VALUE
57
99
  @cluster = nil if @cluster == UNSET_VALUE
58
100
  @console = nil if @console == UNSET_VALUE
59
- @memory_size = '256 MB' if @memory_size == UNSET_VALUE
101
+ @memory_size = '256 MiB' if @memory_size == UNSET_VALUE
60
102
  @memory_maximum = @memory_size if @memory_maximum == UNSET_VALUE
61
103
  @memory_guaranteed = @memory_size if @memory_guaranteed == UNSET_VALUE
62
104
  @template = nil if @template == UNSET_VALUE
63
105
  @cloud_init = nil if @cloud_init == UNSET_VALUE
64
106
  @affinity = nil if @affinity == UNSET_VALUE
65
107
  @placement_host = nil if @placement_host == UNSET_VALUE
108
+ @bios_serial = nil if @bios_serial == UNSET_VALUE
109
+ @optimized_for = nil if @optimized_for == UNSET_VALUE
110
+ @description = '' if @description == UNSET_VALUE
111
+ @comment = '' if @comment == UNSET_VALUE
112
+
113
+ unless optimized_for.nil?
114
+ raise "Invalid 'optimized_for'. Must be one of #{OvirtSDK4::VmType.constants.map { |s| "'#{s.downcase}'" }.join(' ')}" unless OvirtSDK4::VmType.constants.include? optimized_for.upcase.to_sym
115
+ end
66
116
 
67
117
  unless affinity.nil?
68
118
  raise "Invalid affinity. Must be one of #{OvirtSDK4::VmAffinity.constants.map { |s| "'#{s.downcase}'" }.join(' ')}" unless OvirtSDK4::VmAffinity.constants.include? affinity.upcase.to_sym
69
119
  end
70
120
 
121
+ unless disk_size.nil?
122
+ begin
123
+ @disk_size = Filesize.from(@disk_size).to_f('B').to_i
124
+ rescue ArgumentError
125
+ raise "Not able to parse 'disk_size'. Please verify and check again."
126
+ end
127
+ end
128
+
71
129
  begin
72
130
  @memory_size = Filesize.from(@memory_size).to_f('B').to_i
73
131
  @memory_maximum = Filesize.from(@memory_maximum).to_f('B').to_i
74
132
  @memory_guaranteed = Filesize.from(@memory_guaranteed).to_f('B').to_i
75
- rescue ArgumentError
133
+ rescue ArgumentError
76
134
  raise "Not able to parse either `memory_size` or `memory_guaranteed`. Please verify and check again."
77
135
  end
78
136
  end