Vnx-vagrant

From VNX
Revision as of 18:50, 14 June 2014 by David (talk | contribs)
Jump to: navigation, search

How to create a Ubuntu Vagrant virtual machine to run VNX virtual scenarios

This procedure describes how to use Vagrant to create a Ubuntu 14.04 virtual machine to run VNX. This is probably the easiest way to test VNX over Linux, Mac OSX or Windows. You can download the VM created with this procedure from here.

The VNX scenarios started within the VM created are restricted to LXC, due to limitations in nested virtualizacion (KVM virtual machines cannot be started whitin a Virtualbox virtual machine).

Create the Vagrant VM

To create a VNX ready Vagrant virtual machine, follow this procedure:

Convert the Vagrant VM to a base image (.box)

To create a Vagrant base box starting from the VM created:

  • Optionally, try to reduce the VM image by writting zeros to free disk space. From inside the VM, type:
  • sudo dd if=/dev/zero of=/EMPTY bs=1M
    sudo rm -f /EMPTY
    
  • Get the name of the VM from VirtualBox with:
  • VBoxManage list vms
    ...
    "vnx_1402744959" {e46a72f4-2b47-4220-b77c-7a58ae98b6d1}
    ...
    
  • Then package that VM with:
  • vagrant package --base vnx_1402744959 --output vnx-ubuntu-14.04-v01.box --vagrantfile Vagrantfile.pkg
    
  • Optionally, copy the file created (vnx-ubuntu-14.04-v01.box) to a web server to allow creation of VM from this Vagrant base image.

Create a VM starting from the base image

To download and create a VM from the Vagrant base image created, just:

vagrant box add vnx http://idefix.dit.upm.es/vnx/vagrant-vnx/vnx-ubuntu-14.04-v01.box
mkdir vnx
cd vnx
vagrant init vnx
vagrant up

Optionally, you can customize the VM (memory assigned or the number of cpus) by editing Vagrantfile. For example, to increase memory to 2Gb and the number of CPUs to 4, add the following lines:

   config.vm.provider :virtualbox do |vb|
    vb.customize ["modifyvm", :id,
                  "--memory", "2048",
                  "--cpus", "4"]
  end

Vagrantfile content

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "trusty32"
  config.ssh.forward_x11 = true
  config.vm.provision :shell, :path => "bootstrap.sh"
  config.vm.provider :virtualbox do |vb|
    vb.gui = false
    vb.customize ["modifyvm", :id, 
                  "--memory", "1024",
                  "--cpus", "2"]
  end
end

bootstrap.sh file content

#!/usr/bin/env bash

#
# VNX installation script for Vagrant VMs
# 
# Author: David Fernández (david@dit.upm.es)
#
# This file is part of the Virtual Networks over LinuX (VNX) Project distribution. 
# (www: http://www.dit.upm.es/vnx - e-mail: vnx@dit.upm.es) 
# 
# Departamento de Ingeniería de Sistemas Telemáticos (DIT)
# Universidad Politécnica de Madrid
# SPAIN
#

HOSTNAME=vnx

echo "-- Installing VNX:"

echo ""
echo "---- Changing hostname:"
echo ""

echo $HOSTNAME > /etc/hostname
hostname $HOSTNAME
sed -i -e "s/127.0.1.1.*/127.0.1.1   $HOSTNAME/" /etc/hosts

echo ""
echo "---- Installing required packages:"
echo ""

apt-get update
apt-get -y install qemu-kvm libvirt-bin vlan xterm bridge-utils screen virt-manager \
  virt-viewer libxml-checker-perl libxml-parser-perl libnetaddr-ip-perl libnet-pcap-perl \
  libnet-ipv6addr-perl liberror-perl libexception-class-perl \
  uml-utilities libxml-libxml-perl libterm-readline-perl-perl libnet-telnet-perl \
  libnet-ip-perl libreadonly-perl libmath-round-perl libappconfig-perl \
  libdbi-perl graphviz genisoimage gnome-terminal tree libio-pty-perl libsys-virt-perl \
  libfile-homedir-perl curl w3m picocom expect lxc aptsh libxml-tidy-perl inkscape \
  linux-image-extra-virtual wmctrl

echo ""
echo "---- Installing VNX application:"
echo ""

mkdir /tmp/vnx-update
cd /tmp/vnx-update
rm -rf /tmp/vnx-update/vnx-*
wget http://vnx.dit.upm.es/vnx/vnx-latest.tgz
tar xfvz vnx-latest.tgz
cd vnx-*
sudo ./install_vnx

sudo mv /usr/share/vnx/etc/vnx.conf.sample /etc/vnx.conf
# Set svg viewer to inkview
sed -i -e '/\[general\]/{:a;n;/^$/!ba;i\svg_viewer=inkview' -e '}' /etc/vnx.conf
# Set console to xterm
sed -i -e '/console_term/d' /etc/vnx.conf
sed -i -e '/\[general\]/{:a;n;/^$/!ba;i\console_term=xterm' -e '}' /etc/vnx.conf

echo ""
echo "---- Installing VNX LXC rootfs:"
echo ""

cd /usr/share/vnx/filesystems/
/usr/bin/vnx_download_rootfs -l -r vnx_rootfs_lxc_ubuntu-14.04-v025 -y
ln -s rootfs_lxc_ubuntu rootfs_lxc

echo "-- Rebooting to finish installation..."
reboot

echo "----"

Install CDPS exercise

  • Download exercise:
  • cd
    mkdir p7
    cd p7
    wget idefix.dit.upm.es/download/cdps/p7.xml
    
  • Update rootfs:
  • sudo lxc-start -n vnx -f  /usr/share/vnx/filesystems/vnx_rootfs_lxc_ubuntu-13.10-v025/config
    dhclient eth0
    apt-get update
    apt-get -y install fuse glusterfs-client glusterfs-server
    mknod -m 666 /dev/fuse c 10 229
    
  • Test the exercise:
  • sudo vnx -f p7.xml -v -t
    
  • Copy config scripts
  • scp root@10.0.2.2:/root/cdps/p7/p7-con* .