diff options
| author | Jenkins <jenkins@review.openstack.org> | 2011-12-14 20:08:24 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2011-12-14 20:08:24 +0000 |
| commit | c178043d3021548111a7d7ae4a53210fd96cc1bf (patch) | |
| tree | 6086eb14da6fa8fa7f2af726a7cb711cc7eda160 | |
| parent | af54e79b7815c233c6e800bc79e428fe23f92eb7 (diff) | |
| parent | 5815efb158d8dc7f9f435ce96ab4f4caa599a640 (diff) | |
Merge "Pass additional information from nova to Quantum"
| -rw-r--r-- | nova/network/quantum/manager.py | 23 | ||||
| -rw-r--r-- | nova/network/quantum/quantum_connection.py | 9 | ||||
| -rw-r--r-- | nova/tests/test_quantum.py | 5 |
3 files changed, 30 insertions, 7 deletions
diff --git a/nova/network/quantum/manager.py b/nova/network/quantum/manager.py index 86ee5e3da..fc38f007e 100644 --- a/nova/network/quantum/manager.py +++ b/nova/network/quantum/manager.py @@ -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) diff --git a/nova/network/quantum/quantum_connection.py b/nova/network/quantum/quantum_connection.py index 989a0a185..d3b403822 100644 --- a/nova/network/quantum/quantum_connection.py +++ b/nova/network/quantum/quantum_connection.py @@ -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"] diff --git a/nova/tests/test_quantum.py b/nova/tests/test_quantum.py index 37a3ea465..8e8a8511c 100644 --- a/nova/tests/test_quantum.py +++ b/nova/tests/test_quantum.py @@ -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)" |
