Difference between revisions of "Vnx-examples"

From VNX
Jump to: navigation, search
(Created page with "{{Title|VNX Example Scenarios}} Several example scenarios are distributed together with VNX to allow easily testing its functionalities (see /usr/share/vnx/examples directory). ...")
 
 
(104 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Title|VNX Example Scenarios}}
+
{{Title|VNX Simple Scenarios}}
  
Several example scenarios are distributed together with VNX to allow easily testing its functionalities (see /usr/share/vnx/examples directory).
+
__TOC__
  
Three types of scenarios are included:
+
== Description ==
<ul>
+
Several simple example scenarios are included in VNX distribution to allow testing the tool functionalities with the different types of virtual machines supported (see /usr/share/vnx/examples/simple_*.xml files).
<li> '''simple-XXXX.xml''', which are a set of simple scenarios made of one virtual machine with one network interface.</li>
 
<ul>
 
<li> '''simple_uml.xml''': a single Linux virtual machine started using UML with address 10.0.0.2</li>
 
<li> '''simple_xp.xml''': a single Windows XP virtual machine started using libvirt with address 10.0.0.3</li>
 
<li> '''simple_win7.xml''': a single Windows 7 virtual machine started using libvirt with address 10.0.0.4</li>
 
<li> '''simple_ubuntu.xml''': a single Ubuntu 10.04.1 server virtual machine started using libvirt with address 10.0.0.5</li>
 
<li> '''simple_ubuntu-gui.xml''': a single Ubuntu 10.04.1 virtual machine with a minimal GNOME gui started using libvirt with address 10.0.0.6
 
<li> '''simple_freebsd.xml''': a single FreeBSD 8.1 server virtual machine started using libvirt with address 10.0.0.7</li>
 
<li> '''simple_freebsd-gui.xml''': a single FreeBSD 8.1 virtual machine with a minimal GNOME gui started using libvirt with address 10.0.0.8</li>
 
All scenarios share the same network (Net0, 10.0.0.0/24) to allow connectivity among all the virtual machines and the host (which has address 10.0.0.1)
 
</ul>
 
