vagrant-ovirt4 1.1.0 → 2.0.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 (37) 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 +2 -0
  5. data/Dockerfile +11 -0
  6. data/Gemfile +5 -11
  7. data/Gemfile.lock +31 -37
  8. data/README.md +26 -12
  9. data/Rakefile +1 -7
  10. data/lib/vagrant-ovirt4/action.rb +29 -9
  11. data/lib/vagrant-ovirt4/action/connect_ovirt.rb +1 -0
  12. data/lib/vagrant-ovirt4/action/create_network_interfaces.rb +62 -26
  13. data/lib/vagrant-ovirt4/action/create_vm.rb +98 -14
  14. data/lib/vagrant-ovirt4/action/destroy_vm.rb +14 -1
  15. data/lib/vagrant-ovirt4/action/disconnect_ovirt.rb +25 -0
  16. data/lib/vagrant-ovirt4/action/halt_vm.rb +11 -0
  17. data/lib/vagrant-ovirt4/action/read_ssh_info.rb +6 -1
  18. data/lib/vagrant-ovirt4/action/read_state.rb +7 -1
  19. data/lib/vagrant-ovirt4/action/resize_disk.rb +18 -17
  20. data/lib/vagrant-ovirt4/action/start_vm.rb +76 -34
  21. data/lib/vagrant-ovirt4/action/wait_til_suspended.rb +1 -1
  22. data/lib/vagrant-ovirt4/action/wait_till_down.rb +13 -2
  23. data/lib/vagrant-ovirt4/action/wait_till_up.rb +35 -6
  24. data/lib/vagrant-ovirt4/config.rb +81 -1
  25. data/lib/vagrant-ovirt4/errors.rb +20 -0
  26. data/lib/vagrant-ovirt4/plugin.rb +3 -3
  27. data/lib/vagrant-ovirt4/version.rb +1 -1
  28. data/locales/en.yml +17 -1
  29. data/spec/vagrant-ovirt4/config_spec.rb +53 -3
  30. data/templates/Vagrantfile.erb +199 -0
  31. data/tools/prepare_redhat_for_box.sh +18 -2
  32. data/vagrant-ovirt4.gemspec +3 -1
  33. metadata +35 -13
  34. data/docker-compose.yml +0 -9
  35. data/lib/vagrant-ovirt4/action/sync_folders.rb +0 -69
  36. data/lib/vagrant-ovirt4/cap/nic_mac_addresses.rb +0 -15
  37. data/test.rb +0 -3
@@ -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"]}")
@@ -1,4 +1,6 @@
1
1
  require 'vagrant'
2
+ require 'filesize'
3
+ require 'ovirtsdk4'
2
4
 
3
5
  module VagrantPlugins
4
6
  module OVirtProvider
@@ -9,15 +11,25 @@ module VagrantPlugins
9
11
  attr_accessor :password
10
12
  attr_accessor :insecure
11
13
  attr_accessor :debug
14
+ attr_accessor :disk_size
15
+ attr_accessor :filtered_api
12
16
  attr_accessor :cpu_cores
13
17
  attr_accessor :cpu_sockets
14
18
  attr_accessor :cpu_threads
15
19
  attr_accessor :template
16
20
  attr_accessor :memory_size
21
+ attr_accessor :memory_maximum
17
22
  attr_accessor :memory_guaranteed
18
23
  attr_accessor :cluster
19
24
  attr_accessor :console
20
25
  attr_accessor :cloud_init
26
+ attr_accessor :affinity
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
21
33
 
22
34
  def initialize
23
35
  @url = UNSET_VALUE
@@ -25,34 +37,102 @@ module VagrantPlugins
25
37
  @password = UNSET_VALUE
26
38
  @insecure = UNSET_VALUE
27
39
  @debug = UNSET_VALUE
40
+ @disk_size = UNSET_VALUE
41
+ @filtered_api = UNSET_VALUE
28
42
  @cpu_cores = UNSET_VALUE
