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.
-
#disk_image_format ⇒ Object
Returns the value of attribute disk_image_format.
-
#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_folder_gid ⇒ Object
- #shared_folder_uid ⇒ Object
-
#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
-
#provisioner=(_value) ⇒ Object
This shows an error message to smooth the transition for the backwards incompatible provisioner syntax change introduced in Vagrant 0.7.0.
- #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.
27 28 29 30 31 32 |
# File 'lib/vagrant/config/vm.rb', line 27 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 |
#disk_image_format ⇒ Object
Returns the value of attribute disk_image_format.
22 23 24 |
# File 'lib/vagrant/config/vm.rb', line 22 def disk_image_format @disk_image_format 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_folder_gid ⇒ Object
80 81 82 |
# File 'lib/vagrant/config/vm.rb', line 80 def shared_folder_gid @shared_folder_gid || env.config.ssh.username end |
#shared_folder_uid ⇒ Object
76 77 78 |
# File 'lib/vagrant/config/vm.rb', line 76 def shared_folder_uid @shared_folder_uid || env.config.ssh.username 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.
25 26 27 |
# File 'lib/vagrant/config/vm.rb', line 25 def system @system end |
Instance Method Details
#customize(&block) ⇒ Object
84 85 86 |
# File 'lib/vagrant/config/vm.rb', line 84 def customize(&block) push_proc(&block) end |
#define(name, options = nil, &block) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/vagrant/config/vm.rb', line 102 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.
98 99 100 |
# File 'lib/vagrant/config/vm.rb', line 98 def defined_vm_keys @defined_vm_keys ||= [] end |
#defined_vms ⇒ Object
92 93 94 |
# File 'lib/vagrant/config/vm.rb', line 92 def defined_vms @defined_vms ||= {} end |
#forward_port(name, guestport, hostport, options = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vagrant/config/vm.rb', line 34 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
88 89 90 |
# File 'lib/vagrant/config/vm.rb', line 88 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 |
#provisioner=(_value) ⇒ Object
This shows an error message to smooth the transition for the backwards incompatible provisioner syntax change introduced in Vagrant 0.7.0.
72 73 74 |
# File 'lib/vagrant/config/vm.rb', line 72 def provisioner=(_value) raise Errors::VagrantError, :_key => :provisioner_equals_not_supported end |
#share_folder(name, guestpath, hostpath, opts = nil) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/vagrant/config/vm.rb', line 46 def share_folder(name, guestpath, hostpath, opts=nil) @shared_folders[name] = { :guestpath => guestpath, :hostpath => hostpath }.merge(opts || {}) end |
#validate(errors) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/vagrant/config/vm.rb', line 116 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 end # Each provisioner can validate itself provisioners.each do |prov| prov.validate(errors) end end |