source: installer/vagrant/Vagrantfile-devel-vbox @ 7b7d79c

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 7b7d79c was 2e97c42, checked in by ramon <ramongomez@…>, 9 years ago

#739: Comentarios en scripts de despliegue, preparado despliegue para cliente modelo con apagado automático tras instalación.

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

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