Permalink
219 lines (198 sloc) 6.49 KB
<% config[:vagrantfiles].each do |vagrantfile| %>
require "<%= vagrantfile %>"
<% end %>
Vagrant.configure("2") do |c|
c.berkshelf.enabled = false if Vagrant.has_plugin?("vagrant-berkshelf")
<% if config[:cachier] %>
if Vagrant.has_plugin?("vagrant-cachier")
c.cache.scope = <%= [':box', ':machine'].include?(config[:cachier]) ? config[:cachier] : ':box' %>
end
<% end %>
c.vm.box = "<%= config[:box] %>"
<% if config[:box_url] %>
c.vm.box_url = "<%= config[:box_url] %>"
<% end %>
<% if config[:box_version] %>
c.vm.box_version = "<%= config[:box_version] %>"
<% end %>
<% if !config[:box_check_update].nil? %>
c.vm.box_check_update = <%= config[:box_check_update] %>
<% end %>
<% if !config[:box_download_ca_cert].nil? %>
c.vm.box_download_ca_cert = "<%= config[:box_download_ca_cert] %>"
<% end %>
<% if !config[:box_download_insecure].nil? %>
c.vm.box_download_insecure = "<%= config[:box_download_insecure] %>"
<% end %>
<% if config[:vm_hostname] %>
c.vm.hostname = "<%= config[:vm_hostname] %>"
<% end %>
<% if config[:communicator] %>
c.vm.communicator = "<%= config[:communicator] %>"
<% end %>
<% if config[:guest] %>
c.vm.guest = "<%= config[:guest] %>"
<% end %>
<% if config[:communicator] %>
<% if config[:username] %>
c.<%= config[:communicator] %>.username = "<%= config[:username] %>"
<% end %>
<% if config[:password] %>
c.<%= config[:communicator] %>.password = "<%= config[:password] %>"
<% end %>
<% else %>
<% if config[:username] %>
c.ssh.username = "<%= config[:username] %>"
<% end %>
<% if config[:password] %>
c.ssh.password = "<%= config[:password] %>"
<% end %>
<% end %>
<% if config[:ssh_key] %>
c.ssh.private_key_path = "<%= config[:ssh_key] %>"
<% end %>
<% config[:ssh].each do |key, value| %>
c.ssh.<%= key %> = <%= [true, false].include?(value) ? value : value.inspect %>
<% end %>
<% if config[:winrm] %>
<% config[:winrm].each do |key, value| %>
<% if value.is_a? String %>
c.winrm.<%= key %> = "<%= value%>"
<% else %>
c.winrm.<%= key %> = <%= value%>
<% end %>
<% end %>
<% end %>
<% if config[:boot_timeout] %>
c.vm.boot_timeout = <%= config[:boot_timeout] %>
<% end %>
<% Array(config[:network]).each do |opts| %>
c.vm.network(:<%= opts[0] %>, <%= opts[1..-1].join(", ") %>)
<% end %>
c.vm.synced_folder ".", "/vagrant", disabled: true
<% config[:synced_folders].each do |source, destination, options| %>
c.vm.synced_folder <%= source.inspect %>, <%= destination.inspect %>, <%= options %>
<% end %>
c.vm.provider :<%= config[:provider] %> do |p|
<% case config[:provider]
when "virtualbox" %>
p.name = "kitchen-<%= File.basename(config[:kitchen_root]) %>-<%= instance.name %>"
<% end %>
<% case config[:provider]
when "virtualbox", /^vmware_/
if config[:gui] == true || config[:gui] == false %>
p.gui = <%= config[:gui] %>
<% end
end
case config[:provider]
when "virtualbox", /^vmware_/, "parallels"
if config[:linked_clone] == true || config[:linked_clone] == false %>
p.linked_clone = <%= config[:linked_clone] %>
<% end
when "hyperv" %>
p.vmname = "kitchen-<%= File.basename(config[:kitchen_root]) %>-<%= instance.name %>"
<% if config[:linked_clone] == true || config[:linked_clone] == false %>
p.differencing_disk = <%= config[:linked_clone] %>
<% end
end %>
<% config[:customize].each do |key, value| %>
<% case config[:provider]
when "libvirt" %>
<% if key == :storage %>
<% if value.is_a? String %>
p.storage <%= value %>
<% elsif value.is_a? Array %>
<% value.each do |v| %>
p.storage <%= v %>
<% end %>
<% end %>
<% else %>
<% if value.is_a? String %>
p.<%= key %> = "<%= value%>"
<% else %>
p.<%= key %> = <%= value%>
<% end %>
<% end %>
<% when "lxc" %>
<% if key == :container_name %>
p.container_name = <%= value == ":machine" ? value : "\"#{value}\"" %>
<% elsif key == :backingstore %>
p.backingstore = "<%= value %>"
<% elsif key == :backingstore_options %>
<% config[:customize][:backingstore_options].each do |opt, opt_val| %>
p.backingstore_option "--<%= opt %>", "<%= opt_val %>"
<% end %>
<% elsif key == :include %>
<% Array(value).each do |include| %>
p.customize "<%= key %>", "<%= include %>"
<% end %>
<% else %>
p.customize "<%= key %>", "<%= value %>"
<% end %>
<% when "managed" %>
<% if key == :server %>
p.server = "<%= value %>"
<% end %>
<% when "parallels" %>
<% if key == :memory || key == :cpus %>
p.<%= key %> = <%= value %>
<% else %>
p.customize ["set", :id, "--<%= key.to_s.gsub('_', '-') %>", "<%= value %>"]
<% end %>
<% when "softlayer" %>
<% if key == :disk_capacity %>
p.<%= key %> = <%= value %>
<% else %>
p.<%= key %> = "<%= value %>"
<% end %>
<% when "virtualbox" %>
<% if key == :createhd %>
<% value = [value] unless value.instance_of?(Array) %>
<% value.each do |item| %>
p.customize ["createhd", "--filename", "<%= item[:filename] %>", "--size", <%= item[:size] %>]
<% end %>
<% elsif key == :storageattach || key == :storagectl %>
<% value = [value] unless value.instance_of?(Array) %>
<% value.each do |item| %>
<% options = [] %>
<% item.each do |storage_option_key, storage_option_value|
options << "\"--#{storage_option_key}\""
if storage_option_value.instance_of? Fixnum
options << storage_option_value
else
options << "\"#{storage_option_value}\""
end
end %>
p.customize ["<%= key.to_s %>", :id, <%= options.join(', ') %>]
<% end %>
<% elsif key == :cpuidset %>
<% ids = [] %>
<% value.each do | id |
ids << "\"#{id}\""
end %>
p.customize ["modifyvm", :id, "--cpuidset", <%= ids.join(', ') %>]
<% else %>
p.customize ["modifyvm", :id, "--<%= key %>", "<%= value %>"]
<% end %>
<% when /^vmware_/ %>
<% if key == :memory %>
<% unless config[:customize].include?(:memsize) %>
p.vmx["memsize"] = "<%= value %>"
<% end %>
<% elsif key == :cpus %>
<% unless config[:customize].include?(:numvcpus) %>
p.vmx["numvcpus"] = "<%= value %>"
<% end %>
<% else %>
p.vmx["<%= key %>"] = "<%= value %>"
<% end %>
<% else %>
<% if value.is_a? String %>
p.<%= key %> = "<%= value%>"
<% else %>
p.<%= key %> = <%= value%>
<% end %>
<% end %>
<% end %>
end
end