forked from bloomberg/chef-bach
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
138 lines (117 loc) · 4.64 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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
94
95
96
97
98
99
100
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
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# This is a Vagrantfile to automatically provision a bootstrap node
# with a Chef server.
#
# See http://www.vagrantup.com/ for info on Vagrant.
#
require 'json'
require 'ipaddr'
prefix = File.basename(File.expand_path('.')) == 'vbox' ? '../' : ''
require_relative "#{prefix}lib/cluster_data"
require_relative "#{prefix}lib/hypervisor_node"
include BACH::ClusterData
include BACH::ClusterData::HypervisorNode
#
# You can override parts of the vagrant config by creating a
# 'Vagrantfile.local.rb'
#
# (You may find this useful for SSL certificate injection.)
#
local_file =
if File.basename(File.expand_path('.')) == 'vbox'
File.expand_path('../Vagrantfile.local.rb')
else
"#{__FILE__}.local.rb"
end
if File.exist?(local_file)
if ENV['BACH_DEBUG']
$stderr.puts "Found #{local_file}, including"
end
require local_file
end
#
# Since we run vagrant commands from ~/chef-bcpc and from
# ~/chef-bcpc/vbox directory, finding correct location for environment
# file is important.
#
if ENV['BACH_DEBUG']
$stderr.puts "Base directory is : #{repo_dir}"
end
chef_env = JSON.parse(File.read(chef_environment_path))
cluster_environment = chef_env['name']
bootstrap_hostname =
chef_env['override_attributes']['bcpc']['bootstrap']['hostname']
bootstrap_domain =
chef_env['override_attributes']['bcpc']['domain_name'] || 'bcpc.example.com'
# Management IP, Float IP, Storage IP
rack = chef_env['override_attributes']['bcpc']['networks'].keys.first
network_json = chef_env['override_attributes']['bcpc']['networks'][rack]
management_net =
IPAddr.new(network_json['management']['cidr'] || '10.0.100.0/24')
float_net =
IPAddr.new(network_json['floating']['cidr'] || '192.168.100.0/24')
storage_net =
IPAddr.new(network_json['storage']['cidr'] || '172.16.100.0/24')
# We rely on global variables to deal with Vagrantfile scoping rules.
# rubocop:disable Style/GlobalVars
$bach_local_environment = cluster_environment
$bach_local_mirror = nil
Vagrant.configure('2') do |config|
config.vm.define bootstrap_hostname.to_sym do |bootstrap|
bootstrap.vm.hostname = "#{bootstrap_hostname}.#{bootstrap_domain}"
# Awaiting https://github.com/ruby/ruby/pull/1269 to properly retrieve mask
mgmt_mask = IPAddr.new(management_net.instance_variable_get('@mask_addr'),
Socket::AF_INET).to_s
storage_mask = IPAddr.new(storage_net.instance_variable_get('@mask_addr'),
Socket::AF_INET).to_s
float_mask = IPAddr.new(float_net.instance_variable_get('@mask_addr'),
Socket::AF_INET).to_s
bootstrap.vm.network(:private_network,
ip: management_net.succ.succ.succ.to_s,
netmask: mgmt_mask,
adapter_ip: management_net.succ.succ.to_s,
type: :static)
bootstrap.vm.network(:private_network,
ip: storage_net.succ.succ.succ.to_s,
netmask: storage_mask,
adapter_ip: storage_net.succ.succ.to_s,
type: :static)
bootstrap.vm.network(:private_network,
ip: float_net.succ.succ.succ.to_s,
netmask: float_mask,
adapter_ip: float_net.succ.succ.to_s,
type: :static)
if File.basename(File.expand_path('.')) == 'vbox'
bootstrap.vm.synced_folder '../', '/chef-bcpc-host'
else
bootstrap.vm.synced_folder './', '/chef-bcpc-host'
end
# set up repositories
if $bach_local_mirror
bootstrap.vm.provision :shell, inline: <<-EOH
sed -i s/archive.ubuntu.com/#{$bach_local_mirror}/g /etc/apt/sources.list
sed -i s/security.ubuntu.com/#{$bach_local_mirror}/g /etc/apt/sources.list
sed -i s/^deb-src/\#deb-src/g /etc/apt/sources.list
EOH
end
end
config.vm.box = 'trusty64'
config.vm.box_url = 'trusty-server-cloudimg-amd64-vagrant-disk1.box'
memory = ENV['BOOTSTRAP_VM_MEM'] || '2048'
cpus = ENV['BOOTSTRAP_VM_CPUs'] || '1'
config.vm.provider :virtualbox do |vb|
# Don't boot with headless mode
vb.gui = false
vb.name = bootstrap_hostname.to_s
vb.customize ['modifyvm', :id, '--nictype2', '82543GC']
vb.customize ['modifyvm', :id, '--memory', memory]
vb.customize ['modifyvm', :id, '--cpus', cpus]
vb.customize ['modifyvm', :id, '--largepages', 'on']
vb.customize ['modifyvm', :id, '--nestedpaging', 'on']
vb.customize ['modifyvm', :id, '--vtxvpid', 'on']
vb.customize ['modifyvm', :id, '--hwvirtex', 'on']
vb.customize ['modifyvm', :id, '--ioapic', 'on']
end
end