Managing Virtual Networks 3.4

A host is connected to one or more networks that are available to the virtual machines through the corresponding bridges. OpenNebula allows the creation of Virtual Networks by mapping them on top of the physical ones

inlinetoc

Overview

In this guide you'll learn how to define and use virtual networks. For the sake of simplicity the following examples assume that the hosts are attached to two physical networks:

  • A private network, through the virtual bridge vbr0
  • A network with Internet connectivity, through vbr1

This guide uses the CLI command onevnet, but you can also manage your virtual networks using Sunstone. Select the Network tab, and there you will be able to create and manage your virtual networks in a user friendly way.

Adding and Deleting Virtual Networks

To set up a virtual network you just need to know the name of the bridge to bind the virtual machines to, and decide the IP addresses (the leases) that the VNet will contain.

New Virtual Networks are defined in a Virtual Network template file. The onevnet command is used to create a VNet from that template.

As an example, we will create two new VNets, Blue and Red. Lets assume we have two files, blue.net and red.net.

Blue.net file:

NAME    = "Blue LAN"
TYPE    = FIXED
 
# We have to bind this network to ''virbr1'' for Internet Access
BRIDGE  = vbr1
 
LEASES  = [IP=130.10.0.1]
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]
 
# Custom Attributes to be used in Context
GATEWAY = 130.10.0.1
DNS     = 130.10.0.1
 
LOAD_BALANCER = 130.10.0.4

And red.net file:

NAME    = "Red LAN"
TYPE    = RANGED
 
# Now we'll use the host private network (physical)
BRIDGE  = vbr0
 
NETWORK_SIZE    = C
NETWORK_ADDRESS = 192.168.0.0
 
# Custom Attributes to be used in Context
GATEWAY = 192.168.0.1
DNS     = 192.168.0.1
 
LOAD_BALANCER = 192.168.0.3

Once the files have been created, we can create the VNets executing:

<xterm> $ onevnet create blue.net ID: 0 $ onevnet create red.net ID: 1 </xterm>

Also, onevnet can be used to query OpenNebula about available VNets: <xterm> $ onevnet list

ID USER     GROUP    NAME            CLUSTER    TYPE BRIDGE  LEASES
 0 oneadmin oneadmin Blue LAN        -             F   vbr1       0
 1 oneadmin oneadmin Red LAN         -             R   vbr0       0

</xterm>

In the output above, USER is 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>

You can also check the IPs leased in a network with the onevnet show command

Check the onevnet command help or the reference guide for more options to list the virtual networks.

Managing Virtual Networks

Adding and Removing Leases

You can add and remove leases to existing FIXED virtual networks (see the template file reference for more info on the network types). To do so, use the onevnet addleases and onevnet rmleases commands.

The new lease can be added specifying its IP and, optionally, its MAC. If the lease already exists, the action will fail.

<xterm> $ onevnet addleases 0 130.10.0.10 $ onevnet addleases 0 130.10.0.11 50:20:20:20:20:31 $ $ onevnet addleases 0 130.10.0.1 [VirtualNetworkAddLeases] Error modifiying network leases. Error inserting lease, IP 130.10.0.1 already exists </xterm>

To remove existing leases from the network, they must be free (i.e., not used by any VM).

<xterm> $ onevnet rmleases 0 130.10.0.3 </xterm>

Hold and Release Leases

Leases can be temporarily be marked “on hold” state. These leases are reserved, they are part of the network, but they will not be assigned to any VM.

To do so, use the 'onevnet hold' and 'onevnet release' commands. You see the the list of leases on hold with the 'onevnet show' command.

<xterm> $ onevnet hold “Blue LAN” 130.10.0.1 $ onevnet hold 0 130.10.0.4 </xterm>

Lease management in Sunstone

If you are using the Sunstone GUI, you can then easily add, remove, hold and release leases from the dialog of extended information of a Virtual Network. You can open this dialog by clicking the desired element on the Virtual Network table, as you can see in this picture:

Update the Virtual Network Template

The TEMPLATE section can hold any arbitrary data. You can use the onevnet update command to open an editor and edit or add new template attributes. These attributes can be later used in the Virtual Machine Contextualization. For example:

dns = "$NETWORK[DNS, NETWORK_ID=3]"

Publishing Virtual Networks

The users can share their virtual networks with other users in their group, or with all the users in OpenNebula. See the Managing Permissions documentation for more information.

Let's see a quick example. To share the virtual network 0 with users in the group, the USE right bit for GROUP must be set with the chmod command:

<xterm> $ onevnet show 0 … PERMISSIONS OWNER : um- GROUP : — OTHER : —

