Integration library between network (Neutron) and compute (Nova) providers
Go to file
Daniel P. Berrange 11af752a5a Add formal classes for each of the types of VIF backend config
The current VIF object model is just a direct representation
of the ill-defined nova.network.model.VIF class. Many of the
attributes are only relevant for certain VIF types. Other
attributes are just indirectly representing different plugin
schemes (eg OVS hybrid vs direct should be done as two
plugins, not a boolean on the VIF object).

Some of the attributes are generic metadata related to the
network port that can be associated with multiple VIF types
regardless of how the port is connected to the guest.

This refactors the VIF class so that there is a base class
defining the common data, and then subclasses providing the
VIF type specific data. There are initially 5 core VIF backend
class defined, which are sufficient to cover all the current
usage in the libvirt driver and some usage in other drivers.
It is expected that a couple more VIF types may be added for
vmware/hyper, when those drivers are later converted. The
generic network port profile data is represented by the new
VIFPortProfileBase class and its subclasses.

The various property/methods which were defined are also
removed as most of this is logic that belongs in the
corresponding vif plugin implementation, not on the core
data model.

Change-Id: Id286f85cd5fe7ca80f02d95f6380979a0d920ef6
2016-01-28 16:12:18 +00:00
doc/source Import of code from https://github.com/jaypipes/os_vif 2016-01-13 12:56:01 -05:00
os_vif Add formal classes for each of the types of VIF backend config 2016-01-28 16:12:18 +00:00
.coveragerc Import of code from https://github.com/jaypipes/os_vif 2016-01-13 12:56:01 -05:00
.gitignore Import of code from https://github.com/jaypipes/os_vif 2016-01-13 12:56:01 -05:00
.gitreview Added .gitreview 2015-11-11 16:10:58 +00:00
.mailmap Import of code from https://github.com/jaypipes/os_vif 2016-01-13 12:56:01 -05:00
.testr.conf Import of code from https://github.com/jaypipes/os_vif 2016-01-13 12:56:01 -05:00
CONTRIBUTING.rst Import of code from https://github.com/jaypipes/os_vif 2016-01-13 12:56:01 -05:00
HACKING.rst Import of code from https://github.com/jaypipes/os_vif 2016-01-13 12:56:01 -05:00
LICENSE Import of code from https://github.com/jaypipes/os_vif 2016-01-13 12:56:01 -05:00
MANIFEST.in Import of code from https://github.com/jaypipes/os_vif 2016-01-13 12:56:01 -05:00
README.rst Add formal classes for each of the types of VIF backend config 2016-01-28 16:12:18 +00:00
babel.cfg Import of code from https://github.com/jaypipes/os_vif 2016-01-13 12:56:01 -05:00
openstack-common.conf Import of code from https://github.com/jaypipes/os_vif 2016-01-13 12:56:01 -05:00
requirements.txt don't catch ProcessExecutionError exception as special case 2016-01-18 13:32:33 +00:00
setup.cfg remove python 2.6 trove classifier 2016-01-14 19:50:08 +00:00
setup.py Import of code from https://github.com/jaypipes/os_vif 2016-01-13 12:56:01 -05:00
test-requirements.txt Import of code from https://github.com/jaypipes/os_vif 2016-01-13 12:56:01 -05:00
tox.ini reorder tox envlist to run python 3.4 before 2.7 2016-01-14 19:45:08 +00:00

README.rst

os-vif

A library for plugging and unplugging virtual interfaces in OpenStack.

Features

  • A base VIF plugin class that supplies a plug() and unplug() interface
  • Versioned objects that represent a virtual interface and its components

Usage

The interface to the os_vif library is very simple. To begin using the library, first call the os_vif.initialize() function, supplying a set of keyword arguments for configuration options:

import os_vif

os_vif.initialize(libvirt_virt_type='kvm',
                  network_device_mtu=1500,
                  vlan_interface='eth1',
                  use_ipv6=False,
                  iptables_top_regex='',
                  iptables_bottom_regex='',
                  iptables_drop_action='DROP',
                  forward_bridge_interface=['all'])

Once the os_vif library is initialized, there are only two other library functions: os_vif.plug() and os_vif.unplug(). Both methods accept a single argument of type `os_vif.objects.VIF`:

import uuid

from nova import objects as nova_objects
from os_vif import exception as vif_exc
from os_vif import objects as vif_objects
from os_vif import vnic_types

instance_uuid = 'd7a730ca-3c28-49c3-8f26-4662b909fe8a'
instance = nova_objects.Instance.get_by_uuid(instance_uuid)
instance_info = vif_objects.InstanceInfo(
    uuid=instance.uuid,
    name=instance.name,
    project_id=instance.project_id)

subnet = vif_objects.Subnet(cidr='192.168.1.0/24')
subnets = vif_objects.SubnetList([subnet])
network = vif_objects.Network(label='tenantnet',
                              subnets=subnets,
                              multi_host=False,
                              should_provide_vlan=False,
                              should_provide_bridge=False)

vif_uuid = uuid.uuid4()
vif = vif_objects.VIFVHostUser(id=vif_uuid,
                               address=None,
                               network=network,
                               plugin='vhostuser',
                               path='/path/to/socket',
                               mode=vif_objects.fields.VIFVHostUserMode.SERVER)

# Now do the actual plug operations to connect the VIF to
# the backing network interface.
try:
    os_vif.plug(vif)
except vif_exc.PlugException as err:
    # Handle the failure...

# If you are removing a virtual machine and its interfaces,
# you would use the unplug() operation:
try:
    os_vif.unplug(vif)
except vif_exc.UnplugException as err:
    # Handle the failure...