<li> '''tutorial_root1-XXXX.xml''', which are virtual scenarios based on the [http://www.dit.upm.es/vnumlwiki/index.php/Tutorial VNUML tutorial scenario] but starting virtual machines using other operating systems.</li>
 
<li> '''root_fs_XXX.xml''', which are libvirt specifications to start virtual machines with Internet connection (through a NAT) using the different VNX root file-systems. They are included to easily allow modifying root filesystems (for example, to install new software packages).</li>
 
</ul>
 
  
To test the scenarios:
+
Each simple scenario includes just one virtual machine connected to a virtual network (Net0, 10.0.0.0/24), where the hosts has also a virtual network interface connected (10.0.0.1).
<ul>
 
<li>Open a root shell from the graphical console of the host machine. If you are not sat in front of host's console you can access it using ssh with X-forwarding activated. For example, from a Unix machine you can use:</li>
 
  ssh -X <host-addr>
 
In this case, it is recommended to test that X-forwarding is working by launching a "xterm" or "xeyes" application and seeing that the application window is correctly launched. Besides, as the access to the virtual machine consoles is tipically made using virt-viewer application (VNC protocol), you need a good connectivity between your machine and the host were VNX runs.
 
</ul>
 
  
=== Simple scenarios (simple_XXXX.xml) ===
+
The simple scenarios are prepared to be started and tested individually or to be started all together to form the compound scenario shown in Figure 1.  
<ul>
 
<li>Start simple scenarios by means of:</li>
 
sudo vnx -f /usr/share/vnx/examples/simple_XXXX.xml -v --create
 
For example, to start an XP virtual machine type:
 
sudo vnx -f /usr/share/vnx/examples/simple_xp.xml -v --create
 
Just after the execution, you will see the console of the Windows XP machine starting. Once the machine has completely started, the VNX autoconfiguration daemon will configure its name and the network interfaces and restart the machine for the changes to take effect. After the restart, the virtual machine will be available for interacting with it.
 
  
Note: virt-viewer console application "captures" the mouse when interacting with the virtual machines. You have to type "Ctrl-Alt" to release the mouse.
+
<center>
 +
[[Image:Simple.png|center|thumb|800px|<div align=center>
 +
'''Figure 1: simple scenarios topology'''</div>]]
 +
</center>
 +
 
 +
The following simple scenarios are available:
 +
 
 +
<center>
 +
{| style="color:black; background-color:#ffffcc; font-size: 80%;" cellpadding="4" cellspacing="0" border="1"
 +
|'''Scenario file name'''
 +
|'''Description'''
 +
|'''VM ip address'''
 +
|-
 +
|simple_uml.xml || Just one User Mode Linux (UML) Debian system || 10.0.0.2
 +
|-
 +
|simple_winxp.xml ||Just one KVM Windows XP system ||10.0.0.3
 +
|-
 +
|simple_ubuntu.xml ||Just one KVM Ubuntu system without GUI ||10.0.0.4
 +
|-
 +
|simple_ubuntu-gui.xml ||Just one KVM Ubuntu system with minimal GNOME GUI ||10.0.0.5
 +
|-
 +
|simple_freebsd.xml ||Just one KVM FreeBSD system without GUI ||10.0.0.6
 +
|-
 +
|simple_freebsd-gui.xml ||Just one KVM FreeBSD system with minimal GNOME GUI ||10.0.0.7
 +
|-
 +
|simple_win7.xml ||Just one KVM Windows 7 system ||10.0.0.8
 +
|-
 +
|simple_fedora.xml ||Just one KVM Fedora system without GUI ||10.0.0.9
 +
|-
 +
|simple_fedora-gui.xml ||Just one KVM Fedora system with a GNOME GUI ||10.0.0.10
 +
|-
 +
|simple_dynamips.xml ||Just one Dynamips emulated CISCO 3600 router ||10.0.0.11
 +
|-
 +
|simple_dynamips2.xml ||Just one Dynamips emulated CISCO 7200 router ||10.0.0.12
 +
|-
 +
|simple_olive.xml ||Just one Olive emulated Juniper router ||10.0.0.13
 +
|-
 +
|simple_centos.xml ||Just one KVM CentOS system without GUI ||10.0.0.15
 +
|-
 +
|simple_centos-gui.xml ||Just one KVM CentOS system with a GNOME GUI ||10.0.0.16
 +
|}
 +
</center>
 +
 
 +
All scenarios are available in /usr/share/vnx/examples directory. See, for example, the content of [[Vnx-examples#simple_ubuntu-gui.xml_scenario|simple_ubuntu-gui.xml]] scenario at the end of this page
  
<li>Once started, you can test the network connectivity form the host to the virtual machine:
+
== Starting a simple scenario ==
 +
 
 +
You can start VNX scenarios either from a local shell window or remotely using an SSH session with X-forwarding enabled. For example, if you connect to the VNX host from a Unix or MacOS system you can use:
 +
  ssh -X <vnx-host-address-or-name>
 +
If you connect from another system, just investigate how to configure your SSH client to do X-forwarding (most of them include it).
 +
 
 +
In case of remote connections, it is recommended to test that X-forwarding is working by launching a "xterm" or "xeyes" application and checking that the application window is correctly launched. Beware that X-forwarding is very bandwidth consuming, so you will need a good connectivity between your system and the host were VNX runs.
 +
 
 +
As VNX needs root priviledges, you have to be '''root''' in the shell window or, alternatively, if your account is allowed to "sudo" root (as typically is, for example, in Ubuntu systems), just precede vnx commands with "sudo", as shown below.
 +
 
 +
To start, for example, the simple_ubuntu-gui scenario:
 +
cd /usr/share/vnx/examples/
 +
sudo vnx -f simple_ubuntu-gui.xml -v --create
 +
You will see the two virtual machine consoles opening: the graphical one showing the gnome desktop and the text console.
 +
 
 +
<center>
 +
[[File:simple-ubuntu-gui.png|center|thumb|500px|<div align=center>
 +
'''Figure 2: Graphical and textual consoles of simple_ubuntu-gui scenario'''</div>]]
 +
</center>
 +
 
 +
Beware that, once the virtual machine has completely started, the VNX autoconfiguration daemon (VNXACED) has to do its job configuring the name and the network interfaces parameters and restarting the machine for the changes to take effect. After that restart, the virtual machine is ready to be used.
 +
 
 +
Once started, you can test the network connectivity from the host to the virtual machine:
 +
<pre>
 +
# ping -c 4 10.0.0.5
 +
PING 10.0.0.5 (10.0.0.5) 56(84) bytes of data.
 +
64 bytes from 10.0.0.5: icmp_seq=1 ttl=64 time=0.197 ms
 +
64 bytes from 10.0.0.5: icmp_seq=2 ttl=64 time=0.188 ms
 +
64 bytes from 10.0.0.5: icmp_seq=3 ttl=64 time=0.177 ms
 +
64 bytes from 10.0.0.5: icmp_seq=4 ttl=64 time=0.171 ms
 +
 
 +
--- 10.0.0.5 ping statistics ---
 +
4 packets transmitted, 4 received, 0% packet loss, time 3001ms
 +
rtt min/avg/max/mdev = 0.171/0.183/0.197/0.013 ms
 +
</pre>
 +
 
 +
If you close the consoles, you can reopen them with the following commands:
 +
sudo vnx -f simple_ubuntu-gui.xml -v --console con0 -M ubuntu-gui
 +
sudo vnx -f simple_ubuntu-gui.xml -v --console con1 -M ubuntu-gui
 +
 
 +
Or much simpler, you can use libvirt commands:
 +
# sudo virsh list
 +
  Id Nombre              Estado
 +
----------------------------------
 +
  31 ubuntu-gui          running
 +
# virt-viewer 31 &                      # To open the graphical console
 +
# xterm -e "sudo virsh console 31" &    # To open the text console
 +
 
 +
Beware that only one textual console can be used at a time. If you open a second one, you will experiment a strange behaviour as both consoles will compete for the pts terminal. On the contrary, you can open several graphical console simultaneously.
 +
 
 +
See [[Vnx-console-mgmt|VNX Console Management]] for more details.
 +
 
 +
== Executing commands ==
 +
 
 +
You can also execute commands on the virtual machine from the host by means of the '''<exec>''' tags in the XML scenario specification:
 +
 
 +
For example, you can start the calculator or the xeyes application on the virtual machine by issuing:
 +
sudo vnx -f simple_ubuntu-gui.xml -v --exe calc
 +
sudo vnx -f simple_ubuntu-gui.xml -v --exe xeyes
 +
 
 +
Those commands execute what is defined in the <exec> tags with seq="calc" or seq="xeyes" respectively:
 
<pre>
 
<pre>
root@tutatis:/usr/share/vnx/examples# ping -c 4 10.0.0.3
+
<!-- Start xeyes application -->
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
+
<exec seq="xeyes"    type="verbatim" ostype="xexec">xeyes</exec>
64 bytes from 10.0.0.3: icmp_seq=1 ttl=128 time=0.312 ms
 
64 bytes from 10.0.0.3: icmp_seq=2 ttl=128 time=0.376 ms
 
64 bytes from 10.0.0.3: icmp_seq=3 ttl=128 time=0.249 ms
 
64 bytes from 10.0.0.3: icmp_seq=4 ttl=128 time=0.260 ms
 
  
--- 10.0.0.3 ping statistics ---
+
<!-- Start calculator  -->
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
+
<exec seq="calc"      type="verbatim" ostype="xexec">gcalctool</exec>
rtt min/avg/max/mdev = 0.249/0.299/0.376/0.051 ms
+
<exec seq="calcoff"  type="verbatim" ostype="system">pkill gcalctool</exec>
 
</pre>
 
</pre>
  
<li>You can also execute commands on the virtual machine from the host. For example, you can start the calculator on the Windows XP machine by issuing:</li>
+
The "ostype" attribute is used to specify the type of command included in <exec> tag, either command line (CLI) or graphical (GUI), and whether vnx tool waits for command execution end or not. For values are posible:
  sudo vnx -f /usr/share/vnx/examples/simple_xp.xml -v --exe calc
+
 
 +
<center>
 +
{| style="color:black; background-color:#ffffcc; font-size: 80%;" cellpadding="4" cellspacing="0" border="1"
 +
| '''ostype''' || '''Type of commands''' ||''' Waits for command execution end'''
 +
|-
 +
| system || CLI || YES
 +
|-
 +
| exec || CLI || NO
 +
|-
 +
| xsystem || GUI || YES
 +
|-
 +
| xexec || GUI || NO
 +
|}
 +
</center>
 +
 
 +
You can check, for example, the "xexec" value with:
 +
sudo vnx -f simple_ubuntu-gui.xml -v --exe xeyes2
 +
which executes the command:
 +
<!-- Start xeyes application and wait until it is closed -->
 +
<exec seq="xeyes2"    type="verbatim" ostype="xexec">xeyes</exec>
 +
You will see the application xeyes opened in the virtual machine, but the command executed in the host will not end till the application is closed.  
 +
 
 +
Or you can use a "system" command that closes (kills) all calc applications opened:
 +
sudo vnx -f simple_ubuntu-gui.xml -v --exe calcoff
 +
 
 +
You can start or stop a web server in the virtual machine with:
 +
sudo vnx -f /usr/share/vnx/examples/simple_ubuntu.xml -v --exe start-www
 +
  sudo vnx -f /usr/share/vnx/examples/simple_ubuntu.xml -v --exe stop-www
 +
 
 +
And test that the web server is running by manually opening a web navigator in the host and loading URL http://10.0.0.5. Alternativey, you can check the server availability with "nmap" tool:
 +
<pre>
 +
# nmap -p 80 10.0.0.5
 +
 
 +
Starting Nmap 5.00 ( http://nmap.org ) at 2011-07-28 00:48 CEST
 +
Interesting ports on 10.0.0.5:
 +
PORT  STATE SERVICE
 +
80/tcp open  http
 +
MAC Address: 02:FD:00:05:01:01 (Unknown)
 +
 
 +
Nmap done: 1 IP address (1 host up) scanned in 0.40 seconds
 +
</pre>
 +
 
 +
Apart from the <exec> tags which define the commands used to start the web server ("service apache2 start"), the command sequence "start-www" includes a '''<filetree>''' tag to copy files from the host to the virtual machine that it is used to copy the initial web page shown by the server.
 +
<pre>
 +
<!-- Copy the content of conf/txtfile directory in the host to
 +
      the /var/www directory in the virtual machine -->
 +
<filetree seq="start-www" root="/var/www">conf/txtfile</filetree>
 +
<!-- Start/stop apache www server -->
 +
<exec seq="start-www" type="verbatim" ostype="system">service apache2 start</exec>
 +
<exec seq="stop-www"  type="verbatim" ostype="system">service apache2 stop</exec>
 +
</pre>
 +
 
 +
You can find more example commands by having a look at <exec> and <filetree> tags in simple_ubuntu-gui.xml file or in other simple_*.xml examples. And more information about command execution in [[Vnx-autoconf|here]].
 +
<!--
 
This command has been specified inside the simple_xp.xml file in the line:
 
This command has been specified inside the simple_xp.xml file in the line:
 
  <exec seq="calc" type="verbatim" mode="system">calc.exe</exec>
 
  <exec seq="calc" type="verbatim" mode="system">calc.exe</exec>
Line 62: Line 189:
 
  <filetree seq="vnxtxt" root="c:\temp">conf/txtfile</filetree>
 
  <filetree seq="vnxtxt" root="c:\temp">conf/txtfile</filetree>
 
  <exec seq="vnxtxt" type="verbatim" mode="system">start /max notepad c:\temp\vnx.txt</exec>
 
  <exec seq="vnxtxt" type="verbatim" mode="system">start /max notepad c:\temp\vnx.txt</exec>
 
<li>You can start a Linux Ubuntu server with:</li>
 
sudo vnx -f /usr/share/vnx/examples/simple_ubuntu.xml -v --create
 
And start a web server inside it with:
 
sudo vnx -f /usr/share/vnx/examples/simple_ubuntu.xml -v --exe start-www
 
And test the web server access from the XP virtual machine by manually opening a web navigator and loading URL http://10.0.0.4.
 
 
 
<center>
 
<center>
 
[[Image:Vnx-simple_xp.png|400px]]
 
[[Image:Vnx-simple_xp.png|400px]]
 
</center>
 
</center>
 +
-->
  
<li>You can find more example commands by having a look at <exec> and <filetree> tags in simple_XXXX.xml files.</li>
+
== Stopping the scenario ==
  
<li>To stop the scenario preserving the changes made:</li>
+
To stop the scenario preserving the changes made inside virtual machines you have to use the "-d" or "--shutdown" option:
  sudo vnx -f /usr/share/vnx/examples/simple_xp.xml -v --shutdown
+
  sudo vnx -f simple_ubuntu-gui.xml -v --shutdown
 
You can later restart the scenario with:
 
You can later restart the scenario with:
  sudo vnx -f /usr/share/vnx/examples/simple_xp.xml -v --create
+
  sudo vnx -f simple_ubuntu-gui.xml -v --create
  
<li>To stop the scenario discarding the changes made:</li>
+
To stop the scenario discarding all the changes made in the virtual machine use the "-P" or "--destroy" option:
  sudo vnx -f /usr/share/vnx/examples/simple_xp.xml -v --destroy
+
  sudo vnx -f simple_ubuntu-gui.xml -v --destroy
</ul>
 
  
=== Tutorial scenarios (tutorial_root1_XXXX.xml) ===
+
Tipically, virtual machines in VNX are created using "Copy-on-write (COW)" filesystems to allow sharing a root filesystem among several virtual machines.  
  
<ul>
+
In the definition of the virtual machine:
 +
<filesystem type="cow">/usr/share/vnx/filesystems/rootfs_ubuntu-gui</filesystem>
 +
you specify the root filesystem to use (/usr/share/vnx/filesystems/rootfs_ubuntu-gui) and how it is mounted (cow). Using COW mode, the virtual machine will use the root filesystem in read-only mode and use another filesystem to save the files modified. When you use "-P|--destroy" option to stop an scenario, vnx deletes the filesystem with the modifications.
  
<li>To start the tutorial scenario with linux, FreeBSD, XP and Win7 virtual machines just type:</li>
+
== Other interesting options ==
sudo vnx -f tutorial_root1_all.xml -v --create
+
 
 +
You can see a graphical map of the virtual scenario using the --show-map option:
 +
  sudo vnx -f simple_ubuntu-gui.xml -v --show-map
  
<li>Once the scenario has completely started (remenber that libvirt machines have to be restarted for the autoconfiguration to complete), you should see all the virtual machine consoles:</li>
 
 
<center>
 
<center>
[[Image:Vnx-tutorial_root1_all-s.png|400px]]
+
[[Image:Simple_ubuntu-gui.png|center|thumb|800px|<div align=center>
 +
'''Figure 3: simple_ubuntu-gui scenario topology'''</div>]]
 
</center>
 
</center>
  
<li>You can test the network connectivity, for example, accesing '''h1''' machine and tracing to '''h4''':
+
  traceroute -n 10.0.2.3
+
 
 +
== simple_ubuntu-gui.xml scenario ==
 +
 
 +
<pre>
 +
<?xml version="1.0" encoding="UTF-8"?>
 +
 
 +
<!--
 +
~~~~~~~~~~~~~~~~~~~~
 +
VNX Sample scenarios
 +
~~~~~~~~~~~~~~~~~~~~
 +
 
 +
Name:        simple_ubuntu-gui
 +
Description: Just one Ubuntu virtual machine with GUI connected to a Network named Net0 with address 10.0.0.5.
 +
            The host has an interface in Net0 with address 10.0.0.1 
 +
            This simple scenario is supposed to be used for testing the different
 +
            types of virtual machines supported by VNX. You can start several simple_*.xml
 +
            scenarios and test the connectivity among virtual machines and the host, as all
 +
            scenarios share the same "Net0" network.  
  
<li>To stop and restart a virtual machine without loosing the modifications you have made you can type::
+
This file is part of the Virtual Networks over LinuX (VNX) Project distribution.
  sudo vnx -f tutorial_root1_all.xml -v --shutdown -M uml4
+
(www: http://www.dit.upm.es/vnx - e-mail: vnx@dit.upm.es)
  sudo vnx -f tutorial_root1_all.xml -v --create  -M uml4
 
  
<li>The same but loosing the changes made and returning to a fresh virtual machine state:
+
Departamento de Ingenieria de Sistemas Telematicos (DIT)
  sudo vnx -f tutorial_root1_all.xml -v --destroy -M uml4
+
Universidad Politecnica de Madrid
  sudo vnx -f tutorial_root1_all.xml -v --create -M uml4
+
SPAIN
 +
-->
  
</ul>
+
<vnx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 +
  xsi:noNamespaceSchemaLocation="/usr/share/xml/vnx/vnx-2.00.xsd">
 +
  <global>
 +
    <version>2.0</version>
 +
    <scenario_name>simple_ubuntu-gui</scenario_name>
 +
    <automac offset="5"/>
 +
    <vm_mgmt type="none" />
 +
    <vm_defaults>
 +
    <console id="0" display="yes"/>
 +
    <console id="1" display="yes"/>
 +
    </vm_defaults>
 +
  </global>
 +
   
 +
  <net name="Net0" mode="virtual_bridge" />
 +
 
 +
  <!-- NODES -->
 +
  <vm name="ubuntu-gui" type="libvirt" subtype="kvm" os="linux">
 +
    <filesystem type="cow">/usr/share/vnx/filesystems/rootfs_ubuntu-gui</filesystem>
 +
    <mem>512M</mem>
 +
    <if id="1" net="Net0">
 +
      <ipv4>10.0.0.5/24</ipv4>
 +
    </if>
 +
    <filetree seq="vnxtxt" root="/tmp">conf/txtfile</filetree>
 +
    <filetree seq="vnxwww" root="/tmp">conf/txtfile</filetree>
 +
    <filetree seq="start-www" root="/var/www">conf/txtfile</filetree>
  
=== Other interesting options ===
+
    <!-- Start xeyes application -->
 +
    <exec seq="xeyes"    type="verbatim" ostype="xexec">xeyes</exec>
  
You can see a graphical map of the virtual scenario using the --show-map option:
+
    <!-- Start xeyes application and wait until it is closed -->
  sudo vnx -f tutorial_root1_all.xml -v --show-map
+
    <exec seq="xeyes2"    type="verbatim" ostype="xsystem">xeyes</exec>
 +
 
 +
    <!-- Start gedit, maximize the window and show a text file -->
 +
    <exec seq="vnxtxt"    type="verbatim" ostype="system">chmod 666 /tmp/vnx.txt</exec>
 +
    <exec seq="vnxtxt"    type="verbatim" ostype="xexec">gedit /tmp/vnx.txt</exec>
 +
    <exec seq="vnxtxt"    type="verbatim" ostype="xexec">sleep 3; wmctrl -r vnx.txt -b add,maximized_vert,maximized_horz</exec>
 +
    <exec seq="vnxtxtoff" type="verbatim" ostype="system">pkill gedit; rm /tmp/vnx.*</exec>
 +
 
 +
    <!-- Start firefox and load vnx.html, copied by means of a <filetree> -->
 +
    <exec seq="vnxwww"    type="verbatim" ostype="system">chmod 666 /tmp/vnx.html</exec>
 +
    <exec seq="vnxwww"    type="verbatim" ostype="xexec">firefox /tmp/vnx.html</exec>
 +
    <exec seq="vnxwwwoff" type="verbatim" ostype="system">pkill firefox; rm /tmp/vnx.*</exec>
  
=== Modify root filesystem scenarios (root_fs_XXX.xml) ===
+
    <!-- Start calculator  -->
 +
    <exec seq="calc"      type="verbatim" ostype="xexec">gcalctool</exec>
 +
    <exec seq="calcoff"  type="verbatim" ostype="system">pkill gcalctool</exec>
  
To modify a root filesystem, for example, installing new software packages, just start the associated libvirt scenario with:
+
    <!-- Start/stop apache www server -->
  virsh create root_fs_XXX.xml
+
    <exec seq="start-www" type="verbatim" ostype="system">service apache2 start</exec>
 +
    <exec seq="stop-www" type="verbatim" ostype="system">service apache2 stop</exec>
 +
    <exec seq="start-www2" type="verbatim" ostype="exec">service apache2 start</exec>
 +
   
 +
    <exec seq="ping"      type="verbatim" ostype="system">'ping 10.0.0.1'</exec>
 +
    <exec seq="showlog"  type="verbatim" ostype="system">tail -f /var/log/vnxaced.log</exec>
 +
    <exec seq="start-www" type="verbatim" ostype="system">chmod 644 /var/www/*</exec>
  
And open the console using:
+
  </vm>
virt-viewer VMNAME
 
being VMNAME the name assigned to the virtual machine (you can get it with "virsh list" command or just looking for the <name> tag in root_fs_XXX.xml file).
 
  
To easy the process, you can use the vnx_modify_rootfs simple script that starts the virtual machine and opens the console:
+
  <host>
 +
    <hostif net="Net0">
 +
      <ipv4>10.0.0.1/24</ipv4>
 +
    </hostif>
 +
  </host>
 +
 
 +
</vnx>
  
/usr/share/vnx/bin/vnx_modify_rootfs root_fs_XXX.xml
+
</pre>

Latest revision as of 00:32, 13 February 2012

VNX Simple Scenarios

Description

Several simple example scenarios are included in VNX distribution to allow testing the tool functionalities with the different types of virtual machines supported (see /usr/share/vnx/examples/simple_*.xml files).

Each simple scenario includes just one virtual machine connected to a virtual network (Net0, 10.0.0.0/24), where the hosts has also a virtual network interface connected (10.0.0.1).

The simple scenarios are prepared to be started and tested individually or to be started all together to form the compound scenario shown in Figure 1.

Figure 1: simple scenarios topology

The following simple scenarios are available:

Scenario file name Description VM ip address
simple_uml.xml Just one User Mode Linux (UML) Debian system 10.0.0.2
simple_winxp.xml Just one KVM Windows XP system 10.0.0.3
simple_ubuntu.xml Just one KVM Ubuntu system without GUI 10.0.0.4
simple_ubuntu-gui.xml Just one KVM Ubuntu system with minimal GNOME GUI 10.0.0.5
simple_freebsd.xml Just one KVM FreeBSD system without GUI 10.0.0.6
simple_freebsd-gui.xml Just one KVM FreeBSD system with minimal GNOME GUI 10.0.0.7
simple_win7.xml Just one KVM Windows 7 system 10.0.0.8
simple_fedora.xml Just one KVM Fedora system without GUI 10.0.0.9
simple_fedora-gui.xml Just one KVM Fedora system with a GNOME GUI 10.0.0.10
simple_dynamips.xml Just one Dynamips emulated CISCO 3600 router 10.0.0.11
simple_dynamips2.xml Just one Dynamips emulated CISCO 7200 router 10.0.0.12
simple_olive.xml Just one Olive emulated Juniper router 10.0.0.13
simple_centos.xml Just one KVM CentOS system without GUI 10.0.0.15
simple_centos-gui.xml Just one KVM CentOS system with a GNOME GUI 10.0.0.16

All scenarios are available in /usr/share/vnx/examples directory. See, for example, the content of simple_ubuntu-gui.xml scenario at the end of this page

Starting a simple scenario

You can start VNX scenarios either from a local shell window or remotely using an SSH session with X-forwarding enabled. For example, if you connect to the VNX host from a Unix or MacOS system you can use:

  ssh -X <vnx-host-address-or-name>

If you connect from another system, just investigate how to configure your SSH client to do X-forwarding (most of them include it).

In case of remote connections, it is recommended to test that X-forwarding is working by launching a "xterm" or "xeyes" application and checking that the application window is correctly launched. Beware that X-forwarding is very bandwidth consuming, so you will need a good connectivity between your system and the host were VNX runs.

As VNX needs root priviledges, you have to be root in the shell window or, alternatively, if your account is allowed to "sudo" root (as typically is, for example, in Ubuntu systems), just precede vnx commands with "sudo", as shown below.

To start, for example, the simple_ubuntu-gui scenario:

cd /usr/share/vnx/examples/
sudo vnx -f simple_ubuntu-gui.xml -v --create

You will see the two virtual machine consoles opening: the graphical one showing the gnome desktop and the text console.

Figure 2: Graphical and textual consoles of simple_ubuntu-gui scenario

Beware that, once the virtual machine has completely started, the VNX autoconfiguration daemon (VNXACED) has to do its job configuring the name and the network interfaces parameters and restarting the machine for the changes to take effect. After that restart, the virtual machine is ready to be used.

Once started, you can test the network connectivity from the host to the virtual machine:

# ping -c 4 10.0.0.5
PING 10.0.0.5 (10.0.0.5) 56(84) bytes of data.
64 bytes from 10.0.0.5: icmp_seq=1 ttl=64 time=0.197 ms
64 bytes from 10.0.0.5: icmp_seq=2 ttl=64 time=0.188 ms
64 bytes from 10.0.0.5: icmp_seq=3 ttl=64 time=0.177 ms
64 bytes from 10.0.0.5: icmp_seq=4 ttl=64 time=0.171 ms

--- 10.0.0.5 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3001ms
rtt min/avg/max/mdev = 0.171/0.183/0.197/0.013 ms

If you close the consoles, you can reopen them with the following commands:

sudo vnx -f simple_ubuntu-gui.xml -v --console con0 -M ubuntu-gui
sudo vnx -f simple_ubuntu-gui.xml -v --console con1 -M ubuntu-gui

Or much simpler, you can use libvirt commands:

# sudo virsh list
 Id Nombre               Estado
----------------------------------
 31 ubuntu-gui           running
# virt-viewer 31 &                       # To open the graphical console
# xterm -e "sudo virsh console 31" &     # To open the text console

Beware that only one textual console can be used at a time. If you open a second one, you will experiment a strange behaviour as both consoles will compete for the pts terminal. On the contrary, you can open several graphical console simultaneously.

See VNX Console Management for more details.

Executing commands

You can also execute commands on the virtual machine from the host by means of the <exec> tags in the XML scenario specification:

For example, you can start the calculator or the xeyes application on the virtual machine by issuing:

sudo vnx -f simple_ubuntu-gui.xml -v --exe calc
sudo vnx -f simple_ubuntu-gui.xml -v --exe xeyes

Those commands execute what is defined in the <exec> tags with seq="calc" or seq="xeyes" respectively:

<!-- Start xeyes application -->
<exec seq="xeyes"    type="verbatim" ostype="xexec">xeyes</exec>

<!-- Start calculator  -->
<exec seq="calc"      type="verbatim" ostype="xexec">gcalctool</exec>
<exec seq="calcoff"   type="verbatim" ostype="system">pkill gcalctool</exec>

The "ostype" attribute is used to specify the type of command included in <exec> tag, either command line (CLI) or graphical (GUI), and whether vnx tool waits for command execution end or not. For values are posible:

ostype Type of commands Waits for command execution end
system CLI YES
exec CLI NO
xsystem GUI YES
xexec GUI NO

You can check, for example, the "xexec" value with:

sudo vnx -f simple_ubuntu-gui.xml -v --exe xeyes2

which executes the command:

<exec seq="xeyes2"    type="verbatim" ostype="xexec">xeyes</exec>

You will see the application xeyes opened in the virtual machine, but the command executed in the host will not end till the application is closed.

Or you can use a "system" command that closes (kills) all calc applications opened:

sudo vnx -f simple_ubuntu-gui.xml -v --exe calcoff

You can start or stop a web server in the virtual machine with:

sudo vnx -f /usr/share/vnx/examples/simple_ubuntu.xml -v --exe start-www
sudo vnx -f /usr/share/vnx/examples/simple_ubuntu.xml -v --exe stop-www

And test that the web server is running by manually opening a web navigator in the host and loading URL http://10.0.0.5. Alternativey, you can check the server availability with "nmap" tool:

# nmap -p 80 10.0.0.5

Starting Nmap 5.00 ( http://nmap.org ) at 2011-07-28 00:48 CEST
Interesting ports on 10.0.0.5:
PORT   STATE SERVICE
80/tcp open  http
MAC Address: 02:FD:00:05:01:01 (Unknown)

Nmap done: 1 IP address (1 host up) scanned in 0.40 seconds

Apart from the <exec> tags which define the commands used to start the web server ("service apache2 start"), the command sequence "start-www" includes a <filetree> tag to copy files from the host to the virtual machine that it is used to copy the initial web page shown by the server.

 <!-- Copy the content of conf/txtfile directory in the host to
      the /var/www directory in the virtual machine -->
 <filetree seq="start-www" root="/var/www">conf/txtfile</filetree>
 <!-- Start/stop apache www server -->
 <exec seq="start-www" type="verbatim" ostype="system">service apache2 start</exec>
 <exec seq="stop-www"  type="verbatim" ostype="system">service apache2 stop</exec>

You can find more example commands by having a look at <exec> and <filetree> tags in simple_ubuntu-gui.xml file or in other simple_*.xml examples. And more information about command execution in here.

Stopping the scenario

To stop the scenario preserving the changes made inside virtual machines you have to use the "-d" or "--shutdown" option:

sudo vnx -f simple_ubuntu-gui.xml -v --shutdown

You can later restart the scenario with:

sudo vnx -f simple_ubuntu-gui.xml -v --create

To stop the scenario discarding all the changes made in the virtual machine use the "-P" or "--destroy" option:

sudo vnx -f simple_ubuntu-gui.xml -v --destroy

Tipically, virtual machines in VNX are created using "Copy-on-write (COW)" filesystems to allow sharing a root filesystem among several virtual machines.

In the definition of the virtual machine:

<filesystem type="cow">/usr/share/vnx/filesystems/rootfs_ubuntu-gui</filesystem>

you specify the root filesystem to use (/usr/share/vnx/filesystems/rootfs_ubuntu-gui) and how it is mounted (cow). Using COW mode, the virtual machine will use the root filesystem in read-only mode and use another filesystem to save the files modified. When you use "-P|--destroy" option to stop an scenario, vnx deletes the filesystem with the modifications.

Other interesting options

You can see a graphical map of the virtual scenario using the --show-map option:

 sudo vnx -f simple_ubuntu-gui.xml -v --show-map
Figure 3: simple_ubuntu-gui scenario topology

simple_ubuntu-gui.xml scenario

<?xml version="1.0" encoding="UTF-8"?>

<!--
~~~~~~~~~~~~~~~~~~~~
VNX Sample scenarios
~~~~~~~~~~~~~~~~~~~~

Name:        simple_ubuntu-gui
Description: Just one Ubuntu virtual machine with GUI connected to a Network named Net0 with address 10.0.0.5. 
             The host has an interface in Net0 with address 10.0.0.1  
             This simple scenario is supposed to be used for testing the different 
             types of virtual machines supported by VNX. You can start several simple_*.xml
             scenarios and test the connectivity among virtual machines and the host, as all
             scenarios share the same "Net0" network.  

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 Ingenieria de Sistemas Telematicos (DIT)
Universidad Politecnica de Madrid
SPAIN
-->

<vnx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="/usr/share/xml/vnx/vnx-2.00.xsd">
  <global>
    <version>2.0</version>
    <scenario_name>simple_ubuntu-gui</scenario_name>
    <automac offset="5"/>
    <vm_mgmt type="none" />
    <vm_defaults>
	    <console id="0" display="yes"/>
	    <console id="1" display="yes"/>
    </vm_defaults>
  </global>
    
  <net name="Net0" mode="virtual_bridge" />
  
  <!-- NODES -->
  <vm name="ubuntu-gui" type="libvirt" subtype="kvm" os="linux">
    <filesystem type="cow">/usr/share/vnx/filesystems/rootfs_ubuntu-gui</filesystem>
    <mem>512M</mem>
    <if id="1" net="Net0">
      <ipv4>10.0.0.5/24</ipv4>
    </if>
    <filetree seq="vnxtxt" root="/tmp">conf/txtfile</filetree>
    <filetree seq="vnxwww" root="/tmp">conf/txtfile</filetree>
    <filetree seq="start-www" root="/var/www">conf/txtfile</filetree>

    <!-- Start xeyes application -->
    <exec seq="xeyes"     type="verbatim" ostype="xexec">xeyes</exec>

    <!-- Start xeyes application and wait until it is closed -->
    <exec seq="xeyes2"    type="verbatim" ostype="xsystem">xeyes</exec>

    <!-- Start gedit, maximize the window and show a text file -->
    <exec seq="vnxtxt"    type="verbatim" ostype="system">chmod 666 /tmp/vnx.txt</exec>
    <exec seq="vnxtxt"    type="verbatim" ostype="xexec">gedit /tmp/vnx.txt</exec>
    <exec seq="vnxtxt"    type="verbatim" ostype="xexec">sleep 3; wmctrl -r vnx.txt -b add,maximized_vert,maximized_horz</exec>
    <exec seq="vnxtxtoff" type="verbatim" ostype="system">pkill gedit; rm /tmp/vnx.*</exec>

    <!-- Start firefox and load vnx.html, copied by means of a <filetree> -->
    <exec seq="vnxwww"    type="verbatim" ostype="system">chmod 666 /tmp/vnx.html</exec>
    <exec seq="vnxwww"    type="verbatim" ostype="xexec">firefox /tmp/vnx.html</exec>
    <exec seq="vnxwwwoff" type="verbatim" ostype="system">pkill firefox; rm /tmp/vnx.*</exec>

    <!-- Start calculator  -->
    <exec seq="calc"      type="verbatim" ostype="xexec">gcalctool</exec>
    <exec seq="calcoff"   type="verbatim" ostype="system">pkill gcalctool</exec>

    <!-- Start/stop apache www server -->
    <exec seq="start-www" type="verbatim" ostype="system">service apache2 start</exec>
    <exec seq="stop-www"  type="verbatim" ostype="system">service apache2 stop</exec>
    <exec seq="start-www2" type="verbatim" ostype="exec">service apache2 start</exec>
    
    <exec seq="ping"      type="verbatim" ostype="system">'ping 10.0.0.1'</exec>
    <exec seq="showlog"   type="verbatim" ostype="system">tail -f /var/log/vnxaced.log</exec>
    <exec seq="start-www" type="verbatim" ostype="system">chmod 644 /var/www/*</exec>

  </vm>

  <host>
    <hostif net="Net0">
       <ipv4>10.0.0.1/24</ipv4>
    </hostif>
  </host>
  
</vnx>