29
43
  @cpu_sockets = UNSET_VALUE
30
44
  @cpu_threads = UNSET_VALUE
31
45
  @template = UNSET_VALUE
32
46
  @memory_size = UNSET_VALUE
47
+ @memory_maximum = UNSET_VALUE
33
48
  @memory_guaranteed = UNSET_VALUE
34
49
  @cluster = UNSET_VALUE
35
50
  @console = UNSET_VALUE
36
51
  @cloud_init = UNSET_VALUE
52
+ @affinity = UNSET_VALUE
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 = []
37
59
 
38
60
  end
39
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
+
40
88
  def finalize!
41
89
  @url = nil if @url == UNSET_VALUE
42
90
  @username = nil if @username == UNSET_VALUE
43
91
  @password = nil if @password == UNSET_VALUE
44
92
  @insecure = false if @insecure == UNSET_VALUE
45
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
46
96
  @cpu_cores = 1 if @cpu_cores == UNSET_VALUE
47
97
  @cpu_sockets = 1 if @cpu_sockets == UNSET_VALUE
48
98
  @cpu_threads = 1 if @cpu_threads == UNSET_VALUE
49
99
  @cluster = nil if @cluster == UNSET_VALUE
50
100
  @console = nil if @console == UNSET_VALUE
51
- @memory_size = 256 if @memory_size == UNSET_VALUE
101
+ @memory_size = '256 MiB' if @memory_size == UNSET_VALUE
102
+ @memory_maximum = @memory_size if @memory_maximum == UNSET_VALUE
52
103
  @memory_guaranteed = @memory_size if @memory_guaranteed == UNSET_VALUE
53
104
  @template = nil if @template == UNSET_VALUE
54
105
  @cloud_init = nil if @cloud_init == UNSET_VALUE
106
+ @affinity = nil if @affinity == UNSET_VALUE
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
116
+
117
+ unless affinity.nil?
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
119
+ end
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
55
128
 
129
+ begin
130
+ @memory_size = Filesize.from(@memory_size).to_f('B').to_i
131
+ @memory_maximum = Filesize.from(@memory_maximum).to_f('B').to_i
132
+ @memory_guaranteed = Filesize.from(@memory_guaranteed).to_f('B').to_i
133
+ rescue ArgumentError
134
+ raise "Not able to parse either `memory_size` or `memory_guaranteed`. Please verify and check again."
135
+ end
56
136
  end
57
137
 
58
138
  end
@@ -7,6 +7,10 @@ module VagrantPlugins
7
7
  error_namespace("vagrant_ovirt4.errors")
8
8
  end
9
9
 
10
+ class RsyncError < VagrantOVirtError
11
+ error_key(:rsync_error)
12
+ end
13
+
10
14
  class NoVMError < VagrantOVirtError
11
15
  error_key(:no_vm_error)
12
16
  end
@@ -31,6 +35,10 @@ module VagrantPlugins
31
35
  error_key(:no_network_error)
32
36
  end
33
37
 
38
+ class NetworkNotFoundError < VagrantOVirtError
39
+ error_key(:network_not_found_error)
40
+ end
41
+
34
42
  class NoIPError < VagrantOVirtError
35
43
  error_key(:no_ip_error)
36
44
  end
@@ -42,6 +50,18 @@ module VagrantPlugins
42
50
  class RemoveSnapshotError < VagrantOVirtError
43
51
  error_key(:remove_snapshot_error)
44
52
  end
53
+
54
+ class UpdateVolumeError < VagrantOVirtError
55
+ error_key(:resize_disk_error)
56
+ end
57
+
58
+ class RemoveVMError < VagrantOVirtError
59
+ error_key(:remove_vm_error)
60
+ end
61
+
62
+ class UpdateBiosError < VagrantOVirtError
63
+ error_key(:update_bios_error)
64
+ end
45
65
  end
