Class: ChefWorkflow::VM::VagrantProvisioner
- Inherits:
-
Object
- Object
- ChefWorkflow::VM::VagrantProvisioner
- Defined in:
- lib/chef-workflow/support/vm/vagrant.rb
Overview
Provisions a server group with vagrant and virtualbox.
All vagrant machines share the same IP address on eth0, which is typically 10.0.2.15. To compensate for that, a host-only network address will be auto-generated for each server in the group and lives on eth1. It is strongly recommended that you deal with this problem in your chef cookbooks, as node will typically be wrong and we cannot compensate for it.
Groups provisioned in this manner are done so with Vagrant::Prison.
Instance Attribute Summary collapse
-
#name ⇒ Object
name of server group.
-
#number_of_servers ⇒ Object
readonly
number of servers to provision.
-
#prison ⇒ Object
readonly
Vagrant::Prison object.
Instance Method Summary collapse
-
#bootstrap_vagrant_ipsupport ⇒ Object
helper to bootstrap vagrant requirements.
-
#initialize(name, number_of_servers) ⇒ VagrantProvisioner
constructor
Constructor.
-
#ips ⇒ Object
Get the ips associated with this server group.
- #report ⇒ Object
-
#shutdown ⇒ Object
Deprovisions the servers for this group, and cleans up the prison and allocated IP addresses.
-
#startup(*args) ⇒ Object
Provision a group of servers.
-
#ui_class ⇒ Object
Get the appropriate Vagrant UI class, depending on debugging settings.
Constructor Details
#initialize(name, number_of_servers) ⇒ VagrantProvisioner
Constructor. Expects a server group name and a number of servers to provision.
31 32 33 34 35 36 |
# File 'lib/chef-workflow/support/vm/vagrant.rb', line 31 def initialize(name, number_of_servers) @db = ChefWorkflow::DatabaseSupport::Object.new("vm_prisons") @name = name @number_of_servers = number_of_servers @prison = @db[name] end |
Instance Attribute Details
#name ⇒ Object
name of server group
26 27 28 |
# File 'lib/chef-workflow/support/vm/vagrant.rb', line 26 def name @name end |
#number_of_servers ⇒ Object (readonly)
number of servers to provision
24 25 26 |
# File 'lib/chef-workflow/support/vm/vagrant.rb', line 24 def number_of_servers @number_of_servers end |
#prison ⇒ Object (readonly)
Vagrant::Prison object
22 23 24 |
# File 'lib/chef-workflow/support/vm/vagrant.rb', line 22 def prison @prison end |
Instance Method Details
#bootstrap_vagrant_ipsupport ⇒ Object
helper to bootstrap vagrant requirements.
55 56 57 |
# File 'lib/chef-workflow/support/vm/vagrant.rb', line 55 def bootstrap_vagrant_ipsupport ChefWorkflow::IPSupport.seed_vagrant_ips end |
#ips ⇒ Object
Get the ips associated with this server group.
41 42 43 |
# File 'lib/chef-workflow/support/vm/vagrant.rb', line 41 def ips ChefWorkflow::IPSupport.get_role_ips(name) end |
#report ⇒ Object
111 112 113 |
# File 'lib/chef-workflow/support/vm/vagrant.rb', line 111 def report ["#{@number_of_servers} servers; prison dir: #{@prison.dir}"] end |
#shutdown ⇒ Object
Deprovisions the servers for this group, and cleans up the prison and allocated IP addresses.
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/chef-workflow/support/vm/vagrant.rb', line 99 def shutdown @prison ||= @db[name] if prison prison.configure_environment(:ui_class => ui_class) prison.cleanup end ChefWorkflow::IPSupport.delete_role(name) @db.delete(name) return true end |
#startup(*args) ⇒ Object
Provision a group of servers. If successful, returns an array of the ips allocated for the group. Ignores incoming arguments.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/chef-workflow/support/vm/vagrant.rb', line 63 def startup(*args) bootstrap_vagrant_ipsupport ChefWorkflow::IPSupport.delete_role(name) @prison = Vagrant::Prison.new(Dir.mktmpdir, false) prison.name = name prison.configure do |config| config.vm.box_url = ChefWorkflow::VagrantSupport.box_url config.vm.box = ChefWorkflow::VagrantSupport.box if customizations = ChefWorkflow::VagrantSupport.customizations customizations.each { |c| config.vm.customize c } end number_of_servers.times do |x| ip = ChefWorkflow::IPSupport.unused_ip ChefWorkflow::IPSupport.assign_role_ip(name, ip) config.vm.define "#{name}-#{x}" do |this_config| this_config.vm.network :hostonly, ip end end end prison.construct(:ui_class => ui_class) @db[name] = prison # eager save in case start has issues return prison.start ? ips : false ensure @db[name] = prison end |
#ui_class ⇒ Object
Get the appropriate Vagrant UI class, depending on debugging settings.
48 49 50 |
# File 'lib/chef-workflow/support/vm/vagrant.rb', line 48 def ui_class $CHEF_WORKFLOW_DEBUG >= 2 ? Vagrant::UI::Basic : Vagrant::UI::Silent end |