source: installer/vagrant/Vagrantfile-devel-vbox @ abfdc97

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since abfdc97 was b6fd406, checked in by ramon <ramongomez@…>, 8 years ago

#730 #739: Actualizador y entorno Vagrant de pruebas preparados para Ubuntu 16.04

git-svn-id: https://opengnsys.es/svn/branches/version1.1@5174 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100644
File size: 6.2 KB
Line 
1# Vagrantfile to install OpenGnsys 1.1 virtual environment using VirtualBox provider.
2
3VAGRANTFILE_API_VERSION = "2"
4# VM provider: Oracle VM VirtualBox.
5ENV['VAGRANT_DEFAULT_PROVIDER'] = "virtualbox"
6# Language (accepted values: es_ES, ca_ES, en_GB).
7LANGUAGE = "es_ES"
8ENV['LC_ALL'] = LANGUAGE + ".UTF-8"
9# Number of OpenGnsys clients (accepted values: from 2 to 9).
10NCLIENTS = 4
11# Repository virtual disk: file and size (GB).
12REPODISK = "ogRepo.vdi"
13REPOSIZE = 50
14# Amount of memory for server and clients (MB)
15SERVERMEM = 1024        # Minimum: 512
16CLIENTMEM = 512         # Minimum: 256
17# Clients MAC address prefix.
18MACPREFIX = "08:00:27:0E:65:"
19NETPREFIX = "192.168.2."
20# Local port to access OpenGnsys Server.
21LOCALWEBPORT = 8443
22
23# OpenGnsys Server provisioning script: prepare repo disk, install OpenGnsys, change default interface, configure DHCP server.
24OGSERVERSCRIPT = <<EOT
25# Mount repository disk.
26test -n "$(blkid /dev/sdb1 | grep ext4)" && exit
27echo -e "o\nn\np\n\n\n\nw" | fdisk /dev/sdb
28mkfs -t ext4 /dev/sdb1
29mkdir -p /opt/opengnsys/images
30echo "/dev/sdb1  /opt/opengnsys/images  ext4  defaults  0  0" >> /etc/fstab
31mount -a
32# Install OpenGnsys and change server address.
33wget -q http://opengnsys.es/svn/branches/version1.1/installer/opengnsys_installer.sh -O - | bash
34echo y | sudo /opt/opengnsys/bin/setserveraddr enp0s8
35# Insert DHCP data.
36for ((i=#{NCLIENTS}; i>0; i--)); do
37    sed -i "/^}$/ i host ogClient0${i} { hardware ethernet #{MACPREFIX}0${i}; fixed-address #{NETPREFIX}1${i}; }" /etc/dhcp/dhcpd.conf
38done
39service isc-dhcp-server restart
40# Set language.
41export LANG="#{LANGUAGE}.UTF-8"
42echo "LANG=\"$LANG\"" > /etc/default/locale
43echo "LANG=\"$LANG\"" >> /etc/environment
44locale-gen --lang #{LANGUAGE}
45sed -i "s/XKBLAYOUT=.*/XKBLAYOUT=\"${LANG%_*}\"/" /etc/default/keyboard
46dpkg-reconfigure -fnoninteractive console-setup
47# Comment out next lines for automatic data insertion.
48#SQL="INSERT INTO aulas (nombreaula, idcentro, urlfoto, grupoid, ubicacion, puestos, modomul, ipmul, pormul, velmul, router, netmask, ntp, 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"
49#for ((i=1; i<=#{NCLIENTS}; i++)); do
50#    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'),"
51#done
52#mysql -u usuog -ppassusuog -D ogAdmBD -e "${SQL%,}"
53#/opt/opengnsys/bin/setclientmode ogAdmin ogClient01 1
54#for ((i=2; i<=#{NCLIENTS}; i++)); do
55#    /opt/opengnsys/bin/setclientmode ogClient ogClient0$i 1
56#done
57echo "New OpenGnsys local URL: https://localhost:#{LOCALWEBPORT}/opengnsys/"
58EOT
59
60# Client 1 OS provisioning script.
61MODELSCRIPT = <<EOT
62# Comment out next lines to install and configure OGAgent for Ubuntu.
63#apt-get install -y libxss1 policykit-1 python python-requests python-qt4 python-six python-prctl
64#wget -q http://opengnsys.es/svn/branches/version1.1-tickets/OGAgent-ticket718/client/shared/lib/ogagent/ogagent_1.1.0_all.deb  # temporal
65#dpkg -i ogagent_1.1.0_all.deb
66#sed -i "0,/remote=/ s,remote=.*,remote=https://#{NETPREFIX}10/opengnsys/rest/," /usr/share/OGAgent/cfg/ogagent.cfg
67# Remove network configuration added by Vagrant.
68sed -i "/VAGRANT/,$ d" /etc/network/interfaces
69echo "After now, use VirtualBox GUI to disable network interface 1 and work with this VM."
70# Leave VM halted.
71sleep 2
72poweroff &
73EOT
74
75Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
76
77  # OpenGnsys Server VM definition.
78  config.vm.define "ogAdministrator", primary: true do |og|
79    # Specific VirtualBox configuration.
80    og.vm.provider "virtualbox" do |vb|
81      # VM name, memory and CPUs.
82      vb.name = "ogAdministrator"
83      vb.memory = SERVERMEM
84      vb.cpus = 1
85      # Get VM disk path
86      line = `VBoxManage list systemproperties | grep "Default machine folder"`
87      vb_machine_folder = line.split(':')[1].strip()
88      second_disk = File.join(vb_machine_folder, vb.name, REPODISK)
89      # Create repo virtual disk, if needed.
90      unless File.exist?(second_disk)
91        vb.customize ['createhd', '--filename', second_disk, '--size', REPOSIZE * 1024]
92      end
93      # Attach repo virtual disk.
94      vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', second_disk]
95    end
96    # VM base and host name.
97    og.vm.box = "bento/ubuntu-16.04"
98    og.vm.hostname = "ogAdministrator"
99    # Network configuration: forward web port and attach new interface to VMs private network.
100    og.vm.network "forwarded_port", guest: 443, host: 8443
101    og.vm.network "private_network", ip: "#{NETPREFIX}10", virtualbox__intnet: true
102    # Comment out to disable synced folder.
103    #og.vm.synced_folder ".", "/vagrant", disabled: true
104    # Launch provisioning script.
105    og.vm.provision "shell", inline: OGSERVERSCRIPT
106  end
107
108  # Client 1 VM definition.
109  config.vm.define "ogClient01", autostart: false do |v1|
110    v1.vm.box = "bento/ubuntu-16.04"
111    v1.vm.hostname = "ogClient01"
112    v1.vm.network "private_network", mac: "#{MACPREFIX}01".tr(":",""), type: "dhcp", virtualbox__intnet: true
113    v1.vm.provider "virtualbox" do |vb|
114      vb.name = "ogClient01"
115      vb.memory = CLIENTMEM
116      vb.cpus = 1
117      vb.customize ['modifyvm', :id, '--boot1', 'net', '--boot2', 'disk']
118    end
119    v1.vm.synced_folder ".", "/vagrant", disabled: true
120    v1.vm.provision "shell", inline: MODELSCRIPT
121  end
122
123  # Clonable clients definition.
124  (2..NCLIENTS).each do |i|
125    config.vm.define "ogClient0#{i}", autostart: false do |cl|
126      cl.vm.box = "clink15/pxe"
127      cl.ssh.insert_key = false
128      cl.vm.boot_timeout = 5
129      cl.vm.network "private_network", mac: "#{MACPREFIX}".tr(":","") + "%02d" % "#{i}", type: "dhcp", virtualbox__intnet: true
130      cl.vm.provider "virtualbox" do |vb|
131        vb.name = "ogClient0#{i}"
132        vb.memory = CLIENTMEM
133        vb.cpus = 1
134        vb.customize ['modifyvm', :id, '--boot1', 'net', '--boot2', 'disk']
135        vb.customize ["modifyvm", :id, "--nic1", "none"]
136      end
137    end
138  end
139
140end
141
Note: See TracBrowser for help on using the repository browser.