46
66
  end
47
67
  end
@@ -8,9 +8,9 @@ end
8
8
 
9
9
  # This is a sanity check to make sure no one is attempting to install
10
10
  # this into an early Vagrant version.
11
- # Note: snapshots only available in 1.8+
12
- if Vagrant::VERSION < '1.8.0'
13
- raise "The Vagrant oVirt v4 plugin is only compatible with Vagrant 1.8+"
11
+ # Note: snapshots only available in 1.9.1+
12
+ if Vagrant::VERSION < '1.9.1'
13
+ raise "The Vagrant oVirt v4 plugin is only compatible with Vagrant 1.9.1+"
14
14
  end
15
15
 
16
16
  module VagrantPlugins
@@ -1,6 +1,6 @@
1
1
  module VagrantPlugins
2
2
  module OVirtProvider
3
- VERSION = '1.1.0'
3
+ VERSION = '2.0.0'
4
4
  end
5
5
  end
6
6
 
@@ -14,6 +14,8 @@ en:
14
14
  VM is currently powering up. Please run `vagrant halt` to abort or wait until its status is 'up'.
15
15
  wait_for_ready_vm: |-
16
16
  Waiting for VM to become "ready" to start...
17
+ wait_for_ready_volume: |-
18
+ Waiting for disk resize to finish...
17
19
  error_recovering: |-
18
20
  An error occured. Recovering..
19
21
  waiting_for_ip: |-
@@ -53,14 +55,26 @@ en:
53
55
  The instance is not running. Use `vagrant up` to start it.
54
56
  short_down: |-
55
57
  down
58
+ long_not_created: |-
59
+ The instance is not created. Use `vagrant up` to create it.
60
+ short_not_created: |-
61
+ not created
56
62
  errors:
63
+ remove_vm_error: |-
64
+ Error removing VM '%{vm_name}'. oVirt error message was '%{error_message}'
57
65
  no_vm_error: |-
58
- No VM %{vm_name} found.
66
+ No VM found with id '%{vm_id}'
67
+ rsync_error: |-
68
+ An rsync error occurred. oVirt error message was '%{error_message}'
59
69
  create_vm_error: |-
60
70
  Creation failed. oVirt error message was '%{error_message}'
71
+ update_bios_error: |-
72
+ BIOS update failed. oVirt error message was '%{error_message}'
61
73
  start_vm_error: |-
62
74
  Unable to start VM: %{error_message}
63
75
  no_network_error: |-
76
+ No network provided and none were imported from the template. There would be no way to communicate with this machine.
77
+ network_not_found_error: |-
64
78
  No network %{network_name} found.
65
79
  wait_for_ready_vm_timeout: |-
66
80
  Timeout occurred while waiting for VM to become ready to start
@@ -72,3 +86,5 @@ en:
72
86
  Snapshot with id %{id} is the active snapshot which cannot be removed.
73
87
  remove_snapshot_error: |-
74
88
  Snapshot with id %{id} Could not be removed. Details: %{error_message}.
89
+ resize_disk_error: |-
90
+ Disk resize failed. oVirt error message was '%{error_message}'
@@ -33,20 +33,28 @@ describe VagrantPlugins::OVirtProvider::Config do
33
33
  its("password") { should be_nil }
34
34
  its("insecure") { should == false }
35
35
  its("debug") { should == false }
36
+ its("filtered_api") { should == false }
36
37
  its("cpu_cores") { should == 1 }
37
38
  its("cpu_sockets") { should == 1 }
38
39
  its("cpu_threads") { should == 1 }
39
40
  its("cluster") { should be_nil }
40
41
  its("console") { should be_nil }
41
42
  its("template") { should be_nil }
42
- its("memory_size") { should == 256 }
43
- its("memory_guaranteed") { should == 256 }
43
+ its("memory_size") { should == 256000000 }
44
+ its("memory_maximum") { should == 256000000 }
45
+ its("memory_guaranteed") { should == 256000000 }
44
46
  its("cloud_init") { should be_nil }
