-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
127 lines (111 loc) · 4.28 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
require 'yaml'
config = File.exist?('local-dev-cluster.yaml') ? YAML.load_file('local-dev-cluster.yaml') : YAML.load_file('dev-cluster.yaml')
$cluster_vm_ram = config["cluster"]["node"]["ram"]
$cluster_vm_cpus = config["cluster"]["node"]["cpu"] || 2
num_of_nodes = config["cluster"]["nodeCount"]
$router_ram = config["router"]["ram"]
$router_cpus = config["router"]["cpu"] || 1
router_count = config["router"]["count"] || 1
$bridge_interface = config["networking"] == nil ? nil : config["networking"]["bridgeInterface"]
$host_only = config["networking"] == nil ? false : (config["networking"]["hostOnly"] || false)
$ip = 2 # start with 2 because virtualbox adapter makes 10.10.0.1 reserved for the host
def configure_cpus(vm, cpus)
vm.vm.provider "virtualbox" do |v|
v.cpus = cpus
end
vm.vm.provider :libvirt do |l|
l.cpus = cpus
end
end
def configure_ram(vm, ram)
vm.vm.provider "virtualbox" do |v|
v.memory = ram
end
vm.vm.provider :libvirt do |l|
l.memory = ram
end
end
def configure_private_network(vm, auto_config)
vm.vm.network "private_network",
ip: "10.10.0." + $ip.to_s,
virtualbox__intnet: "clusterNetwork",
:libvirt__dhcp_enabled => false,
:libvirt__forward_mode => 'none',
auto_config: auto_config
$ip = $ip + 1
end
def configure_router(i, config)
config.vm.define "router#{i}" do |router|
router.vm.box = "generic/debian12"
router.vm.provision "shell", reboot: true, inline: "sudo systemctl enable systemd-networkd.service"
lip = $ip.clone
router.vm.provision "shell", reboot: true, path:"dev/router-networking.sh", args: [lip, $host_only.to_s]
if $host_only == false then
if $bridge_interface != nil then
router.vm.network "public_network",
:dev => $bridge_interface
else
router.vm.network "public_network"
end
else
router.vm.network "private_network",
virtualbox__intnet: "outgoing_network",
:libvirt__forward_mode => "nat",
:libvirt__network_name => "outgoing",
:libvirt__host_ip => "10.69.0.1",
:ip => "10.69.0."+ (i+1).to_s,
:libvirt__dhcp_enable => false
router.vm.provision "shell",
run: "always",
inline: "ip r add default via 10.69.0.1"
#NOTE (luisd): i think virtualbox doesnt have this problem
# it mostly applies to wireless configs or you don't want to
# expose the router to your network
end
configure_cpus(router, $router_cpus)
configure_ram(router, $router_ram)
configure_private_network(router, false)
router.vm.provision "shell" do |s|
s.inline = "hostnamectl set-hostname $1"
s.args = ["router"+i.to_s]
end
end
end
def configure_cluster_node(i, config)
config.vm.define "cluster#{i}" do |clustervm|
clustervm.vm.box = "NIAEFEUP/rocky-NInux"
clustervm.vm.box_version = "0.5.1"
lip = $ip.clone
# We enable nested virtualization for vm build tests in vagrant
clustervm.vm.provider "virtualbox" do |vb|
vb.customize ['modifyvm', :id, '--nested-hw-virt', 'on']
end
clustervm.vm.provider :libvirt do |libvirt|
# Enable KVM nested virtualization
libvirt.nested = true
libvirt.cpu_mode = "host-model"
end
clustervm.vm.provision "shell" do |s|
s.path = "dev/node-networking.sh"
s.args = [lip]
end
clustervm.vm.provision "shell" do |s|
s.inline = "hostnamectl set-hostname $1"
s.args = ["cluster"+i.to_s]
end
configure_cpus(clustervm, $cluster_vm_cpus)
configure_ram(clustervm, $cluster_vm_ram)
configure_private_network(clustervm, false)
clustervm.ssh.username = "ni"
clustervm.ssh.private_key_path = "node/bootstrap_key"
end
end
Vagrant.configure("2") do |config|
config.vm.synced_folder '.', '/vagrant', disabled: true
for i in 1..router_count do
configure_router(i, config)
end
for i in 1..num_of_nodes do
configure_cluster_node(i, config)
end
end