-
Notifications
You must be signed in to change notification settings - Fork 1
/
vagrantfile
93 lines (76 loc) · 4.22 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
os = "bento/ubuntu-18.04"
net_ip = "192.168.50"
[
["iot-edge-key1", "#{net_ip}.21", "512", os , "configure_iotedge_symkey.py"],
["iot-edge-key2", "#{net_ip}.22", "512", os , "configure_iotedge_symkey.py"],
["iot-edge-cert1", "#{net_ip}.31", "512", os , "configure_iotedge_cert.py"],
["iot-edge-cert2", "#{net_ip}.32", "512", os , "configure_iotedge_cert.py"],
["iot-edge-tpm1", "#{net_ip}.41", "512", os , "configure_iotedge_tpm.py"],
["iot-edge-tpm2", "#{net_ip}.42", "512", os , "configure_iotedge_tpm.py"],
].each do |vmname,ip,mem,os,registerscript|
config.vm.define "#{vmname}" do |edge_vm|
edge_vm.vm.provider "virtualbox" do |vb|
vb.linked_clone = true
vb.memory = "#{mem}"
vb.cpus = 1
vb.name = "#{vmname}"
#fix ubuntu network issue https://stackoverflow.com/questions/18457306/how-to-enable-internet-access-inside-vagrant
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb.customize ["modifyvm", :id, "--groups", "/IOT-Edge-PoC"]
end
edge_vm.vm.box = "#{os}"
edge_vm.vm.hostname = "#{vmname}"
#private network for metadata service
edge_vm.vm.network "private_network", ip: "#{ip}"
#based on https://docs.microsoft.com/de-de/azure/iot-edge/how-to-install-iot-edge-linux
edge_vm.vm.provision "file", source: ".output/", destination: "$HOME/config/iotedge"
edge_vm.vm.provision "file", source: ".certs/certs/", destination: "$HOME/config/certs"
edge_vm.vm.provision "file", source: ".certs/private/", destination: "$HOME/config/certs"
#fix because some certs are read only which prevents reprovisioning
edge_vm.vm.provision "shell", inline: "chmod 777 /home/vagrant/config/certs/*"
#end fix
edge_vm.vm.provision "file", source: "#{registerscript}", destination: "$HOME/register_iotedge.py"
edge_vm.vm.provision "shell", inline: "sudo apt update; sudo apt upgrade -y"
# Only for TPM, !!! --> this whill install development tools and build the whole IoT SDK
if registerscript.include? "tpm"
edge_vm.vm.provision "shell", path: "vagrant_init_vtpm2.sh"
end
# Continue for all Edges
edge_vm.vm.provision "shell", path: "vagrant_init_edge.sh"
# Copy related certificates to iotedge folder
edge_vm.vm.provision "shell", inline: "cp /home/vagrant/config/certs/*#{vmname}* /etc/iotedge/"
edge_vm.vm.provision "shell", inline: "sudo python3 register_iotedge.py"
edge_vm.vm.provision "shell", inline: "sudo systemctl restart iotedge; sudo systemctl status iotedge; sudo iotedge check;"
# route to metadata service
edge_vm.vm.provision "shell", inline: "sudo route add -host 169.254.169.254 gw #{net_ip}.10"
end
end
gateway_hostname = "iot-edge-gateway"
#Central Server and Gateway
#this server will issue the certificates later on (act as central Server) and as Proxy/Gateway
config.vm.define :"#{gateway_hostname}", primary: true do |gateway_config|
gateway_config.vm.provider "virtualbox" do |vb|
vb.linked_clone = true
vb.memory = "2048"
vb.cpus = 1
vb.name = "#{gateway_hostname}"
#fix ubuntu network issue https://stackoverflow.com/questions/18457306/how-to-enable-internet-access-inside-vagrant
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb.customize ["modifyvm", :id, "--groups", "/IOT-Edge-PoC"]
end
gateway_config.vm.box = "#{os}"
gateway_config.vm.host_name = "#{gateway_hostname}"
gateway_config.vm.network "private_network", ip: "#{net_ip}.10"
gateway_config.vm.synced_folder "gateway_server/squid/", "/srv/squid"
gateway_config.vm.synced_folder "gateway_server/provisioner/", "/srv/provisioner"
gateway_config.vm.provision "shell", inline: "sudo apt update; sudo apt upgrade -y; sudo apt install python3 squid -y;"
end
#EOF
end