47
+ its("affinity") { should be_nil }
48
+ its("placement_host") { should be_nil }
49
+ its("bios_serial") { should be_nil }
50
+ its("optimized_for") { should be_nil }
51
+ its("description") { should == '' }
52
+ its("comment") { should == '' }
45
53
 
46
54
  end
47
55
 
48
56
  describe "overriding defaults" do
49
- [:url, :username, :password, :insecure, :debug, :cpu_cores, :cpu_sockets, :cpu_threads, :cluster, :console, :template, :memory_size, :memory_guaranteed, :cloud_init].each do |attribute|
57
+ [:url, :username, :password, :insecure, :debug, :filtered_api, :cpu_cores, :cpu_sockets, :cpu_threads, :cluster, :console, :template, :cloud_init, :placement_host, :bios_serial, :optimized_for, :description, :comment].each do |attribute|
50
58
 
51
59
  it "should not default #{attribute} if overridden" do
52
60
  instance.send("#{attribute}=".to_sym, "foo")
@@ -56,4 +64,46 @@ describe VagrantPlugins::OVirtProvider::Config do
56
64
  end
57
65
  end
58
66
 
67
+ describe "overriding memory defaults" do
68
+ [:memory_size, :memory_maximum, :memory_guaranteed].each do |attribute|
69
+
70
+ it "should not default #{attribute} if overridden" do
71
+ instance.send("#{attribute}=".to_sym, "512 MiB")
72
+ instance.finalize!
73
+ instance.send(attribute).should == 512000000
74
+ end
75
+
76
+ it "should convert the value" do
77
+ instance.send("#{attribute}=".to_sym, "1 GiB")
78
+ instance.finalize!
79
+ instance.send(attribute).should == 1000000000
80
+ end
81
+
82
+ end
83
+ end
84
+
85
+ describe "overriding affinity defaults" do
86
+ [:affinity].each do |attribute|
87
+
88
+ context 'valid value' do
89
+ it "should not default #{attribute} if overridden" do
90
+ instance.send("#{attribute}=".to_sym, "pinned")
91
+ instance.finalize!
92
+ instance.send(attribute).should == "pinned"
93
+ end
94
+ end
95
+
96
+ context 'invalid value' do
97
+ it "should error" do
98
+ expect {
99
+ instance.send("#{attribute}=".to_sym, "foo")
100
+ instance.finalize!
101
+ }.to raise_error(RuntimeError)
102
+
103
+ end
104
+
105
+ end
106
+
107
+ end
108
+ end
59
109
  end
