From 51ad3d4ee9f28184510a2802867535284c0f1b8b Mon Sep 17 00:00:00 2001 From: Nachi Ueno Date: Tue, 31 Jul 2012 17:47:02 +0000 Subject: Adding port attribute in network parameter of boot. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Example is (network:[{‘port’:}] ) The specified port will be used. A port who have already device_id can not be used to be boot. This fix is for isolating functionalities between Quantum and Nova. There are no need update nova side if port model will be changed in future quantum model. This function is for QuantumV2 api use only. Added port attribute in requested_network attribute. Fixes bug 1031096. Change-Id: Id2c86228edb0c22f536f8b36a955c87870e9d98b --- nova/api/openstack/compute/servers.py | 49 ++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 12 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index 99d48d8a6..0c5a2e530 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -197,6 +197,8 @@ class CommonDeserializer(wsgi.MetadataXMLDeserializer): item["uuid"] = network_node.getAttribute("uuid") if network_node.hasAttribute("fixed_ip"): item["fixed_ip"] = network_node.getAttribute("fixed_ip") + if network_node.hasAttribute("port"): + item["port"] = network_node.getAttribute("port") networks.append(item) return networks else: @@ -498,14 +500,31 @@ class Controller(wsgi.Controller): injected_files.append((path, contents)) return injected_files + def _is_quantum_v2(self): + return FLAGS.network_api_class ==\ + "nova.network.quantumv2.api.API" + def _get_requested_networks(self, requested_networks): """Create a list of requested networks from the networks attribute.""" networks = [] for network in requested_networks: try: - network_uuid = network['uuid'] + port_id = network.get('port', None) + if port_id: + network_uuid = None + if not self._is_quantum_v2(): + # port parameter is only for qunatum v2.0 + msg = _("Unknown argment : port") + raise exc.HTTPBadRequest(explanation=msg) + if not utils.is_uuid_like(port_id): + msg = _("Bad port format: port uuid is " + "not in proper format " + "(%s)") % port_id + raise exc.HTTPBadRequest(explanation=msg) + else: + network_uuid = network['uuid'] - if not utils.is_uuid_like(network_uuid): + if not port_id and not utils.is_uuid_like(network_uuid): br_uuid = network_uuid.split('-', 1)[-1] if not utils.is_uuid_like(br_uuid): msg = _("Bad networks format: network uuid is " @@ -520,16 +539,22 @@ class Controller(wsgi.Controller): if address is not None and not utils.is_valid_ipv4(address): msg = _("Invalid fixed IP address (%s)") % address raise exc.HTTPBadRequest(explanation=msg) - # check if the network id is already present in the list, - # we don't want duplicate networks to be passed - # at the boot time - for id, ip in networks: - if id == network_uuid: - expl = (_("Duplicate networks (%s) are not allowed") % - network_uuid) - raise exc.HTTPBadRequest(explanation=expl) - - networks.append((network_uuid, address)) + + # For quantumv2, requestd_networks + # should be tuple of (network_uuid, fixed_ip, port_id) + if self._is_quantum_v2(): + networks.append((network_uuid, address, port_id)) + else: + # check if the network id is already present in the list, + # we don't want duplicate networks to be passed + # at the boot time + for id, ip in networks: + if id == network_uuid: + expl = (_("Duplicate networks" + " (%s) are not allowed") % + network_uuid) + raise exc.HTTPBadRequest(explanation=expl) + networks.append((network_uuid, address)) except KeyError as key: expl = _('Bad network format: missing %s') % key raise exc.HTTPBadRequest(explanation=expl) -- cgit