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
|
# Vagrantfile to install OpenGnsys Trunk virtual environment using VirtualBox provider.
VAGRANTFILE_API_VERSION = "2"
# VM provider: Oracle VM VirtualBox.
ENV['VAGRANT_DEFAULT_PROVIDER'] = "virtualbox"
# Language (accepted values: es_ES, ca_ES, en_GB).
LANGUAGE = "es_ES"
ENV['LC_ALL'] = LANGUAGE + ".UTF-8"
# Number of OpenGnsys clients (accepted values: from 2 to 9).
NCLIENTS = 4
# Repository virtual disk: file and size (GB).
REPODISK = "ogRepo.vdi"
REPOSIZE = 50
# Amount of memory for server and clients (MB)
SERVERMEM = 1024 # Minimum: 512
CLIENTMEM = 512 # Minimum: 256
# Clients MAC address prefix.
MACPREFIX = "08:00:27:0E:65:"
NETPREFIX = "192.168.2."
# Local port to access OpenGnsys Server.
LOCALWEBPORT = 8443
# OpenGnsys Server provisioning script: prepare repo disk, install OpenGnsys, change default interface, configure DHCP server.
OGSERVERSCRIPT = <<EOT
# Mount repository disk.
test -n "$(blkid /dev/sdb1 | grep ext4)" && exit
echo -e "o\nn\np\n\n\n\nw" | fdisk /dev/sdb
mkfs -t ext4 /dev/sdb1
mkdir -p /opt/opengnsys/images
echo "/dev/sdb1 /opt/opengnsys/images ext4 defaults 0 0" >> /etc/fstab
mount -a
# Install OpenGnsys and change server address.
wget -q http://opengnsys.es/svn/trunk/installer/opengnsys_installer.sh -O - | bash
echo y | sudo /opt/opengnsys/bin/setserveraddr eth1
# Insert DHCP data.
for ((i=#{NCLIENTS}; i>0; i--)); do
sed -i "/^}$/ i host ogClient0${i} { hardware ethernet #{MACPREFIX}0${i}; fixed-address #{NETPREFIX}1${i}; }" /etc/dhcp/dhcpd.conf
done
service isc-dhcp-server restart
# Set language.
export LANG="#{LANGUAGE}.UTF-8"
echo "LANG=\"$LANG\"" > /etc/default/locale
echo "LANG=\"$LANG\"" >> /etc/environment
locale-gen --lang #{LANGUAGE}
sed -i "s/XKBLAYOUT=.*/XKBLAYOUT=\"${LANG%_*}\"/" /etc/default/keyboard
dpkg-reconfigure -fnoninteractive console-setup
# Comment out next lines for automatic data insertion.
#SQL="INSERT INTO aulas (nombreaula, idcentro, urlfoto, grupoid, ubicacion, puestos, modomul, ipmul, pormul, velmul, router, netmask, dns, proxy, modp2p, timep2p) VALUES ('Aula virtual', 1, 'aula.jpg', 0, 'Despliegue virtual con Vagrant.', 5, 2, '239.194.2.11', 9000, 70, '#{NETPREFIX}1', '255.255.255.0', '', '', 'peer', 30); INSERT INTO ordenadores (nombreordenador, ip, mac, idaula, idrepositorio, idperfilhard, idmenu, idproautoexec, grupoid, router, mascara, arranque, netiface, netdriver, fotoord) VALUES"
#for ((i=1; i<=#{NCLIENTS}; i++)); do
# SQL="$SQL ('ogClient0$i', '#{NETPREFIX}1$i', REPLACE('#{MACPREFIX}0$i',':',''), 1, 1, 0, 0, 0, 0, '#{NETPREFIX}1', '255.255.255.0', '00unknown', 'eth0', 'generic', 'fotoordenador.gif'),"
#done
#mysql -u usuog -ppassusuog -D ogAdmBD -e "${SQL%,}"
#if ! grep -q "1\.0" /opt/opengnsys/doc/VERSION.txt; then AUX=1; fi
#/opt/opengnsys/bin/setclientmode ogAdmin ogClient01 $AUX
#for ((i=2; i<=#{NCLIENTS}; i++)); do
# /opt/opengnsys/bin/setclientmode ogClient ogClient0$i $AUX
#done
echo "New OpenGnsys local URL: https://localhost:#{LOCALWEBPORT}/opengnsys/"
EOT
# Client 1 OS provisioning script.
MODELSCRIPT = <<EOT
# Remove network configuration added by Vagrant.
sed -i "/VAGRANT/,$ d" /etc/network/interfaces
echo "After now, use VirtualBox GUI to disable network interface 1 and work with this VM."
# Leave VM halted.
sleep 2
poweroff &
EOT
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# OpenGnsys Server VM definition.
config.vm.define "ogAdministrator", primary: true do |og|
# Specific VirtualBox configuration.
og.vm.provider "virtualbox" do |vb|
# VM name, memory and CPUs.
vb.name = "ogAdministrator"
vb.memory = SERVERMEM
vb.cpus = 1
# 2nd virtual disk path (current dir on Windows, VM dir on other OSes)
if Vagrant::Util::Platform.windows? then
second_disk = File.join(".", REPODISK)
else
line = `VBoxManage list systemproperties`.match("Default machine folder.*")[0]
vb_machine_folder = line.split(':')[1].strip()
second_disk = File.join(vb_machine_folder, vb.name, REPODISK)
end
# Create repo virtual disk, if needed.
unless File.exist?(second_disk)
vb.customize ['createhd', '--filename', second_disk, '--size', REPOSIZE * 1024]
end
# Attach repo virtual disk.
vb.customize ['storageattach', :id, '--storagectl', 'SATAController', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', second_disk]
end
# VM base and host name.
og.vm.box = "ubuntu/trusty64"
og.vm.hostname = "ogAdministrator"
# Network configuration: forward web port and attach new interface to VMs private network.
og.vm.network "forwarded_port", guest: 443, host: LOCALWEBPORT, host_ip: "127.0.0.1"
og.vm.network "private_network", ip: "#{NETPREFIX}10", virtualbox__intnet: true
# Comment out to disable synced folder.
#og.vm.synced_folder ".", "/vagrant", disabled: true
# Launch provisioning script.
og.vm.provision "shell", inline: OGSERVERSCRIPT
end
# Client 1 VM definition.
config.vm.define "ogClient01", autostart: false do |v1|
v1.vm.box = "ubuntu/trusty64"
v1.vm.hostname = "ogClient01"
v1.vm.network "private_network", mac: "#{MACPREFIX}01".tr(":",""), type: "dhcp", virtualbox__intnet: true
v1.vm.provider "virtualbox" do |vb|
vb.name = "ogClient01"
vb.memory = CLIENTMEM
vb.cpus = 1
vb.customize ['modifyvm', :id, '--boot1', 'net', '--boot2', 'disk']
end
v1.vm.synced_folder ".", "/vagrant", disabled: true
v1.vm.provision "shell", inline: MODELSCRIPT
end
# Clonable clients definition.
(2..NCLIENTS).each do |i|
config.vm.define "ogClient0#{i}", autostart: false do |cl|
cl.vm.box = "clink15/pxe"
cl.ssh.insert_key = false
cl.vm.boot_timeout = 5
cl.vm.network "private_network", mac: "#{MACPREFIX}".tr(":","") + "%02d" % "#{i}", type: "dhcp", virtualbox__intnet: true
cl.vm.provider "virtualbox" do |vb|
vb.name = "ogClient0#{i}"
vb.memory = CLIENTMEM
vb.cpus = 1
vb.customize ['modifyvm', :id, '--boot1', 'net', '--boot2', 'disk']
vb.customize ["modifyvm", :id, "--nic1", "none"]
end
end
end
end
|