Class: Vagrant::Config::VMConfig
- Includes:
- Util::StackedProcRunner
- Defined in:
- lib/vagrant/config/vm.rb,
lib/vagrant/config/vm/sub_vm.rb,
lib/vagrant/config/vm/provisioner.rb
Defined Under Namespace
Classes: Provisioner, SubVM
Instance Attribute Summary collapse
-
#auto_port_range ⇒ Object
Returns the value of attribute auto_port_range.
-
#base_mac ⇒ Object
Returns the value of attribute base_mac.
-
#boot_mode ⇒ Object
Returns the value of attribute boot_mode.
-
#box ⇒ Object
Returns the value of attribute box.
-
#box_ovf ⇒ Object
Returns the value of attribute box_ovf.
-
#box_url ⇒ Object
Returns the value of attribute box_url.
-
#forwarded_ports ⇒ Object
readonly
Returns the value of attribute forwarded_ports.
-
#host_name ⇒ Object
Returns the value of attribute host_name.
-
#network_options ⇒ Object
readonly
Returns the value of attribute network_options.
-
#provisioners ⇒ Object
readonly
Returns the value of attribute provisioners.
-
#shared_folders ⇒ Object
readonly
Returns the value of attribute shared_folders.
-
#system ⇒ Object
Returns the value of attribute system.
Attributes inherited from Base
Instance Method Summary collapse
- #customize(&block) ⇒ Object
- #define(name, options = nil, &block) ⇒ Object
-
#defined_vm_keys ⇒ Object
This returns the keys of the sub-vms in the order they were defined.
- #defined_vms ⇒ Object
- #forward_port(name, guestport, hostport, options = nil) ⇒ Object
- #has_multi_vms? ⇒ Boolean
-
#initialize ⇒ VMConfig
constructor
A new instance of VMConfig.
- #network(ip, options = nil) ⇒ Object
- #provision(name, options = nil, &block) ⇒ Object
- #share_folder(name, guestpath, hostpath, opts = nil) ⇒ Object
- #validate(errors) ⇒ Object
Methods included from Util::StackedProcRunner
#proc_stack, #push_proc, #run_procs!
Methods inherited from Base
configures, #env, #instance_variables_hash, json_create, #set_options, #to_hash, #to_json
Constructor Details
#initialize ⇒ VMConfig
Returns a new instance of VMConfig.
24 25 26 27 28 29 |
# File 'lib/vagrant/config/vm.rb', line 24 def initialize @forwarded_ports = {} @shared_folders = {} @network_options = [] @provisioners = [] end |
Instance Attribute Details
#auto_port_range ⇒ Object
Returns the value of attribute auto_port_range.
11 12 13 |
# File 'lib/vagrant/config/vm.rb', line 11 def auto_port_range @auto_port_range end |
#base_mac ⇒ Object
Returns the value of attribute base_mac.
15 16 17 |
# File 'lib/vagrant/config/vm.rb', line 15 def base_mac @base_mac end |
#boot_mode ⇒ Object
Returns the value of attribute boot_mode.
16 17 18 |
# File 'lib/vagrant/config/vm.rb', line 16 def boot_mode @boot_mode end |
#box ⇒ Object
Returns the value of attribute box.
12 13 14 |
# File 'lib/vagrant/config/vm.rb', line 12 def box @box end |
#box_ovf ⇒ Object
Returns the value of attribute box_ovf.
14 15 16 |
# File 'lib/vagrant/config/vm.rb', line 14 def box_ovf @box_ovf end |
#box_url ⇒ Object
Returns the value of attribute box_url.
13 14 15 |
# File 'lib/vagrant/config/vm.rb', line 13 def box_url @box_url end |
#forwarded_ports ⇒ Object (readonly)
Returns the value of attribute forwarded_ports.
18 19 20 |
# File 'lib/vagrant/config/vm.rb', line 18 def forwarded_ports @forwarded_ports end |
#host_name ⇒ Object
Returns the value of attribute host_name.
17 18 19 |
# File 'lib/vagrant/config/vm.rb', line 17 def host_name @host_name end |
#network_options ⇒ Object (readonly)
Returns the value of attribute network_options.
20 21 22 |
# File 'lib/vagrant/config/vm.rb', line 20 def @network_options end |
#provisioners ⇒ Object (readonly)
Returns the value of attribute provisioners.
21 22 23 |
# File 'lib/vagrant/config/vm.rb', line 21 def provisioners @provisioners end |
#shared_folders ⇒ Object (readonly)
Returns the value of attribute shared_folders.
19 20 21 |
# File 'lib/vagrant/config/vm.rb', line 19 def shared_folders @shared_folders end |
#system ⇒ Object
Returns the value of attribute system.
22 23 24 |
# File 'lib/vagrant/config/vm.rb', line 22 def system @system end |
Instance Method Details
#customize(&block) ⇒ Object
69 70 71 |
# File 'lib/vagrant/config/vm.rb', line 69 def customize(&block) push_proc(&block) end |
#define(name, options = nil, &block) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/vagrant/config/vm.rb', line 87 def define(name, =nil, &block) name = name.to_sym ||= {} # Add the name to the array of VM keys. This array is used to # preserve the order in which VMs are defined. defined_vm_keys << name # Add the SubVM to the hash of defined VMs defined_vms[name] ||= SubVM.new defined_vms[name]..merge!() defined_vms[name].push_proc(&block) end |
#defined_vm_keys ⇒ Object
This returns the keys of the sub-vms in the order they were defined.
83 84 85 |
# File 'lib/vagrant/config/vm.rb', line 83 def defined_vm_keys @defined_vm_keys ||= [] end |
#defined_vms ⇒ Object
77 78 79 |
# File 'lib/vagrant/config/vm.rb', line 77 def defined_vms @defined_vms ||= {} end |
#forward_port(name, guestport, hostport, options = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vagrant/config/vm.rb', line 31 def forward_port(name, guestport, hostport, =nil) = { :guestport => guestport, :hostport => hostport, :protocol => :tcp, :adapter => 0, :auto => false }.merge( || {}) forwarded_ports[name] = end |
#has_multi_vms? ⇒ Boolean
73 74 75 |
# File 'lib/vagrant/config/vm.rb', line 73 def has_multi_vms? !defined_vms.empty? end |
#network(ip, options = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/vagrant/config/vm.rb', line 53 def network(ip, =nil) = { :ip => ip, :netmask => "255.255.255.0", :adapter => 1, :mac => nil, :name => nil }.merge( || {}) @network_options[[:adapter]] = end |
#provision(name, options = nil, &block) ⇒ Object
65 66 67 |
# File 'lib/vagrant/config/vm.rb', line 65 def provision(name, =nil, &block) @provisioners << Provisioner.new(top, name, , &block) end |
#share_folder(name, guestpath, hostpath, opts = nil) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/vagrant/config/vm.rb', line 43 def share_folder(name, guestpath, hostpath, opts=nil) @shared_folders[name] = { :guestpath => guestpath, :hostpath => hostpath, :owner => nil, :group => nil, :nfs => false }.merge(opts || {}) end |
#validate(errors) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/vagrant/config/vm.rb', line 101 def validate(errors) errors.add(I18n.t("vagrant.config.vm.box_missing")) if !box errors.add(I18n.t("vagrant.config.vm.box_not_found", :name => box)) if box && !box_url && !env.box errors.add(I18n.t("vagrant.config.vm.boot_mode_invalid")) if ![:vrdp, :gui].include?(boot_mode.to_sym) errors.add(I18n.t("vagrant.config.vm.base_mac_invalid")) if env.box && !base_mac shared_folders.each do |name, | if !File.directory?(File.([:hostpath].to_s, env.root_path)) errors.add(I18n.t("vagrant.config.vm.shared_folder_hostpath_missing", :name => name, :path => [:hostpath])) end if [:nfs] && ([:owner] || [:group]) # Owner/group don't work with NFS errors.add(I18n.t("vagrant.config.vm.shared_folder_nfs_owner_group", :name => name)) end end # Validate some basic networking .each do || next if ! ip = [:ip].split(".") if ip.length != 4 errors.add(I18n.t("vagrant.config.vm.network_ip_invalid", :ip => [:ip])) elsif ip.last == "1" errors.add(I18n.t("vagrant.config.vm.network_ip_ends_one", :ip => [:ip])) end end # Each provisioner can validate itself provisioners.each do |prov| # TODO: Remove at some point if prov.shortcut == :chef_server errors.add(I18n.t("vagrant.config.vm.provisioner_chef_server_changed")) else prov.validate(errors) end end end |