Class: VagrantPlugins::Conductor::Configure
- Inherits:
-
Object
- Object
- VagrantPlugins::Conductor::Configure
- Defined in:
- lib/vagrant/conductor/configure.rb
Overview
This class will configure a vagrant environment.
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
- #configure(args) ⇒ Object
-
#forward_port(guest, host) ⇒ Object
Forwad port from guest/host.
-
#initialize(config) ⇒ Configure
constructor
A new instance of Configure.
-
#set_box(box, version = nil) ⇒ Object
Set the vagrant box and version.
-
#set_forwarded_ports(ports) ⇒ Object
Forward an array or hash of ports.
-
#set_forwarded_ports_from_array(ports) ⇒ Object
set forwarded ports from an array.
-
#set_forwarded_ports_from_hash(ports) ⇒ Object
Set forwarded ports from a hash.
-
#set_hostname(hostname) ⇒ Object
Set the vagrant hostname.
-
#set_private_ip(ip) ⇒ Object
Configure A Private Network IP.
- #set_provider_config(memory, cpus) ⇒ Object
Constructor Details
#initialize(config) ⇒ Configure
Returns a new instance of Configure.
9 10 11 |
# File 'lib/vagrant/conductor/configure.rb', line 9 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
7 8 9 |
# File 'lib/vagrant/conductor/configure.rb', line 7 def config @config end |
Instance Method Details
#configure(args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/vagrant/conductor/configure.rb', line 13 def configure(args) # Configure The Box set_box( args.find?('box', 'bento/ubuntu-14.04'), args.find?('box_version', nil) ) # Set the environments hostname set_hostname(args.find?('hostname', 'conductor')) # Configure A Private Network IP set_private_ip(args.find?('ip', '192.168.10.10')) # Configure A Few VirtualBox Settings set_provider_config( args.find?('memory', '2048'), args.find?('cpus', '1') ) # Configure Port Forwarding set_forwarded_ports(args.find?('forward_ports', [])) end |
#forward_port(guest, host) ⇒ Object
Forwad port from guest/host
91 92 93 |
# File 'lib/vagrant/conductor/configure.rb', line 91 def forward_port(guest, host) @config.vm.network "forwarded_port", guest: guest, host: host end |
#set_box(box, version = nil) ⇒ Object
Set the vagrant box and version
39 40 41 42 43 44 |
# File 'lib/vagrant/conductor/configure.rb', line 39 def set_box(box, version = nil) @config.vm.box = box unless version.nil? @config.vm.box_version = version end end |
#set_forwarded_ports(ports) ⇒ Object
Forward an array or hash of ports
66 67 68 69 70 71 72 |
# File 'lib/vagrant/conductor/configure.rb', line 66 def set_forwarded_ports(ports) if ports.is_a?(Array) set_forwarded_ports_from_array(ports) elsif ports.is_a?(Hash) set_forwarded_ports_from_hash(ports) end end |
#set_forwarded_ports_from_array(ports) ⇒ Object
set forwarded ports from an array
75 76 77 78 79 80 |
# File 'lib/vagrant/conductor/configure.rb', line 75 def set_forwarded_ports_from_array(ports) ports.each { |val| guest, host = val.split(':', 2) forward_port(guest, host) } end |
#set_forwarded_ports_from_hash(ports) ⇒ Object
Set forwarded ports from a hash
83 84 85 86 87 88 |
# File 'lib/vagrant/conductor/configure.rb', line 83 def set_forwarded_ports_from_hash(ports) ports.each do |key, val| guest, host = val.split(':', 2) forward_port(guest, host) end end |
#set_hostname(hostname) ⇒ Object
Set the vagrant hostname
47 48 49 |
# File 'lib/vagrant/conductor/configure.rb', line 47 def set_hostname(hostname) @config.vm.hostname = hostname; end |
#set_private_ip(ip) ⇒ Object
Configure A Private Network IP
52 53 54 |
# File 'lib/vagrant/conductor/configure.rb', line 52 def set_private_ip(ip) @config.vm.network :private_network, ip: ip end |
#set_provider_config(memory, cpus) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/vagrant/conductor/configure.rb', line 56 def set_provider_config(memory, cpus) @config.vm.provider "virtualbox" do |vb| vb.customize ["modifyvm", :id, "--memory", memory] vb.customize ["modifyvm", :id, "--cpus", cpus] vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"] vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] end end |