Managing Virtual Networks 1.4
A cluster node is connected to one or more networks that are available to the virtual machines through the corresponding bridges. To set up a virtual networks you just need to know the name of the bridge to bind the virtual machines to.
In this guide you'll learn how to define and use virtual networks. For the sake of completeness the following examples assumes that the cluster nodes are attached to two physical networks:
OpenNebula allows for the creation of Virtual Networks by mapping them on top of the physical ones. All Virtual Networks are going to share a default value for the MAC preffix, set in the oned.conf
file.
There are two types of Virtual Networks in OpenNebula:
oneadmin
can be used by every other user.
A fixed network consists of a set of IP addresses and associated MACs, defined in a text file.
We need four pieces of information to define a fixed VN:
MAC = MAC_PREFFIX:IP
. So, for example, from IP 10.0.0.1 and MAC_PREFFIX 00:16, we get 00:16:0a:00:00:01. Defining only a MAC address with no associated IP is not allowed.
For example to create a Fixed Virtual Network, called Public
with the set of public IPs to be used by the VMs, just create a file with the following contents:
NAME = "Public" TYPE = FIXED #We have to bind this network to ''virbr1'' for Internet Access BRIDGE = vbr1 LEASES = [IP=130.10.0.1, MAC=50:20:20:20:20:20] LEASES = [IP=130.10.0.2, MAC=50:20:20:20:20:21] LEASES = [IP=130.10.0.3] LEASES = [IP=130.10.0.4]
This type of VNs allows for a definition supported by a base network address and a size. So we need to define:
The following is an example of a Ranged Virtual Network template:
NAME = "Red LAN" TYPE = RANGED #Now we'll use the cluster private network (physical) BRIDGE = vbr0 NETWORK_SIZE = C NETWORK_ADDRESS = 192.168.0.0
Default value for the network size can be found in oned.conf
.
Once a template for a VN has been defined, the onevnet
command can be used to create it.
To create the previous networks put their definitions in two different files, public.net
and red.net
, respectively. Then, execute:
<xterm> $ onevnet -v create public.net $ onevnet -v create red.net </xterm>
Also, onevnet
can be used to query OpenNebula about available VNs:
<xterm>
$ onevnet list
NID USER NAME TYPE BRIDGE #LEASES
2 oneadmin Public Fixed vbr1 0 3 oneadmin Red LAN Ranged vbr0 0
</xterm>
with USER
the owner of the network and #LEASES
the number of IP-MACs assigned to a VM from this network.
To delete a virtual network just use onevnet delete
. For example to delete the previous networks:
<xterm> $onevnet delete 2 $onevnet delete 'Red LAN' </xterm>
onevnet show
command
Check the onevnet
command help or reference guide for more options to list the virtual networks.
A lease from a virtual network can be obtained by simply specifying the virtual network name in the NIC
attribute.
For example, to define VM with two network interfaces, one connected to Red LAN
and other connected to Public
just include in the template:
NIC=[NETWORK="Public"] NIC=[NETWORK="Red LAN"]
You can also request an specific address just by adding the IP
or MAC
attributes to NIC
:
NIC=[NETWORK="Red LAN", IP=192.168.0.3]
When the VM is submitted, OpenNebula will look for available IPs in the Public
and Red LAN
virtual networks. If successful, the onevm show
command should return information about the machine, including network information.
<xterm>
$ onevm show 12
VIRTUAL MACHINE 12 INFORMATION
ID : 12
NAME : server
STATE : PENDING
LCM_STATE : LCM_INIT
START TIME : 07/15 15:30:53
END TIME : -
DEPLOY ID: : -
VIRTUAL MACHINE TEMPLATE NAME=server NIC=[
BRIDGE=vbr1, IP=130.10.0.1, MAC=50:20:20:20:20:20, NETWORK=Public, VNID=5 ]
NIC=[
BRIDGE=eth0, IP=192.168.0.1, MAC=00:03:c0:a8:00:01, NETWORK=Red LAN, VNID=4 ]
VMID=12 </xterm>
Now we can query OpenNebula with onevnet show
to find out about given leases and other VN information:
<xterm> $ onevnet list NID USER NAME TYPE BRIDGE #LEASES
2 onedmin Red LAN Ranged vbr0 1 3 oneamdin Public Fixed vbr1 1
</xterm>
<xterm> $ onevnet show 4 VIRTUAL NETWORK 4 INFORMATION ID: : 4 UID: : 0
VIRTUAL NETWORK TEMPLATE BRIDGE=eth0 NAME=Red LAN NETWORK_ADDRESS=192.168.0.0 NETWORK_SIZE=C TYPE=RANGED
LEASES INFORMATION LEASE=[ IP=192.168.0.1, MAC=00:03:c0:a8:00:01, USED=1, VID=12 ] </xterm>
Hypervisors can attach a specific MAC address to a virtual network interface, but Virtual Machines need to obtain an IP address. There are a variety of ways to achieve this within OpenNebula:
CONTEXT
attribute, check the Contextualization Guide With OpenNebula you can also derive the IP address from the MAC address using the MAC_PREFFIX:IP rule. In order to achieve this we provide a context script for Debian based systems. This script can be easily adapted for other distributions, check dev.opennebula.org.
To configure the Virtual Machine follow these steps:
$ONE_LOCATION/share/scripts/vmcontext.sh
into the /etc/init.d
directory in the VM root file system.<xterm> $ ln /etc/init.d/vmcontext.sh /etc/rc2.d/S01vmcontext.sh </xterm>
Having done so, whenever the VN boots it will execute this script, which in turn would scan the available network interfaces, extract their MAC addresses, make the MAC to IP conversion and construct a /etc/network/interfaces
that will ensure the correct IP assignment to the corresponding interface.