This repository was archived by the owner on Mar 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVagrantfile
More file actions
224 lines (175 loc) · 7.63 KB
/
Vagrantfile
File metadata and controls
224 lines (175 loc) · 7.63 KB
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
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'pp'
DEBIAN_BOX = "boxomatic/debian-13"
COMMON_MESSAGE = "To setup Wiedii (if not done already):
vagrant ssh <wiedii OR wiedii_downstr>
sudo -i
bash -c \"$(wget -O - https://raw.githubusercontent.com/vemarsas/wiedii-bootstrap/main/bootstrap.sh)\"
# OR directly run
bash /vagrant/bootstrap.sh
# which you can edit locally (and commit/push from the host).
"
ENABLE_PASSWD = <<-END
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
systemctl restart sshd.service
END
WIEDII_RAM_MB = 1024
# Ex. allow_promisc wiedii, [2, 3, 4], :allow_vms
# (NIC ID=1 is generally the default/NAT interface)
# The third arg may also be :allow_all or :deny
def allow_promisc(vmcfg, nicids, allow=:allow_vms)
vmcfg.vm.provider "virtualbox" do |vb|
nicids.each do |i|
vb.customize ["modifyvm", :id, "--nicpromisc#{i}", allow.to_s.gsub('_', '-')]
end
end
end
# Some gems with C/C++ extensions crash at compile time if the system has just
# the default amount of 512 MB. RAM >= 1GB is recommended.
def assign_ram(vmcfg, megabytes)
vmcfg.vm.provider "virtualbox" do |vb|
vb.memory = megabytes
end
end
=begin
TOPOLOGY
default/NAT
|
(eth0)
-------- -----
| CLIENT |---default(vlan1?)_access---(eth1)| WIEDII |(eth3)---vlan2_access
-------- -----
(eth2)
|
vlan_trunk (vlans 1, 2)
|
(eth1)
-------------
default/NAT---(eth0)| WIEDII_DOWNSTR |
-------------
(eth2) (eth3)
| |
downstr_vlan_1_access downstr_vlan_2_access
Of course, VLAN IDs 1, 2 are purely conventional/examples: they are not enforced in this Vagrantfile.
A simpler topology with no VLANs will be just WIEDII and CLIENT (e.g. to test Raidus/Chilli and no 802.1Q involved).
That was indeed the original design.
=end
Vagrant.configure("2") do |config|
config.vm.define "wiedii", primary: true do |wiedii|
wiedii.vm.box = DEBIAN_BOX
assign_ram wiedii, WIEDII_RAM_MB
wiedii.vm.hostname = "wiedii"
# wiedii.vm.synced_folder ".", "/vagrant", disabled: true
wiedii.vm.network "forwarded_port", guest: 22, host: 2222
wiedii.vm.network "forwarded_port", guest: 4567, host: 4567
wiedii.vm.network "forwarded_port", guest: 443, host: 4443
# NIC #1 is the default NAT interface, with forwarded ports above
# NIC #2
wiedii.vm.network "private_network", # may also be used as vlan 1 access
auto_config: false, # or will reset what wiedii-persist has configured on the interface
virtualbox__intnet: "default_access"
# NIC #3
wiedii.vm.network "private_network",
auto_config: false, # or will reset what wiedii-persist has configured on the interface
virtualbox__intnet: "vlan_trunk"
# NIC #4
wiedii.vm.network "private_network",
auto_config: false, # or will reset what wiedii-persist has configured on the interface
virtualbox__intnet: "vlan2_access"
# If we ever want bridges to work...
allow_promisc wiedii, [2, 3, 4], :allow_vms
wiedii.vm.provision "shell", inline: ENABLE_PASSWD
wiedii.vm.post_up_message = [
COMMON_MESSAGE,
'After Wiedii setup:',
'SSH: port 2222 @localhost, user: "wiedii", password: "wiedii"',
'Wiedii web: http://localhost:4567 or https://localhost:4443'
].join("\n")
end
config.vm.define "wiedii_downstr", autostart: false do |wiedii_downstr| # downstream switch, currently a wiedii, could be an Arista, Cisco, etc.
wiedii_downstr.vm.box = DEBIAN_BOX
assign_ram wiedii_downstr, WIEDII_RAM_MB
wiedii_downstr.vm.hostname = "wiedii-downstr"
# wiedii_downstr.vm.synced_folder ".", "/vagrant", disabled: true
wiedii_downstr.vm.network "forwarded_port", guest: 22, host: 2223
wiedii_downstr.vm.network "forwarded_port", guest: 4567, host: 4568
wiedii_downstr.vm.network "forwarded_port", guest: 443, host: 4444
# NIC #1 is the default NAT interface, with forwarded ports above
# NIC #2
wiedii_downstr.vm.network "private_network",
auto_config: false, # or will reset what wiedii-persist has configured on the interface
virtualbox__intnet: "vlan_trunk"
# NIC #3
wiedii_downstr.vm.network "private_network",
auto_config: false, # or will reset what wiedii-persist has configured on the interface
virtualbox__intnet: "downstr_vlan_1_access"
# NIC #4
wiedii_downstr.vm.network "private_network",
auto_config: false, # or will reset what wiedii-persist has configured on the interface
virtualbox__intnet: "downstr_vlan_2_access"
allow_promisc wiedii_downstr, [2, 3, 4], :allow_vms
wiedii_downstr.vm.provision "shell", inline: ENABLE_PASSWD
wiedii_downstr.vm.post_up_message = [
COMMON_MESSAGE,
'After Wiedii setup:',
'SSH: port 2223 @localhost, user: "wiedii", password: "wiedii"',
'Wiedii web: http://localhost:4568 or https://localhost:4444'
].join("\n")
end
# The client machine may be any OS, but for economy of storage and download time,
# it's based on the same base box.
config.vm.define "client", autostart: false do |wiediic|
wiediic.vm.box = DEBIAN_BOX
wiediic.vm.hostname = "wiediiclient"
wiediic.vm.network "private_network",
auto_config: false,
# Vagrant auto_config would otherwise mess things up here,
# modifying /etc/network/interfaces so to remove the default gw from
# wiedii (ordinary DHCP or chillispot).
virtualbox__intnet: "default_access"
wiediic.vm.provider "virtualbox" do |vb|
vb.gui = true
# https://stackoverflow.com/a/24253435
vb.customize ["modifyvm", :id, "--vram", "16"]
end
wiediic.vm.provision "shell", inline: <<-EOF
# restore default VBox NAT interface networking (if it has been disabled previously to use wiedii-connected interface eth1)
ip link set up dev eth0
# ASSUME dhclient is the dhcp client
if (ps aux | grep dhclient | grep eth0 | grep -v grep); then
if (ip route | grep default | grep -v grep); then
ip route replace default via 10.0.2.2 dev eth0
else
ip route add default via 10.0.2.2 dev eth0
fi
else
dhclient eth0
fi
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -y upgrade
apt-get install -y lightdm openbox lxterminal psmisc firefox-esr
systemctl start lightdm
# Remove default Internet connection, it will use the second interface behind
# wiedii (now that provisioning is done and software downloaded).
cat > /etc/network/interfaces <<EOFF
# Auto-generated by a custom Vagrant provisioner for wiedii client.
# source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# Default VBox NAT
auto eth0
iface eth0 inet dhcp
pre-up sleep 2
post-up ip route del default dev \\$IFACE || true
# Interface connected to Wiedii
auto eth1
iface eth1 inet dhcp
EOFF
systemctl restart networking
echo "vagrant:vagrant" | chpasswd
EOF
end
end