Changes to incorporate reviwer's comments. Also changed client.py to handle extension URLs.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
"""
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
# Copyright 2011 Cisco Systems, Inc. All rights reserved.
|
||||
#
|
||||
@@ -16,19 +15,20 @@
|
||||
#
|
||||
# @author: Sumit Naiksatam, Cisco Systems, Inc.
|
||||
#
|
||||
"""
|
||||
|
||||
"""VIF drivers for interface type direct."""
|
||||
|
||||
from nova import exception as excp
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova import utils
|
||||
from nova.network import linux_net
|
||||
from nova.virt.libvirt import netutils
|
||||
from nova import utils
|
||||
from nova.virt.vif import VIFDriver
|
||||
from quantum.client import Client
|
||||
from quantum.common.wsgi import Serializer
|
||||
|
||||
LOG = logging.getLogger('nova.virt.libvirt.vif')
|
||||
LOG = logging.getLogger('quantum.plugins.cisco.nova.vifdirect')
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
flags.DEFINE_string('quantum_host', "127.0.0.1",
|
||||
@@ -40,10 +40,34 @@ HOST = FLAGS.quantum_host
|
||||
PORT = FLAGS.quantum_port
|
||||
USE_SSL = False
|
||||
TENANT_ID = 'nova'
|
||||
ACTION_PREFIX_EXT = '/v0.1'
|
||||
ACTION_PREFIX_CSCO = ACTION_PREFIX_EXT + \
|
||||
'/extensions/csco/tenants/{tenant_id}'
|
||||
TENANT_ID = 'nova'
|
||||
CSCO_EXT_NAME = 'Cisco Nova Tenant'
|
||||
|
||||
|
||||
class Libvirt802dot1QbhDriver(VIFDriver):
|
||||
"""VIF driver for Linux bridge."""
|
||||
def __init__(self):
|
||||
# We have to send a dummy tenant name here since the client
|
||||
# needs some tenant name, but the tenant name will not be used
|
||||
# since the extensions URL does not require it
|
||||
client = Client(HOST, PORT, USE_SSL, format='json',
|
||||
action_prefix=ACTION_PREFIX_EXT, tenant="dummy")
|
||||
request_url = "/extensions"
|
||||
data = client.do_request('GET', request_url)
|
||||
LOG.debug("Obtained supported extensions from Quantum: %s" % data)
|
||||
for ext in data['extensions']:
|
||||
name = ext['name']
|
||||
if name == CSCO_EXT_NAME:
|
||||
LOG.debug("Quantum plugin supports required \"%s\" extension"
|
||||
"for the VIF driver." % name)
|
||||
return
|
||||
LOG.error("Quantum plugin does not support required \"%s\" extension"
|
||||
" for the VIF driver. nova-compute will quit." \
|
||||
% CSCO_EXT_NAME)
|
||||
raise excp.ServiceUnavailable()
|
||||
|
||||
def _get_configurations(self, instance, network, mapping):
|
||||
"""Gets the device name and the profile name from Quantum"""
|
||||
@@ -51,22 +75,26 @@ class Libvirt802dot1QbhDriver(VIFDriver):
|
||||
instance_id = instance['id']
|
||||
user_id = instance['user_id']
|
||||
project_id = instance['project_id']
|
||||
vif_id = mapping['vif_uuid']
|
||||
|
||||
instance_data_dict = \
|
||||
{'novatenant': \
|
||||
{'instance-id': instance_id,
|
||||
'instance-desc': \
|
||||
{'user_id': user_id, 'project_id': project_id}}}
|
||||
{'instance_id': instance_id,
|
||||
'instance_desc': \
|
||||
{'user_id': user_id,
|
||||
'project_id': project_id,
|
||||
'vif_id': vif_id
|
||||
}}}
|
||||
|
||||
client = Client(HOST, PORT, USE_SSL, format='json')
|
||||
client = Client(HOST, PORT, USE_SSL, format='json', tenant=TENANT_ID,
|
||||
action_prefix=ACTION_PREFIX_CSCO)
|
||||
request_url = "/novatenants/" + project_id + "/get_instance_port"
|
||||
data = client.do_request(TENANT_ID, 'PUT', request_url,
|
||||
body=instance_data_dict)
|
||||
data = client.do_request('PUT', request_url, body=instance_data_dict)
|
||||
|
||||
device = data['vif_desc']['device']
|
||||
portprofile = data['vif_desc']['portprofile']
|
||||
|
||||
LOG.debug(_("Quantum returned device: %s\n") % device)
|
||||
LOG.debug(_("Quantum returned portprofile: %s\n") % portprofile)
|
||||
LOG.debug(_("Quantum provided the device: %s") % device)
|
||||
LOG.debug(_("Quantum provided the portprofile: %s") % portprofile)
|
||||
mac_id = mapping['mac'].replace(':', '')
|
||||
|
||||
result = {
|
||||
|
||||
Reference in New Issue
Block a user