2012-04-18 05:12:27 +00:00
|
|
|
module VagrantPlugins
|
2012-06-15 01:49:20 +00:00
|
|
|
module Kernel_V1
|
2012-12-23 23:54:52 +00:00
|
|
|
# This is the Version 1.0.x Vagrant VM configuration. This is
|
|
|
|
# _outdated_ and exists purely to be upgraded over to the new V2
|
|
|
|
# format.
|
2012-06-26 23:02:44 +00:00
|
|
|
class VMConfig < Vagrant.plugin("1", :config)
|
2012-06-23 19:48:53 +00:00
|
|
|
DEFAULT_VM_NAME = :default
|
|
|
|
|
2012-04-18 05:12:27 +00:00
|
|
|
attr_accessor :name
|
|
|
|
attr_accessor :auto_port_range
|
|
|
|
attr_accessor :base_mac
|
|
|
|
attr_accessor :boot_mode
|
2012-12-23 23:48:01 +00:00
|
|
|
attr_accessor :box
|
|
|
|
attr_accessor :box_url
|
|
|
|
attr_accessor :guest
|
2012-04-18 05:12:27 +00:00
|
|
|
attr_accessor :host_name
|
2012-12-23 23:48:01 +00:00
|
|
|
attr_reader :customizations
|
2012-04-18 05:12:27 +00:00
|
|
|
attr_reader :networks
|
|
|
|
attr_reader :provisioners
|
2012-12-23 23:48:01 +00:00
|
|
|
attr_reader :shared_folders
|
2012-04-18 05:12:27 +00:00
|
|
|
|
|
|
|
def initialize
|
|
|
|
@shared_folders = {}
|
|
|
|
@networks = []
|
|
|
|
@provisioners = []
|
|
|
|
@customizations = []
|
2012-12-24 00:18:31 +00:00
|
|
|
@define_calls = []
|
2012-04-18 05:12:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def forward_port(guestport, hostport, options=nil)
|
2013-01-22 22:07:27 +00:00
|
|
|
options ||= {}
|
|
|
|
|
2013-01-10 20:06:08 +00:00
|
|
|
# Build up the network options for V2
|
|
|
|
network_options = {}
|
|
|
|
network_options[:virtualbox__adapter] = options[:adapter]
|
|
|
|
network_options[:virtualbox__protocol] = options[:protocol]
|
|
|
|
|
|
|
|
# Just append the forwarded port to the networks
|
2013-01-22 22:28:38 +00:00
|
|
|
@networks << [:forwarded_port, [guestport, hostport, network_options]]
|
2012-04-18 05:12:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def share_folder(name, guestpath, hostpath, opts=nil)
|
|
|
|
@shared_folders[name] = {
|
|
|
|
:guestpath => guestpath.to_s,
|
|
|
|
:hostpath => hostpath.to_s,
|
|
|
|
:create => false,
|
|
|
|
:owner => nil,
|
|
|
|
:group => nil,
|
|
|
|
:nfs => false,
|
|
|
|
:transient => false,
|
|
|
|
:extra => nil
|
|
|
|
}.merge(opts || {})
|
|
|
|
end
|
|
|
|
|
|
|
|
def network(type, *args)
|
2013-01-13 09:07:55 +00:00
|
|
|
if type == :hostonly
|
|
|
|
@networks << [:private_network, args]
|
|
|
|
elsif type == :bridged
|
|
|
|
@networks << [:public_network, args]
|
|
|
|
else
|
|
|
|
@networks << [:unknown, type]
|
|
|
|
end
|
2012-04-18 05:12:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def provision(name, options=nil, &block)
|
2012-12-23 23:54:52 +00:00
|
|
|
@provisioners << [name, options, block]
|
2012-04-18 05:12:27 +00:00
|
|
|
end
|
|
|
|
|
2012-12-23 19:26:32 +00:00
|
|
|
# This argument is nil only because the old style was deprecated and
|
|
|
|
# we didn't want to break Vagrantfiles. This was never removed and
|
|
|
|
# since we've moved onto V2 configuration, we might as well keep this
|
|
|
|
# around forever.
|
2012-04-18 05:12:27 +00:00
|
|
|
def customize(command=nil)
|
|
|
|
@customizations << command if command
|
|
|
|
end
|
|
|
|
|
|
|
|
def define(name, options=nil, &block)
|
2012-12-24 00:18:31 +00:00
|
|
|
@define_calls << [name, options, block]
|
2012-04-18 05:12:27 +00:00
|
|
|
end
|
|
|
|
|
2012-06-23 19:48:53 +00:00
|
|
|
def finalize!
|
|
|
|
# If we haven't defined a single VM, then we need to define a
|
|
|
|
# default VM which just inherits the rest of the configuration.
|
|
|
|
define(DEFAULT_VM_NAME) if defined_vm_keys.empty?
|
|
|
|
end
|
|
|
|
|
2012-11-15 03:59:18 +00:00
|
|
|
# Upgrade to a V2 configuration
|
|
|
|
def upgrade(new)
|
2013-01-11 22:44:27 +00:00
|
|
|
new.vm.base_mac = self.base_mac if self.base_mac
|
|
|
|
new.vm.box = self.box if self.box
|
|
|
|
new.vm.box_url = self.box_url if self.box_url
|
|
|
|
new.vm.guest = self.guest if self.guest
|
|
|
|
new.vm.host_name = self.host_name if self.host_name
|
|
|
|
new.vm.usable_port_range = self.auto_port_range if self.auto_port_range
|
2012-11-15 03:59:18 +00:00
|
|
|
|
2012-12-25 17:00:06 +00:00
|
|
|
if self.boot_mode
|
|
|
|
# Enable the GUI if the boot mode is GUI.
|
|
|
|
new.vm.providers[:virtualbox].config.gui = (self.boot_mode.to_s == "gui")
|
|
|
|
end
|
|
|
|
|
2012-12-23 19:05:22 +00:00
|
|
|
# If we have VM customizations, then we enable them on the
|
|
|
|
# VirtualBox provider on the new VM.
|
2012-12-23 23:48:01 +00:00
|
|
|
self.customizations.each do |customization|
|
|
|
|
new.vm.providers[:virtualbox].config.customize(customization)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Re-define all networks.
|
|
|
|
self.networks.each do |type, args|
|
2013-01-13 09:07:55 +00:00
|
|
|
if type == :unknown
|
|
|
|
# TODO: Warn that we don't know what the heck this is.
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2012-12-23 23:48:01 +00:00
|
|
|
new.vm.network(type, *args)
|
|
|
|
end
|
|
|
|
|
2012-12-23 23:54:52 +00:00
|
|
|
# Provisioners
|
|
|
|
self.provisioners.each do |name, options, block|
|
|
|
|
new.vm.provision(name, options, &block)
|
|
|
|
end
|
2012-12-23 23:48:01 +00:00
|
|
|
|
|
|
|
# Shared folders
|
|
|
|
self.shared_folders.each do |name, sf|
|
|
|
|
options = sf.dup
|
|
|
|
guestpath = options.delete(:guestpath)
|
|
|
|
hostpath = options.delete(:hostpath)
|
|
|
|
|
|
|
|
new.vm.share_folder(name, guestpath, hostpath, options)
|
2012-12-23 19:05:22 +00:00
|
|
|
end
|
|
|
|
|
2012-12-24 00:18:31 +00:00
|
|
|
# Defined sub-VMs
|
|
|
|
@define_calls.each do |name, options, block|
|
|
|
|
new.vm.define(name, options, &block)
|
|
|
|
end
|
|
|
|
|
2013-01-21 03:04:50 +00:00
|
|
|
# If name is used, warn that it has no effect anymore
|
|
|
|
warnings = []
|
|
|
|
if @name
|
|
|
|
warnings << "`config.vm.name` has no effect anymore. Names are derived\n" +
|
|
|
|
"directly from any `config.vm.define` calls."
|
|
|
|
end
|
|
|
|
|
|
|
|
[warnings, []]
|
2012-04-18 05:12:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|