Pass additional information from nova to Quantum

Some of the Quantum plugins will require this information

Change-Id: I957b5546b8c16d44d587bd73da975a1bb4a0b630
This commit is contained in:
Brad Hall 2011-12-11 19:56:39 +00:00
parent 67490c6b50
commit 5815efb158
3 changed files with 30 additions and 7 deletions

View File

@ -19,6 +19,7 @@ import time
from netaddr import IPNetwork, IPAddress
from nova.compute import instance_types
from nova import context
from nova import db
from nova import exception
@ -94,6 +95,12 @@ class QuantumManager(manager.FlatManager):
self.driver.ensure_metadata_ip()
self.driver.metadata_forward()
def _get_nova_id(self, context):
# When creating the network we need to pass in an identifier for
# this zone. Some Quantum plugins need this information in order
# to set up appropriate networking.
return FLAGS.node_availability_zone
def get_all_networks(self):
networks = []
admin_context = context.get_admin_context()
@ -121,14 +128,17 @@ class QuantumManager(manager.FlatManager):
" network is created per call"))
q_tenant_id = kwargs["project_id"] or FLAGS.quantum_default_tenant_id
quantum_net_id = uuid
# If a uuid was specified with the network it should have already been
# created in Quantum, so make sure.
if quantum_net_id:
if not self.q_conn.network_exists(q_tenant_id, quantum_net_id):
raise Exception(_("Unable to find existing quantum " \
" network for tenant '%(q_tenant_id)s' with "
"net-id '%(quantum_net_id)s'" % locals()))
else:
# otherwise, create network from default quantum pool
quantum_net_id = self.q_conn.create_network(q_tenant_id, label)
nova_id = self._get_nova_id(context)
quantum_net_id = self.q_conn.create_network(q_tenant_id, label,
nova_id=nova_id)
ipam_tenant_id = kwargs.get("project_id", None)
priority = kwargs.get("priority", 0)
@ -267,9 +277,16 @@ class QuantumManager(manager.FlatManager):
network_ref['id'])
# talk to Quantum API to create and attach port.
instance = db.instance_get(context, instance_id)
instance_type = instance_types.get_instance_type(instance_type_id)
rxtx_factor = instance_type['rxtx_factor']
nova_id = self._get_nova_id(context)
q_tenant_id = project_id or FLAGS.quantum_default_tenant_id
self.q_conn.create_and_attach_port(q_tenant_id, quantum_net_id,
vif_rec['uuid'])
vif_rec['uuid'],
vm_id=instance['uuid'],
rxtx_factor=rxtx_factor,
nova_id=nova_id)
# Tell melange to allocate an IP
ip = self.ipam.allocate_fixed_ip(context, project_id,
quantum_net_id, vif_rec)

View File

@ -52,11 +52,13 @@ class QuantumClientConnection(object):
format="json",
logger=LOG)
def create_network(self, tenant_id, network_name):
def create_network(self, tenant_id, network_name, **kwargs):
"""Create network using specified name, return Quantum
network UUID.
"""
data = {'network': {'name': network_name}}
for kw in kwargs:
data['network'][kw] = kwargs[kw]
resdict = self.client.create_network(data, tenant=tenant_id)
return resdict["network"]["id"]
@ -83,7 +85,8 @@ class QuantumClientConnection(object):
"""Retrieve all networks for this tenant"""
return self.client.list_networks(tenant=tenant_id)
def create_and_attach_port(self, tenant_id, net_id, interface_id):
def create_and_attach_port(self, tenant_id, net_id, interface_id,
**kwargs):
"""Creates a Quantum port on the specified network, sets
status to ACTIVE to enable traffic, and attaches the
vNIC with the specified interface-id.
@ -91,6 +94,8 @@ class QuantumClientConnection(object):
LOG.debug(_("Connecting interface %(interface_id)s to "
"net %(net_id)s for %(tenant_id)s" % locals()))
port_data = {'port': {'state': 'ACTIVE'}}
for kw in kwargs:
port_data['port'][kw] = kwargs[kw]
resdict = self.client.create_port(net_id, port_data, tenant=tenant_id)
port_id = resdict["port"]["id"]

View File

@ -49,7 +49,7 @@ class FakeQuantumClientConnection(object):
net_ids.append(net_id)
return {'networks': net_ids}
def create_network(self, tenant_id, network_name):
def create_network(self, tenant_id, network_name, **kwargs):
uuid = str(utils.gen_uuid())
self.nets[uuid] = {'net-name': network_name,
@ -77,7 +77,8 @@ class FakeQuantumClientConnection(object):
raise Exception(_("interface '%s' is already attached" %
interface_id))
def create_and_attach_port(self, tenant_id, net_id, interface_id):
def create_and_attach_port(self, tenant_id, net_id, interface_id,
**kwargs):
if not self.network_exists(tenant_id, net_id):
raise Exception(
_("network %(net_id)s does not exist for tenant %(tenant_id)"