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

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 a30ad15f was 4f19d25, checked in by ramon <ramongomez@…>, 9 years ago

#739: Usar los parámetros del entorno definido en el curso on-line.

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

  • Property mode set to 100644
File size: 6.0 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
16CLIENTMEM = 512
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 eth1
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
43locale-gen --lang #{LANGUAGE}
44# Unmcomment next lines for automatic data insertion.
45#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"
46#for ((i=1; i<=#{NCLIENTS}; i++)); do
47#    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'),"
48#done
49#mysql -u usuog -ppassusuog -D ogAdmBD -e "${SQL%,}"
50#/opt/opengnsys/bin/setclientmode ogAdmin ogClient01 1
51#for ((i=2; i<=#{NCLIENTS}; i++)); do
52#    /opt/opengnsys/bin/setclientmode ogClient ogClient0$i 1
53#done
54echo "New OpenGnsys local URL: https://localhost:#{LOCALWEBPORT}/opengnsys/"
55EOT
56
57# Client 1 OS provisioning script.
58MODELSCRIPT = <<EOT
59# Uncomment next lines to install and configure OGAgent for Ubuntu.
60#apt-get install -y libxss1 policykit-1 python python-requests python-qt4 python-six python-prctl
61#wget -q http://opengnsys.es/svn/branches/version1.1-tickets/OGAgent-ticket718/client/shared/lib/ogagent/ogagent_1.0.0_all.deb  # temporal
62#dpkg -i ogagent_1.0.0_all.deb
63#sed -i "0,/remote=/ s,remote=.*,remote=https://#{NETPREFIX}10/opengnsys/rest/," /usr/share/OGAgent/cfg/ogagent.cfg
64# Remove network configuration added by Vagrant.
65sed -i "/VAGRANT/,$ d" /etc/network/interfaces
66echo "After now, use VirtualBox GUI to disable network interface 1 and work with this VM."
67# Leave VM halted.
68sleep 2
69poweroff &
70EOT
71
72Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
73
74  # OpenGnsys Server VM definition.
75  config.vm.define "ogAdministrator", primary: true do |og|
76    # Specific VirtualBox configuration.
77    og.vm.provider "virtualbox" do |vb|
78      # VM name, memory and CPUs.
79      vb.name = "ogAdministrator"
80      vb.memory = SERVERMEM
81      vb.cpus = 1
82      # Get VM disk path
83      line = `VBoxManage list systemproperties | grep "Default machine folder"`
84      vb_machine_folder = line.split(':')[1].strip()
85      second_disk = File.join(vb_machine_folder, vb.name, REPODISK)
86      # Create repo virtual disk, if needed.
87      unless File.exist?(second_disk)
88        vb.customize ['createhd', '--filename', second_disk, '--size', REPOSIZE * 1024]
89      end
90      # Attach repo virtual disk.
91      vb.customize ['storageattach', :id, '--storagectl', 'SATAController', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', second_disk]
92    end
93    # VM base and host name.
94    og.vm.box = "ubuntu/trusty64"
95    og.vm.hostname = "ogAdministrator"
96    # Network configuration: forward web port and attach new interface to VMs private network.
97    og.vm.network "forwarded_port", guest: 443, host: 8443
98    og.vm.network "private_network", ip: "#{NETPREFIX}10", virtualbox__intnet: true
99    # Disable synced folder.
100    og.vm.synced_folder ".", "/vagrant", disabled: true
101    # Launch provisioning script.
102    og.vm.provision "shell", inline: OGSERVERSCRIPT
103  end
104
105  # Client 1 VM definition.
106  config.vm.define "ogClient01", autostart: false do |v1|
107    v1.vm.box = "ubuntu/trusty64"
108    v1.vm.hostname = "ogClient01"
109    v1.vm.network "private_network", mac: "#{MACPREFIX}01".tr(":",""), type: "dhcp", virtualbox__intnet: true
110    v1.vm.provider "virtualbox" do |vb|
111      vb.name = "ogClient01"
112      vb.memory = CLIENTMEM
113      vb.cpus = 1
114      vb.customize ['modifyvm', :id, '--boot1', 'net', '--boot2', 'disk']
115    end
116    v1.vm.synced_folder ".", "/vagrant", disabled: true
117    v1.vm.provision "shell", inline: MODELSCRIPT
118  end
119
120  # Clonable clients definition.
121  (2..NCLIENTS).each do |i|
122    config.vm.define "ogClient0#{i}", autostart: false do |cl|
123      cl.vm.box = "clink15/pxe"
124      cl.ssh.insert_key = false
125      cl.vm.boot_timeout = 5
126      cl.vm.network "private_network", mac: "#{MACPREFIX}".tr(":","") + "%02d" % "#{i}", type: "dhcp", virtualbox__intnet: true
127      cl.vm.provider "virtualbox" do |vb|
128        vb.name = "ogClient0#{i}"
129        vb.memory = CLIENTMEM
130        vb.cpus = 1
131        vb.customize ['modifyvm', :id, '--boot1', 'net', '--boot2', 'disk']
132        vb.customize ["modifyvm", :id, "--nic1", "none"]
133      end
134    end
135  end
136
137end
138
Note: See TracBrowser for help on using the repository browser.