-
Notifications
You must be signed in to change notification settings - Fork 2
/
Vagrantfile
69 lines (63 loc) · 3.01 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
BOX_IMAGE = "bento/ubuntu-20.04"
SERVER_COUNT = 2
LPS_PATH = "lps.vdi"
HPS_PATH = "hps.vdi"
PROVISIONED_FLAG = ".provisioned"
Vagrant.configure("2") do |config|
# triggers to create and delete a file indicating that the machines have been provisioned
config.trigger.after :up do |trigger|
trigger.only_on = "server#{SERVER_COUNT}"
trigger.ruby do |env,machine|
unless File.exist?(PROVISIONED_FLAG)
File.open(PROVISIONED_FLAG, "w") {}
end
end
end
config.trigger.after :destroy do |trigger|
trigger.only_on = "controller"
trigger.ruby do |env,machine|
if File.exist?(PROVISIONED_FLAG)
File.delete(PROVISIONED_FLAG)
end
end
end
# define the controller
config.vm.define "controller" do |subconfig|
subconfig.vm.box = BOX_IMAGE
subconfig.vm.hostname = "controller"
subconfig.vm.network :private_network, ip: "10.0.0.10"
subconfig.vm.provider "virtualbox" do |vb|
vb.cpus = 1
vb.memory = 1024
unless File.exist?(PROVISIONED_FLAG)
vb.customize ['createhd', '--filename', LPS_PATH, '--size', 5 * 1024, '--variant', 'Fixed']
vb.customize ['modifymedium', 'disk', LPS_PATH, '--type', 'shareable']
vb.customize ['createhd', '--filename', HPS_PATH, '--size', 5 * 1024, '--variant', 'Fixed']
vb.customize ['modifymedium', 'disk', HPS_PATH, '--type', 'shareable']
vb.customize ['bandwidthctl', :id, 'add', 'Slow', '--type', 'disk', '--limit', '12M']
vb.customize ['bandwidthctl', :id, 'add', 'Fast', '--type', 'disk', '--limit', '192M']
end
vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--mtype', 'shareable', '--medium', LPS_PATH, '--bandwidthgroup', "Slow"]
vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 2, '--device', 0, '--type', 'hdd', '--mtype', 'shareable', '--medium', HPS_PATH, '--bandwidthgroup', "Fast"]
end
end
# define the servers
(1..SERVER_COUNT).each do |i|
config.vm.define "server#{i}" do |subconfig|
subconfig.vm.box = BOX_IMAGE
subconfig.vm.hostname = "server#{i}"
subconfig.vm.network :private_network, ip: "10.0.0.#{10 + i}"
subconfig.vm.provider "virtualbox" do |vb|
vb.cpus = 1
vb.memory = 1024
unless File.exist?(PROVISIONED_FLAG)
vb.customize ['bandwidthctl', :id, 'add', 'Slow', '--type', 'disk', '--limit', '12M']
vb.customize ['bandwidthctl', :id, 'add', 'Fast', '--type', 'disk', '--limit', '192M']
end
vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--mtype', 'shareable', '--medium', LPS_PATH, '--bandwidthgroup', "Slow"]
vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 2, '--device', 0, '--type', 'hdd', '--mtype', 'shareable', '--medium', HPS_PATH, '--bandwidthgroup', "Fast"]
end
end
end
config.vm.provision "shell", path: "bootstrap.sh"
end