@@ -0,0 +1,199 @@
1
+ <% config[:vagrantfiles].each do |vagrantfile| %>
2
+ require "<%= vagrantfile %>"
3
+ require 'securerandom'
4
+ <% end %>
5
+
6
+ Vagrant.configure("2") do |c|
7
+ c.berkshelf.enabled = false if Vagrant.has_plugin?("vagrant-berkshelf")
8
+ <% if config[:cachier] %>
9
+ if Vagrant.has_plugin?("vagrant-cachier")
10
+ c.cache.scope = <%= [':box', ':machine'].include?(config[:cachier]) ? config[:cachier] : ':box' %>
11
+ end
12
+ <% end %>
13
+
14
+ c.vm.box = "<%= config[:box] %>"
15
+
16
+ <% if config[:box_url] %>
17
+ c.vm.box_url = "<%= config[:box_url] %>"
18
+ <% end %>
19
+
20
+ <% if config[:box_version] %>
21
+ c.vm.box_version = "<%= config[:box_version] %>"
22
+ <% end %>
23
+
24
+ <% if !config[:box_check_update].nil? %>
25
+ c.vm.box_check_update = <%= config[:box_check_update] %>
26
+ <% end %>
27
+
28
+ <% if !config[:box_download_ca_cert].nil? %>
29
+ c.vm.box_download_ca_cert = "<%= config[:box_download_ca_cert] %>"
30
+ <% end %>
31
+
32
+ <% if !config[:box_download_insecure].nil? %>
33
+ c.vm.box_download_insecure = "<%= config[:box_download_insecure] %>"
34
+ <% end %>
35
+
36
+ <% if config[:vm_hostname] %>
37
+ c.vm.hostname = "kitchen-<%= config[:vm_hostname] %>-<%= ENV['VAGRANT_VERSION'] %>-<%= SecureRandom.uuid %>"
38
+ <% end %>
39
+
40
+ <% if config[:communicator] %>
41
+ c.vm.communicator = "<%= config[:communicator] %>"
42
+ <% end %>
43
+
44
+ <% if config[:guest] %>
45
+ c.vm.guest = "<%= config[:guest] %>"
46
+ <% end %>
47
+
48
+ <% if config[:communicator] %>
49
+ <% if config[:username] %>
50
+ c.<%= config[:communicator] %>.username = "<%= config[:username] %>"
51
+ <% end %>
52
+ <% if config[:password] %>
53
+ c.<%= config[:communicator] %>.password = "<%= config[:password] %>"
54
+ <% end %>
55
+ <% else %>
56
+ <% if config[:username] %>
57
+ c.ssh.username = "<%= config[:username] %>"
58
+ <% end %>
59
+ <% if config[:password] %>
60
+ c.ssh.password = "<%= config[:password] %>"
61
+ <% end %>
62
+ <% end %>
63
+
64
+ <% if config[:ssh_key] %>
65
+ c.ssh.private_key_path = "<%= config[:ssh_key] %>"
66
+ <% end %>
67
+ <% config[:ssh].each do |key, value| %>
68
+ c.ssh.<%= key %> = <%= [true, false].include?(value) ? value : value.inspect %>
69
+ <% end %>
70
+ <% if config[:winrm] %>
71
+ <% config[:winrm].each do |key, value| %>
72
+ c.winrm.<%= key %> = <%= value %>
73
+ <% end %>
74
+ <% end %>
75
+
76
+ <% if config[:boot_timeout] %>
77
+ c.vm.boot_timeout = <%= config[:boot_timeout] %>
78
+ <% end %>
79
+
80
+ <% Array(config[:network]).each do |opts| %>
81
+ c.vm.network(:<%= opts[0] %>, <%= opts[1..-1].join(", ") %>)
82
+ <% end %>
83
+
84
+ c.vm.synced_folder ".", "/vagrant", disabled: true
85
+ <% config[:synced_folders].each do |source, destination, options| %>
86
+ c.vm.synced_folder <%= source.inspect %>, <%= destination.inspect %>, <%= options %>
87
+ <% end %>
88
+
89
+ c.vm.provider :<%= config[:provider] %> do |p|
90
+ <% case config[:provider]
91
+ when "virtualbox", /^vmware_/
92
+ if config[:gui] == true || config[:gui] == false %>
93
+ p.gui = <%= config[:gui] %>
94
+ <% end
95
+ end
96
+
97
+ case config[:provider]
98
+ when "virtualbox", /^vmware_/, "parallels"
99
+ if config[:linked_clone] == true || config[:linked_clone] == false %>
100
+ p.linked_clone = <%= config[:linked_clone] %>
101
+ <% end
102
+ end %>
103
+
104
+ <% config[:customize].each do |key, value| %>
105
+ <% case config[:provider]
106
+ when "libvirt" %>
107
+ <% if key == :storage %>
108
+ <% if value.is_a? String %>
109
+ p.storage <%= value %>
110
+ <% elsif value.is_a? Array %>
111
+ <% value.each do |v| %>
112
+ p.storage <%= v %>
113
+ <% end %>
114
+ <% end %>
115
+ <% else %>
116
+ <% if value.is_a? String %>
117
+ p.<%= key %> = "<%= value%>"
118
+ <% else %>
119
+ p.<%= key %> = <%= value%>
120
+ <% end %>
121
+ <% end %>
122
+ <% when "lxc" %>
123
+ <% if key == :container_name %>
124
+ p.container_name = <%= value == ":machine" ? value : "\"#{value}\"" %>
125
+ <% elsif key == :backingstore %>
126
+ p.backingstore = "<%= value %>"
127
+ <% elsif key == :backingstore_options %>
128
+ <% config[:customize][:backingstore_options].each do |opt, opt_val| %>
129
+ p.backingstore_option "--<%= opt %>", "<%= opt_val %>"
130
+ <% end %>
131
+ <% elsif key == :include %>
132
+ <% Array(value).each do |include| %>
133
+ p.customize "<%= key %>", "<%= include %>"
134
+ <% end %>
135
+ <% else %>
136
+ p.customize "<%= key %>", "<%= value %>"
137
+ <% end %>
138
+ <% when "managed" %>
139
+ <% if key == :server %>
140
+ p.server = "<%= value %>"
141
+ <% end %>
142
+ <% when "parallels" %>
143
+ <% if key == :memory || key == :cpus %>
144
+ p.<%= key %> = <%= value %>
145
+ <% else %>
146
+ p.customize ["set", :id, "--<%= key.to_s.gsub('_', '-') %>", "<%= value %>"]
147
+ <% end %>
148
+ <% when "softlayer" %>
149
+ <% if key == :disk_capacity %>
150
+ p.<%= key %> = <%= value %>
151
+ <% else %>
152
+ p.<%= key %> = "<%= value %>"
153
+ <% end %>
154
+ <% when "virtualbox" %>
155
+ <% if key == :createhd %>
156
+ p.customize ["createhd", "--filename", "<%= value[:filename] %>", "--size", <%= value[:size] %>]
157
+ <% elsif key == :storageattach %>
158
+ <% options = [] %>
159
+ <% value.each do |storageattach_option_key, storageattach_option_value|
160
+ options << "\"--#{storageattach_option_key}\""
161
+ if storageattach_option_value.instance_of? Fixnum
162
+ options << storageattach_option_value
163
+ else
164
+ options << "\"#{storageattach_option_value}\""
165
+ end
166
+ end %>
167
+ p.customize ["storageattach", :id, <%= options.join(', ') %>]
168
+ <% elsif key == :cpuidset %>
169
+ <% ids = [] %>
170
+ <% value.each do | id |
171
+ ids << "\"#{id}\""
172
+ end %>
173
+ p.customize ["modifyvm", :id, "--cpuidset", <%= ids.join(', ') %>]
174
+ <% else %>
175
+ p.customize ["modifyvm", :id, "--<%= key %>", "<%= value %>"]
176
+ <% end %>
177
+ <% when /^vmware_/ %>
178
+ <% if key == :memory %>
179
+ <% unless config[:customize].include?(:memsize) %>
180
+ p.vmx["memsize"] = "<%= value %>"
181
+ <% end %>
182
+ <% elsif key == :cpus %>
183
+ <% unless config[:customize].include?(:numvcpus) %>
184
+ p.vmx["numvcpus"] = "<%= value %>"
185
+ <% end %>
186
+ <% else %>
187
+ p.vmx["<%= key %>"] = "<%= value %>"
188
+ <% end %>
189
+ <% when "openstack", "cloudstack", "hyperv", "ovirt3", "ovirt4", "rackspace", "aws" %>
190
+ <% if value.is_a? String %>
191
+ p.<%= key %> = "<%= value%>"
192
+ <% else %>
193
+ p.<%= key %> = <%= value%>
194
+ <% end %>
195
+ <% end %>
196
+ <% end %>
197
+ end
198
+
199
+ end