$ onevnet chmod 0 640

$ onevnet show 0 … PERMISSIONS OWNER : um- GROUP : u– OTHER : — </xterm>

The following command allows users in the same group USE and MANAGE the virtual network, and the rest of the users USE it:

<xterm> $ onevnet chmod 0 664

$ onevnet show 0 … PERMISSIONS OWNER : um- GROUP : um- OTHER : u– </xterm>

The commands onevnet publish and onevnet unpublish are still present for compatibility with previous versions. These commands set/unset

Getting a Lease

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 Blue LAN just include in the template:

NIC = [ NETWORK_ID = 0 ]
NIC = [ NETWORK    = "Red LAN" ]

Networks can be referred in a NIC in two different ways, see the Simplified Virtual Machine Definition File documentation for more information:

  • NETWORK_ID, using its ID as returned by the create operation
  • NETWORK, using its name. In this case the name refers to one of the virtual networks owned by the user (names can not be repeated for the same user). If you want to refer to an NETWORK of other user you can specify that with NETWORK_UID (by the uid of the user) or NETWORK_UNAME (by the name of the user).

You can also request a specific address just by adding the IP attributes to NIC:

NIC = [ NETWORK_ID = 1, IP = 192.168.0.3 ]

When the VM is submitted, OpenNebula will look for available IPs in the Blue LAN and Red LAN virtual networks. The leases on hold will be skipped. If successful, the onevm show command should return information about the machine, including network information.

<xterm> $ onevm show 0 VIRTUAL MACHINE 0 INFORMATION ID : 0 NAME : server USER : oneadmin GROUP : oneadmin STATE : PENDING LCM_STATE : LCM_INIT START TIME : 12/13 06:59:07 END TIME : - DEPLOY ID : -

PERMISSIONS OWNER : um- GROUP : — OTHER : —

VIRTUAL MACHINE MONITORING NET_TX : 0 NET_RX : 0 USED MEMORY : 0 USED CPU : 0

VIRTUAL MACHINE TEMPLATE NAME=server NIC=[

BRIDGE=vbr1,
IP=130.10.0.2,
MAC=50:20:20:20:20:21,
NETWORK="Blue LAN",
NETWORK_ID=0,
VLAN=NO ]

NIC=[

BRIDGE=vbr0,
IP=192.168.0.2,
MAC=00:03:c0:a8:00:02,
NETWORK="Red LAN",
NETWORK_ID=1,
VLAN=NO ]

VMID=0 </xterm>

:!: Note that if OpenNebula is not able to obtain a lease from a network the submission will fail.

Now we can query OpenNebula with onevnet show to find out about given leases and other VNet information:

<xterm> $ onevnet list

ID USER     GROUP    NAME            CLUSTER    TYPE BRIDGE  LEASES
 0 oneadmin oneadmin Blue LAN        -             F   vbr1       3
 1 oneadmin oneadmin Red LAN         -             R   vbr0       3

</xterm>

Note that there are two LEASES on hold, and one LEASE used in each network

<xterm> $ onevnet show 1 VIRTUAL NETWORK 1 INFORMATION ID : 1 NAME : Red LAN USER : oneadmin GROUP : oneadmin TYPE : RANGED BRIDGE : vbr0 VLAN : No PHYSICAL DEVICE: VLAN ID : USED LEASES : 3

PERMISSIONS OWNER : um- GROUP : — OTHER : —

VIRTUAL NETWORK TEMPLATE DNS=192.168.0.1 GATEWAY=192.168.0.1 LOAD_BALANCER=192.168.0.3 NETWORK_MASK=255.255.255.0

RANGE IP_START : 192.168.0.1 IP_END : 192.168.0.254

LEASES ON HOLD LEASE=[ IP=192.168.0.1, MAC=00:03:c0:a8:00:01, USED=1, VID=-1 ] LEASE=[ IP=192.168.0.3, MAC=00:03:c0:a8:00:03, USED=1, VID=-1 ]

USED LEASES LEASE=[ IP=192.168.0.2, MAC=00:03:c0:a8:00:02, USED=1, VID=0 ] </xterm>

:!: IP 192.168.0.2 is in use by Virtual Machine 0

Apply Firewall Rules to VMs

You can apply firewall rules on your VMs, to filter TCP and UDP ports, and to define a policy for ICMP connections.

Read more about this feature here.

Using the Leases within the Virtual Machine

Hypervisors can attach a specific MAC address to a virtual network interface, but Virtual Machines need to obtain an IP address. Please visit the contextualization guide to learn how to configure your Virtual Machines to automatically obtain an IP derived from the MAC.