summaryrefslogtreecommitdiffstats
path: root/installer/vagrant/Vagrantfile-devel-vbox
blob: c7247684840e08330ad496dad052ab149fb1e108 (plain)
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
# Vagrantfile to install OpenGnsys 1.1 virtual environment using VirtualBox provider.

VAGRANTFILE_API_VERSION = "2"
# VM provider: Oracle VM VirtualBox.
ENV['VAGRANT_DEFAULT_PROVIDER'] = "virtualbox"
# Language.
LANGUAGE = "es_ES"
ENV['LC_ALL'] = LANGUAGE + ".UTF-8"

# Repository virtual disk: file and size (GB).
REPODISK = "repo.vdi"
REPOSIZE = 50
# Amount of memory for server and clients (MB)
SERVERMEM = 1024
CLIENTMEM = 512
# Clients MAC address prefix.
MACPREFIX = "08:00:27:0E:65:"
NETPREFIX = "192.168.50."
# 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/branches/version1.1/installer/opengnsys_installer.sh -O - | bash
echo y | sudo /opt/opengnsys/bin/setserveraddr eth1
# Insert DHCP data.
sed -i '/^}/d' /etc/dhcp/dhcpd.conf
echo "
    host virt1 { hardware ethernet #{MACPREFIX}01; fixed-address #{NETPREFIX}101; }
    host virt2 { hardware ethernet #{MACPREFIX}02; fixed-address #{NETPREFIX}102; }
}" >> /etc/dhcp/dhcpd.conf
service isc-dhcp-server restart
# Set language.
export LANG="#{LANGUAGE}.UTF-8"
echo "LANG=\"$LANG\"" > /etc/default/locale
locale-gen --lang #{LANGUAGE}
# Unmcomment next lines for automatic data insertion.
#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');" 
#/opt/opengnsys/bin/setclientmode ogAdmin virt1 1
#/opt/opengnsys/bin/setclientmode ogClient virt2 1
echo "New OpenGnsys local URL: https://localhost:#{LOCALWEBPORT}/opengnsys/"
EOT

# Client 1 OS provisioning script.
MODELSCRIPT = <<EOT
# Uncomment next lines to install and configure OGAgent.
#apt-get install -y libxss1 policykit-1 python python-requests python-qt4 python-six python-prctl
#wget -q http://opengnsys.es/svn/branches/version1.1-tickets/OGAgent-ticket718/client/shared/lib/ogagent/ogagent_1.0.0_all.deb	# temporal
#dpkg -i ogagent_1.0.0_all.deb
#sed -i "0,/remote=/s,remote=.*,remote=https://#{NETPREFIX}10/opengnsys/rest/," /usr/share/OGAgent/cfg/ogagent.cfg
echo "After now, use VirtualBox GUI to disable network interface 1 and work with this VM."
# Shutdown VM.
sleep 2
poweroff &
EOT

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  # OpenGnsys Server VM definition.
  config.vm.define "opengnsys", primary: true do |og|
    # Specific VirtualBox configuration.
    og.vm.provider "virtualbox" do |vb|
      # VM name, memory and CPUs.
      vb.name = "opengnsys"
      vb.memory = SERVERMEM
      vb.cpus = 1
      # Get VM disk path
      line = `VBoxManage list systemproperties | grep "Default machine folder"`
      vb_machine_folder = line.split(':')[1].strip()
      second_disk = File.join(vb_machine_folder, vb.name, REPODISK)
      # 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 = "opengnsys"
    # Network configuration: forward web port and attach new interface to VMs private network.
    og.vm.network "forwarded_port", guest: 443, host: 8443
    og.vm.network "private_network", ip: "#{NETPREFIX}10", virtualbox__intnet: true
    # 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 "virt1", autostart: false do |v1|
    v1.vm.box = "ubuntu/trusty64"
    v1.vm.hostname = "virt1"
    v1.vm.network "private_network", mac: "#{MACPREFIX}01".tr(":",""), type: "dhcp", virtualbox__intnet: true
    v1.vm.provider "virtualbox" do |vb|
      vb.name = "virt1"
      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

  # Client 2 VM definition.
  config.vm.define "virt2", autostart: false do |v2|
    v2.vm.box = "clink15/pxe"
    v2.ssh.insert_key = false
    v2.vm.boot_timeout = 5
    v2.vm.network "private_network", mac: "#{MACPREFIX}02".tr(":",""), type: "dhcp", virtualbox__intnet: true
    v2.vm.provider "virtualbox" do |vb|
      vb.name = "virt2"
      vb.memory = CLIENTMEM
      vb.cpus = 1
      vb.customize ['modifyvm', :id, '--boot1', 'net', '--boot2', 'disk']
      vb.customize ["modifyvm", :id, "--nic1", "none"]
    end
  end

end