-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservers.rb
230 lines (184 loc) · 7.41 KB
/
servers.rb
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# -*- mode: ruby -*-
# vi: set ft=ruby :
ALPINE_BOX = 'generic/alpine319'
$alpine_script = <<~SCRIPT
echo "Adding community repository..."
echo "http://dl-cdn.alpinelinux.org/alpine/v3.8/community" >> /etc/apk/repositories
apk update
echo "Installing lldpd..."
apk add lldpd
echo "Enabling and starting lldpd service..."
rc-update add lldpd
rc-service lldpd start
SCRIPT
def configure_servers(config, _wbd, _offset)
config.vm.define 'exit' do |device|
device.vm.box = ALPINE_BOX
device.vm.hostname = 'exit'
device.vm.provider :libvirt do |v|
v.memory = 1024
v.cpus = 1
v.graphics_passwd = 'password'
end
# link for eth1 --> spine01:swp1
device.vm.network 'private_network', **create_tunnel('exit', 'spine01', generate_mac_address(3, 1), 'eth1')
device.vm.provision :shell, inline: $alpine_script
device.vm.provision :shell, inline: <<-SHELL
echo "Installing iptables..."
apk add iptables
echo "Configuring traffic forwarding and iptables rules..."
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
sysctl -p /etc/sysctl.conf
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables-save > /etc/iptables/rules.v4
echo "Persisting iptables rules on reboot..."
echo "#!/bin/sh" >> /etc/network/if-pre-up.d/iptables
echo "iptables-restore < /etc/iptables/rules.v4" >> /etc/network/if-pre-up.d/iptables
chmod +x /etc/network/if-pre-up.d/iptables
echo "Configuring IP address on eth1..."
ip addr add 10.0.10.1/24 dev eth1
ip link set up eth1
echo "Configuring lldpd..."
echo 'DAEMON_ARGS="-S 2c:60:0c:ad:d5:01 -I eth1 -L db:16:f0:5b:28:80"' > /etc/conf.d/lldpd
SHELL
end
(0..(CONTROL_PLANE_COUNT-1)).each do |control_plane_idx|
machine_base_name = "control-plane-#{control_plane_idx}"
config.vm.define machine_base_name do |device|
device.vm.hostname = machine_base_name
device.vm.boot_timeout = 30
device.vm.synced_folder ".", "/vagrant", disabled: true
device.vm.provider :libvirt do |v|
v.storage :file, size: '10G'
v.memory = 2048
v.cpus = 1
v.graphics_passwd = 'password'
v.boot "hd"
v.boot "network"
end
network_args = create_tunnel(machine_base_name, 'leaf01', generate_mac_address(4, 1), 'eth1')
network_args.merge!(libvirt__network_name: 'data')
device.vm.network 'private_network', **network_args
# hook after up to register the vm with vbmc
device.trigger.after :provision do |trigger|
# register_vbmc_server(machine_base_name)
end
# hook after destroy to remove the vm from vbmc
device.trigger.after :destroy do |trigger|
# This is not to be used, as this is called when the VM is simply shutdown
# With ipmi, this will not allow us to restart it after it is shutdown
# remove_vbmc_server(machine_base_name)
end
end
end
(0..(COMPUTE_COUNT-1)).each do |compute_idx|
machine_base_name = "compute-#{compute_idx}"
config.vm.define machine_base_name do |device|
device.vm.hostname = machine_base_name
device.vm.provider :libvirt do |v|
v.memory = 2048
v.cpus = 1
v.graphics_passwd = 'password'
v.boot "hd"
v.boot "network"
(1..2).each do |nvme_idx|
attach_nvme_disk(v, $vagrant_root + "nvme_disk-#{machine_base_name}-#{nvme_idx}.img", "NVMEworker-#{nvme_idx}")
end
end
(1..2).each do |nvme_idx|
device.trigger.before :up do |trigger|
trigger.ruby do |_env, _machine|
recreate_attached_disk($vagrant_root + "nvme_disk-#{machine_base_name}-#{nvme_idx}.img", 10)
end
end
end
# link for eth1 --> leaf01:swp2
network_args = create_tunnel(machine_base_name, 'leaf01', generate_mac_address(4, 1), 'eth1')
network_args.merge!(libvirt__network_name: 'data')
device.vm.network 'private_network', **network_args
end
end
if CEPH_HOT_COUNT > 0
(0..(CEPH_HOT_COUNT-1)).each do |compute_idx|
machine_base_name = "ceph-hot-#{compute_idx}"
config.vm.define machine_base_name do |device|
device.vm.box = ALPINE_BOX
device.vm.hostname = machine_base_name
device.vm.provider :libvirt do |v|
v.memory = 1024
v.cpus = 1
v.graphics_passwd = 'password'
# Set pxe network NIC as default boot
# boot_network = { 'network' => 'data' }
# v.boot boot_network
# v.boot 'hd'
(1..4).each do |nvme_idx|
attach_nvme_disk(v, $vagrant_root + "nvme_disk-#{machine_base_name}-#{nvme_idx}.img", "NVMEworker-#{nvme_idx}")
end
end
(1..4).each do |nvme_idx|
device.trigger.before :up do |trigger|
trigger.ruby do |_env, _machine|
recreate_attached_disk($vagrant_root + "nvme_disk-#{machine_base_name}-#{nvme_idx}.img", 10)
end
end
end
# link for eth1 --> leaf01:swp2
network_args = create_tunnel(machine_base_name, 'leaf01', generate_mac_address(4, 1), 'eth1')
network_args.merge!(libvirt__network_name: 'data')
device.vm.network 'private_network', **network_args
device.vm.provision :shell, inline: $alpine_script
device.vm.provision :shell, inline: <<-SHELL
echo "Configuring IP address on eth1..."
ip addr add #{next_static_ip(LOCAL_SUBNET_RANGE)} dev eth1
ip link set up eth1
echo "Configuring default route via exit node..."
ip route del default
ip route add default via 10.0.10.1 dev eth1
SHELL
device.vm.provision :shell, inline: <<-SHELL
echo "Configuring lldpd..."
echo 'DAEMON_ARGS="-S 2c:60:0c:ad:d5:02 -I eth1 -L db:16:f0:5b:28:81"' > /etc/conf.d/lldpd
SHELL
end
end
end
if CEPH_WARM_COUNT > 0
(0..(CEPH_WARM_COUNT-1)).each do |compute_idx|
machine_base_name = "ceph-warm-#{compute_idx}"
config.vm.define machine_base_name do |device|
device.vm.box = ALPINE_BOX
device.vm.hostname = machine_base_name
device.vm.provider :libvirt do |v|
v.memory = 1024
v.cpus = 1
v.graphics_passwd = 'password'
# Set pxe network NIC as default boot
# boot_network = { 'network' => 'data' }
# v.boot boot_network
# v.boot 'hd'
(1..4).each do |ssd_idx|
v.storage :file, size: '10G'
end
end
# link for eth1 --> leaf01:swp2
network_args = create_tunnel(machine_base_name, 'leaf01', generate_mac_address(4, 1), 'eth1')
network_args.merge!(libvirt__network_name: 'data')
device.vm.network 'private_network', **network_args
device.vm.provision :shell, inline: $alpine_script
device.vm.provision :shell, inline: <<-SHELL
echo "Configuring IP address on eth1..."
ip addr add #{next_static_ip(LOCAL_SUBNET_RANGE)} dev eth1
ip link set up eth1
echo "Configuring default route via exit node..."
ip route del default
ip route add default via 10.0.10.1 dev eth1
SHELL
device.vm.provision :shell, inline: <<-SHELL
echo "Configuring lldpd..."
echo 'DAEMON_ARGS="-S 2c:60:0c:ad:d5:02 -I eth1 -L db:16:f0:5b:28:81"' > /etc/conf.d/lldpd
SHELL
end
end
end
end