8727779308
Object of SubnetList can not be created, as subnet is reassigned. Change-Id: I0e105642e01a7fb66df02b0f396ce0eb706ce30b
2.3 KiB
2.3 KiB
Usage
The interface to the os_vif
library is very simple. To
begin using the library, first call the os_vif.initialize()
function. This will load all installed plugins and register the object
model:
import os_vif
os_vif.initialize()
Once the os_vif
library is initialized, there are only
two other library functions: os_vif.plug()
and
os_vif.unplug()
. Both methods accept an argument of (a
subclass of) type os_vif.objects.vif.VIFBase
and an
argument of type
os_vif.objects.instance_info.InstanceInfo
:
import uuid
from nova import objects as nova_objects
from os_vif import exception as vif_exc
from os_vif.objects import fields
from os_vif.objects import instance_info
from os_vif.objects import network
from os_vif.objects import subnet as os_subnet
from os_vif.objects import vif as vif_obj
= 'd7a730ca-3c28-49c3-8f26-4662b909fe8a'
instance_uuid = nova_objects.Instance.get_by_uuid(instance_uuid)
instance = instance_info.InstanceInfo(
instance_info =instance.uuid,
uuid=instance.name,
name=instance.project_id)
project_id
= os_subnet.Subnet(cidr='192.168.1.0/24')
subnet = os_subnet.SubnetList([subnet])
subnets = network.Network(label='tenantnet',
network =subnets,
subnets=False,
multi_host=False,
should_provide_vlan=False)
should_provide_bridge
= uuid.uuid4()
vif_uuid = vif_obj.VIFVHostUser(id=vif_uuid,
vif =None,
address=network,
network='vhostuser',
plugin='/path/to/socket',
path=fields.VIFVHostUserMode.SERVER)
mode
# Now do the actual plug operations to connect the VIF to
# the backing network interface.
try:
os_vif.plug(vif, instance_info)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, instance_info)except vif_exc.UnplugException as err:
# Handle the failure...