diff options
author | Vishvananda Ishaya <vishvananda@gmail.com> | 2013-01-17 12:42:24 -0800 |
---|---|---|
committer | Vishvananda Ishaya <vishvananda@gmail.com> | 2013-01-31 15:38:17 -0800 |
commit | 45e92d47038514fc05ae17a8a38dae1b337c15fe (patch) | |
tree | 380c42ba080cbd8e1fea82280e87ce3528fe2cd0 | |
parent | 05751bb7861892b949dedeccc283ce48abee0d16 (diff) | |
download | nova-45e92d47038514fc05ae17a8a38dae1b337c15fe.tar.gz nova-45e92d47038514fc05ae17a8a38dae1b337c15fe.tar.xz nova-45e92d47038514fc05ae17a8a38dae1b337c15fe.zip |
Optimize network calls by moving them to api
Now that quantumv2 replaces api, there is no need for many of the
network calls to go over rpc. This patch optimizes them by moving
the implementation into the api class. Note that the old methods
are left in place to keep rpcapi compatibility.
This patch also adds api_deprecated in case anyone is using a
custom out-of-tree manager class. It is possible to set:
network_api_class=nova.network.api_deprecated.API
to get the old functionality.
Part of blueprint optimize-nova-network
Change-Id: I130908df060246e8a5f3711cf16d1c49ee3e2664
-rw-r--r-- | nova/api/openstack/compute/contrib/floating_ips.py | 4 | ||||
-rw-r--r-- | nova/network/api.py | 60 | ||||
-rw-r--r-- | nova/network/api_deprecated.py | 465 | ||||
-rw-r--r-- | nova/network/manager.py | 38 | ||||
-rw-r--r-- | nova/tests/integrated/test_api_samples.py | 3 |
5 files changed, 546 insertions, 24 deletions
diff --git a/nova/api/openstack/compute/contrib/floating_ips.py b/nova/api/openstack/compute/contrib/floating_ips.py index 3f00136f5..81b8c3dc0 100644 --- a/nova/api/openstack/compute/contrib/floating_ips.py +++ b/nova/api/openstack/compute/contrib/floating_ips.py @@ -67,11 +67,11 @@ def _translate_floating_ip_view(floating_ip): } try: result['fixed_ip'] = floating_ip['fixed_ip']['address'] - except (TypeError, KeyError): + except (TypeError, KeyError, AttributeError): result['fixed_ip'] = None try: result['instance_id'] = floating_ip['instance']['uuid'] - except (TypeError, KeyError): + except (TypeError, KeyError, AttributeError): result['instance_id'] = None return {'floating_ip': result} diff --git a/nova/network/api.py b/nova/network/api.py index 59172d9ec..f6beba3c7 100644 --- a/nova/network/api.py +++ b/nova/network/api.py @@ -110,11 +110,14 @@ class API(base.Base): @wrap_check_policy def get_all(self, context): - return self.network_rpcapi.get_all_networks(context) + try: + return self.db.network_get_all(context) + except exception.NoNetworksFound: + return [] @wrap_check_policy def get(self, context, network_uuid): - return self.network_rpcapi.get_network(context, network_uuid) + return self.db.network_get_by_uuid(context.elevated(), network_uuid) @wrap_check_policy def create(self, context, **kwargs): @@ -126,36 +129,39 @@ class API(base.Base): @wrap_check_policy def disassociate(self, context, network_uuid): - return self.network_rpcapi.disassociate_network(context, network_uuid) + network = self.get(context, network_uuid) + self.db.network_disassociate(context, network['id']) @wrap_check_policy def get_fixed_ip(self, context, id): - return self.network_rpcapi.get_fixed_ip(context, id) + return self.db.fixed_ip_get(context, id) @wrap_check_policy def get_fixed_ip_by_address(self, context, address): - return self.network_rpcapi.get_fixed_ip_by_address(context, address) + return self.db.fixed_ip_get_by_address(context, address) @wrap_check_policy def get_floating_ip(self, context, id): - return self.network_rpcapi.get_floating_ip(context, id) + return self.db.floating_ip_get(context, id) @wrap_check_policy def get_floating_ip_pools(self, context): - return self.network_rpcapi.get_floating_ip_pools(context) + return self.db.floating_ip_get_pools(context) @wrap_check_policy def get_floating_ip_by_address(self, context, address): - return self.network_rpcapi.get_floating_ip_by_address(context, address) + return self.db.floating_ip_get_by_address(context, address) @wrap_check_policy def get_floating_ips_by_project(self, context): - return self.network_rpcapi.get_floating_ips_by_project(context) + return self.db.floating_ip_get_all_by_project(context, + context.project_id) @wrap_check_policy def get_floating_ips_by_fixed_address(self, context, fixed_address): - return self.network_rpcapi.get_floating_ips_by_fixed_address(context, - fixed_address) + floating_ips = self.db.floating_ip_get_by_fixed_address(context, + fixed_address) + return [floating_ip['address'] for floating_ip in floating_ips] @wrap_check_policy def get_backdoor_port(self, context, host): @@ -163,18 +169,21 @@ class API(base.Base): @wrap_check_policy def get_instance_id_by_floating_address(self, context, address): - # NOTE(tr3buchet): i hate this - return self.network_rpcapi.get_instance_id_by_floating_address(context, - address) + fixed_ip = self.db.fixed_ip_get_by_floating_address(context, address) + if fixed_ip is None: + return None + else: + return fixed_ip['instance_uuid'] @wrap_check_policy def get_vifs_by_instance(self, context, instance): - return self.network_rpcapi.get_vifs_by_instance(context, - instance['id']) + return self.db.virtual_interface_get_by_instance(context, + instance['uuid']) @wrap_check_policy def get_vif_by_mac_address(self, context, mac_address): - return self.network_rpcapi.get_vif_by_mac_address(context, mac_address) + return self.db.virtual_interface_get_by_address(context, + mac_address) @wrap_check_policy def allocate_floating_ip(self, context, pool=None): @@ -290,11 +299,22 @@ class API(base.Base): project=_sentinel): """Associate or disassociate host or project to network.""" associations = {} + network_id = self.get(context, network_uuid)['id'] if host is not API._sentinel: - associations['host'] = host + if host is None: + self.db.network_disassociate(context, network_id, + disassociate_host=True, + disassociate_project=False) + else: + self.db.network_set_host(context, network_id, host) if project is not API._sentinel: - associations['project'] = project - self.network_rpcapi.associate(context, network_uuid, associations) + project = associations['project'] + if project is None: + self.db.network_disassociate(context, network_id, + disassociate_host=False, + disassociate_project=True) + else: + self.db.network_associate(context, project, network_id, True) @wrap_check_policy def get_instance_nw_info(self, context, instance, update_cache=True): diff --git a/nova/network/api_deprecated.py b/nova/network/api_deprecated.py new file mode 100644 index 000000000..b84a08a6d --- /dev/null +++ b/nova/network/api_deprecated.py @@ -0,0 +1,465 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (c) 2011 X.commerce, a business unit of eBay Inc. +# Copyright 2010 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +""" +This version of the api is deprecated in Grizzly and will be removed. + +It is provided just in case a third party manager is in use. +""" + +import functools +import inspect + +from nova.db import base +from nova import exception +from nova.network import model as network_model +from nova.network import rpcapi as network_rpcapi +from nova.openstack.common import log as logging +from nova import policy + +LOG = logging.getLogger(__name__) + + +def refresh_cache(f): + """ + Decorator to update the instance_info_cache + + Requires context and instance as function args + """ + argspec = inspect.getargspec(f) + + @functools.wraps(f) + def wrapper(self, context, *args, **kwargs): + res = f(self, context, *args, **kwargs) + + try: + # get the instance from arguments (or raise ValueError) + instance = kwargs.get('instance') + if not instance: + instance = args[argspec.args.index('instance') - 2] + except ValueError: + msg = _('instance is a required argument to use @refresh_cache') + raise Exception(msg) + + update_instance_cache_with_nw_info(self, context, instance, + nw_info=res) + + # return the original function's return value + return res + return wrapper + + +def update_instance_cache_with_nw_info(api, context, instance, + nw_info=None): + + try: + if not isinstance(nw_info, network_model.NetworkInfo): + nw_info = None + if not nw_info: + nw_info = api._get_instance_nw_info(context, instance) + # update cache + cache = {'network_info': nw_info.json()} + api.db.instance_info_cache_update(context, instance['uuid'], cache) + except Exception: + LOG.exception(_('Failed storing info cache'), instance=instance) + + +def wrap_check_policy(func): + """Check policy corresponding to the wrapped methods prior to execution.""" + + @functools.wraps(func) + def wrapped(self, context, *args, **kwargs): + action = func.__name__ + check_policy(context, action) + return func(self, context, *args, **kwargs) + + return wrapped + + +def check_policy(context, action): + target = { + 'project_id': context.project_id, + 'user_id': context.user_id, + } + _action = 'network:%s' % action + policy.enforce(context, _action, target) + + +class API(base.Base): + """API for doing networking via the nova-network network manager. + + This is a pluggable module - other implementations do networking via + other services (such as Quantum). + """ + + _sentinel = object() + + def __init__(self, **kwargs): + self.network_rpcapi = network_rpcapi.NetworkAPI() + super(API, self).__init__(**kwargs) + + @wrap_check_policy + def get_all(self, context): + return self.network_rpcapi.get_all_networks(context) + + @wrap_check_policy + def get(self, context, network_uuid): + return self.network_rpcapi.get_network(context, network_uuid) + + @wrap_check_policy + def create(self, context, **kwargs): + return self.network_rpcapi.create_networks(context, **kwargs) + + @wrap_check_policy + def delete(self, context, network_uuid): + return self.network_rpcapi.delete_network(context, network_uuid, None) + + @wrap_check_policy + def disassociate(self, context, network_uuid): + return self.network_rpcapi.disassociate_network(context, network_uuid) + + @wrap_check_policy + def get_fixed_ip(self, context, id): + return self.network_rpcapi.get_fixed_ip(context, id) + + @wrap_check_policy + def get_fixed_ip_by_address(self, context, address): + return self.network_rpcapi.get_fixed_ip_by_address(context, address) + + @wrap_check_policy + def get_floating_ip(self, context, id): + return self.network_rpcapi.get_floating_ip(context, id) + + @wrap_check_policy + def get_floating_ip_pools(self, context): + return self.network_rpcapi.get_floating_ip_pools(context) + + @wrap_check_policy + def get_floating_ip_by_address(self, context, address): + return self.network_rpcapi.get_floating_ip_by_address(context, address) + + @wrap_check_policy + def get_floating_ips_by_project(self, context): + return self.network_rpcapi.get_floating_ips_by_project(context) + + @wrap_check_policy + def get_floating_ips_by_fixed_address(self, context, fixed_address): + return self.network_rpcapi.get_floating_ips_by_fixed_address(context, + fixed_address) + + @wrap_check_policy + def get_backdoor_port(self, context, host): + return self.network_rpcapi.get_backdoor_port(context, host) + + @wrap_check_policy + def get_instance_id_by_floating_address(self, context, address): + # NOTE(tr3buchet): i hate this + return self.network_rpcapi.get_instance_id_by_floating_address(context, + address) + + @wrap_check_policy + def get_vifs_by_instance(self, context, instance): + return self.network_rpcapi.get_vifs_by_instance(context, + instance['id']) + + @wrap_check_policy + def get_vif_by_mac_address(self, context, mac_address): + return self.network_rpcapi.get_vif_by_mac_address(context, mac_address) + + @wrap_check_policy + def allocate_floating_ip(self, context, pool=None): + """Adds (allocates) a floating ip to a project from a pool.""" + # NOTE(vish): We don't know which network host should get the ip + # when we allocate, so just send it to any one. This + # will probably need to move into a network supervisor + # at some point. + return self.network_rpcapi.allocate_floating_ip(context, + context.project_id, pool, False) + + @wrap_check_policy + def release_floating_ip(self, context, address, + affect_auto_assigned=False): + """Removes (deallocates) a floating ip with address from a project.""" + return self.network_rpcapi.deallocate_floating_ip(context, address, + affect_auto_assigned) + + @wrap_check_policy + @refresh_cache + def associate_floating_ip(self, context, instance, + floating_address, fixed_address, + affect_auto_assigned=False): + """Associates a floating ip with a fixed ip. + + ensures floating ip is allocated to the project in context + """ + orig_instance_uuid = self.network_rpcapi.associate_floating_ip(context, + floating_address, fixed_address, affect_auto_assigned) + + if orig_instance_uuid: + msg_dict = dict(address=floating_address, + instance_id=orig_instance_uuid) + LOG.info(_('re-assign floating IP %(address)s from ' + 'instance %(instance_id)s') % msg_dict) + orig_instance = self.db.instance_get_by_uuid(context, + orig_instance_uuid) + + # purge cached nw info for the original instance + update_instance_cache_with_nw_info(self, context, orig_instance) + + @wrap_check_policy + @refresh_cache + def disassociate_floating_ip(self, context, instance, address, + affect_auto_assigned=False): + """Disassociates a floating ip from fixed ip it is associated with.""" + self.network_rpcapi.disassociate_floating_ip(context, address, + affect_auto_assigned) + + @wrap_check_policy + @refresh_cache + def allocate_for_instance(self, context, instance, vpn, + requested_networks, macs=None): + """Allocates all network structures for an instance. + + TODO(someone): document the rest of these parameters. + + :param macs: None or a set of MAC addresses that the instance + should use. macs is supplied by the hypervisor driver (contrast + with requested_networks which is user supplied). + NB: macs is ignored by nova-network. + :returns: network info as from get_instance_nw_info() below + """ + args = {} + args['vpn'] = vpn + args['requested_networks'] = requested_networks + args['instance_id'] = instance['id'] + args['instance_uuid'] = instance['uuid'] + args['project_id'] = instance['project_id'] + args['host'] = instance['host'] + args['rxtx_factor'] = instance['instance_type']['rxtx_factor'] + nw_info = self.network_rpcapi.allocate_for_instance(context, **args) + + return network_model.NetworkInfo.hydrate(nw_info) + + @wrap_check_policy + def deallocate_for_instance(self, context, instance): + """Deallocates all network structures related to instance.""" + + args = {} + args['instance_id'] = instance['id'] + args['project_id'] = instance['project_id'] + args['host'] = instance['host'] + self.network_rpcapi.deallocate_for_instance(context, **args) + + @wrap_check_policy + @refresh_cache + def add_fixed_ip_to_instance(self, context, instance, network_id): + """Adds a fixed ip to instance from specified network.""" + args = {'instance_id': instance['uuid'], + 'host': instance['host'], + 'network_id': network_id} + self.network_rpcapi.add_fixed_ip_to_instance(context, **args) + + @wrap_check_policy + @refresh_cache + def remove_fixed_ip_from_instance(self, context, instance, address): + """Removes a fixed ip from instance from specified network.""" + + args = {'instance_id': instance['uuid'], + 'host': instance['host'], + 'address': address} + self.network_rpcapi.remove_fixed_ip_from_instance(context, **args) + + @wrap_check_policy + def add_network_to_project(self, context, project_id, network_uuid=None): + """Force adds another network to a project.""" + self.network_rpcapi.add_network_to_project(context, project_id, + network_uuid) + + @wrap_check_policy + def associate(self, context, network_uuid, host=_sentinel, + project=_sentinel): + """Associate or disassociate host or project to network.""" + associations = {} + if host is not API._sentinel: + associations['host'] = host + if project is not API._sentinel: + associations['project'] = project + self.network_rpcapi.associate(context, network_uuid, associations) + + @wrap_check_policy + def get_instance_nw_info(self, context, instance, update_cache=True): + """Returns all network info related to an instance.""" + result = self._get_instance_nw_info(context, instance) + if update_cache: + update_instance_cache_with_nw_info(self, context, instance, + result) + return result + + def _get_instance_nw_info(self, context, instance): + """Returns all network info related to an instance.""" + args = {'instance_id': instance['id'], + 'instance_uuid': instance['uuid'], + 'rxtx_factor': instance['instance_type']['rxtx_factor'], + 'host': instance['host'], + 'project_id': instance['project_id']} + nw_info = self.network_rpcapi.get_instance_nw_info(context, **args) + + return network_model.NetworkInfo.hydrate(nw_info) + + @wrap_check_policy + def validate_networks(self, context, requested_networks): + """validate the networks passed at the time of creating + the server + """ + return self.network_rpcapi.validate_networks(context, + requested_networks) + + @wrap_check_policy + def get_instance_uuids_by_ip_filter(self, context, filters): + """Returns a list of dicts in the form of + {'instance_uuid': uuid, 'ip': ip} that matched the ip_filter + """ + return self.network_rpcapi.get_instance_uuids_by_ip_filter(context, + filters) + + @wrap_check_policy + def get_dns_domains(self, context): + """Returns a list of available dns domains. + These can be used to create DNS entries for floating ips. + """ + return self.network_rpcapi.get_dns_domains(context) + + @wrap_check_policy + def add_dns_entry(self, context, address, name, dns_type, domain): + """Create specified DNS entry for address.""" + args = {'address': address, + 'name': name, + 'dns_type': dns_type, + 'domain': domain} + return self.network_rpcapi.add_dns_entry(context, **args) + + @wrap_check_policy + def modify_dns_entry(self, context, name, address, domain): + """Create specified DNS entry for address.""" + args = {'address': address, + 'name': name, + 'domain': domain} + return self.network_rpcapi.modify_dns_entry(context, **args) + + @wrap_check_policy + def delete_dns_entry(self, context, name, domain): + """Delete the specified dns entry.""" + args = {'name': name, 'domain': domain} + return self.network_rpcapi.delete_dns_entry(context, **args) + + @wrap_check_policy + def delete_dns_domain(self, context, domain): + """Delete the specified dns domain.""" + return self.network_rpcapi.delete_dns_domain(context, domain=domain) + + @wrap_check_policy + def get_dns_entries_by_address(self, context, address, domain): + """Get entries for address and domain.""" + args = {'address': address, 'domain': domain} + return self.network_rpcapi.get_dns_entries_by_address(context, **args) + + @wrap_check_policy + def get_dns_entries_by_name(self, context, name, domain): + """Get entries for name and domain.""" + args = {'name': name, 'domain': domain} + return self.network_rpcapi.get_dns_entries_by_name(context, **args) + + @wrap_check_policy + def create_private_dns_domain(self, context, domain, availability_zone): + """Create a private DNS domain with nova availability zone.""" + args = {'domain': domain, 'av_zone': availability_zone} + return self.network_rpcapi.create_private_dns_domain(context, **args) + + @wrap_check_policy + def create_public_dns_domain(self, context, domain, project=None): + """Create a public DNS domain with optional nova project.""" + args = {'domain': domain, 'project': project} + return self.network_rpcapi.create_public_dns_domain(context, **args) + + @wrap_check_policy + def setup_networks_on_host(self, context, instance, host=None, + teardown=False): + """Setup or teardown the network structures on hosts related to + instance""" + host = host or instance['host'] + # NOTE(tr3buchet): host is passed in cases where we need to setup + # or teardown the networks on a host which has been migrated to/from + # and instance['host'] is not yet or is no longer equal to + args = {'instance_id': instance['id'], + 'host': host, + 'teardown': teardown} + + self.network_rpcapi.setup_networks_on_host(context, **args) + + def _is_multi_host(self, context, instance): + try: + fixed_ips = self.db.fixed_ip_get_by_instance(context, + instance['uuid']) + except exception.FixedIpNotFoundForInstance: + return False + network = self.db.network_get(context, fixed_ips[0]['network_id'], + project_only='allow_none') + return network['multi_host'] + + def _get_floating_ip_addresses(self, context, instance): + floating_ips = self.db.instance_floating_address_get_all(context, + instance['uuid']) + return [floating_ip['address'] for floating_ip in floating_ips] + + @wrap_check_policy + def migrate_instance_start(self, context, instance, migration): + """Start to migrate the network of an instance.""" + args = dict( + instance_uuid=instance['uuid'], + rxtx_factor=instance['instance_type']['rxtx_factor'], + project_id=instance['project_id'], + source_compute=migration['source_compute'], + dest_compute=migration['dest_compute'], + floating_addresses=None, + ) + + if self._is_multi_host(context, instance): + args['floating_addresses'] = \ + self._get_floating_ip_addresses(context, instance) + args['host'] = migration['source_compute'] + + self.network_rpcapi.migrate_instance_start(context, **args) + + @wrap_check_policy + def migrate_instance_finish(self, context, instance, migration): + """Finish migrating the network of an instance.""" + args = dict( + instance_uuid=instance['uuid'], + rxtx_factor=instance['instance_type']['rxtx_factor'], + project_id=instance['project_id'], + source_compute=migration['source_compute'], + dest_compute=migration['dest_compute'], + floating_addresses=None, + ) + + if self._is_multi_host(context, instance): + args['floating_addresses'] = \ + self._get_floating_ip_addresses(context, instance) + args['host'] = migration['dest_compute'] + + self.network_rpcapi.migrate_instance_finish(context, **args) diff --git a/nova/network/manager.py b/nova/network/manager.py index d1dabdfd9..f57bb197b 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -674,6 +674,8 @@ class FloatingIP(object): @rpc_common.client_exceptions(exception.FloatingIpNotFound) def get_floating_ip(self, context, id): """Returns a floating IP as a dict.""" + # NOTE(vish): This is no longer used but can't be removed until + # we major version the network_rpcapi. return dict(self.db.floating_ip_get(context, id).iteritems()) def get_floating_pools(self, context): @@ -684,22 +686,30 @@ class FloatingIP(object): def get_floating_ip_pools(self, context): """Returns list of floating ip pools.""" + # NOTE(vish): This is no longer used but can't be removed until + # we major version the network_rpcapi. pools = self.db.floating_ip_get_pools(context) return [dict(pool.iteritems()) for pool in pools] def get_floating_ip_by_address(self, context, address): """Returns a floating IP as a dict.""" + # NOTE(vish): This is no longer used but can't be removed until + # we major version the network_rpcapi. return dict(self.db.floating_ip_get_by_address(context, address).iteritems()) def get_floating_ips_by_project(self, context): """Returns the floating IPs allocated to a project.""" + # NOTE(vish): This is no longer used but can't be removed until + # we major version the network_rpcapi. ips = self.db.floating_ip_get_all_by_project(context, context.project_id) return [dict(ip.iteritems()) for ip in ips] def get_floating_ips_by_fixed_address(self, context, fixed_address): """Returns the floating IPs associated with a fixed_address.""" + # NOTE(vish): This is no longer used but can't be removed until + # we major version the network_rpcapi. floating_ips = self.db.floating_ip_get_by_fixed_address(context, fixed_address) return [floating_ip['address'] for floating_ip in floating_ips] @@ -1873,6 +1883,8 @@ class NetworkManager(manager.SchedulerDependentManager): def get_vifs_by_instance(self, context, instance_id): """Returns the vifs associated with an instance.""" + # NOTE(vish): This is no longer used but can't be removed until + # we major version the network_rpcapi to 2.0. instance = self.db.instance_get(context, instance_id) vifs = self.db.virtual_interface_get_by_instance(context, instance['uuid']) @@ -1880,6 +1892,8 @@ class NetworkManager(manager.SchedulerDependentManager): def get_instance_id_by_floating_address(self, context, address): """Returns the instance id a floating ip's fixed ip is allocated to.""" + # NOTE(vish): This is no longer used but can't be removed until + # we major version the network_rpcapi to 2.0. fixed_ip = self.db.fixed_ip_get_by_floating_address(context, address) if fixed_ip is None: return None @@ -1887,10 +1901,14 @@ class NetworkManager(manager.SchedulerDependentManager): return fixed_ip['instance_uuid'] def get_network(self, context, network_uuid): + # NOTE(vish): used locally + network = self.db.network_get_by_uuid(context.elevated(), network_uuid) return jsonutils.to_primitive(network) def get_all_networks(self, context): + # NOTE(vish): This is no longer used but can't be removed until + # we major version the network_rpcapi to 2.0. try: networks = self.db.network_get_all(context) except exception.NoNetworksFound: @@ -1898,20 +1916,28 @@ class NetworkManager(manager.SchedulerDependentManager): return [jsonutils.to_primitive(network) for network in networks] def disassociate_network(self, context, network_uuid): + # NOTE(vish): This is no longer used but can't be removed until + # we major version the network_rpcapi to 2.0. network = self.get_network(context, network_uuid) self.db.network_disassociate(context, network['id']) def get_fixed_ip(self, context, id): """Return a fixed ip.""" + # NOTE(vish): This is no longer used but can't be removed until + # we major version the network_rpcapi to 2.0. fixed = self.db.fixed_ip_get(context, id) return jsonutils.to_primitive(fixed) def get_fixed_ip_by_address(self, context, address): + # NOTE(vish): This is no longer used but can't be removed until + # we major version the network_rpcapi to 2.0. fixed = self.db.fixed_ip_get_by_address(context, address) return jsonutils.to_primitive(fixed) def get_vif_by_mac_address(self, context, mac_address): """Returns the vifs record for the mac_address.""" + # NOTE(vish): This is no longer used but can't be removed until + # we major version the network_rpcapi to 2.0. return self.db.virtual_interface_get_by_address(context, mac_address) @@ -2011,6 +2037,8 @@ class FlatManager(NetworkManager): def get_floating_ip(self, context, id): """Returns a floating IP as a dict.""" + # NOTE(vish): This is no longer used but can't be removed until + # we major version the network_rpcapi to 2.0. return None def get_floating_pools(self, context): @@ -2021,18 +2049,26 @@ class FlatManager(NetworkManager): def get_floating_ip_pools(self, context): """Returns list of floating ip pools.""" + # NOTE(vish): This is no longer used but can't be removed until + # we major version the network_rpcapi to 2.0. return {} def get_floating_ip_by_address(self, context, address): """Returns a floating IP as a dict.""" + # NOTE(vish): This is no longer used but can't be removed until + # we major version the network_rpcapi to 2.0. return None def get_floating_ips_by_project(self, context): """Returns the floating IPs allocated to a project.""" + # NOTE(vish): This is no longer used but can't be removed until + # we major version the network_rpcapi to 2.0. return [] def get_floating_ips_by_fixed_address(self, context, fixed_address): """Returns the floating IPs associated with a fixed_address.""" + # NOTE(vish): This is no longer used but can't be removed until + # we major version the network_rpcapi to 2.0. return [] def migrate_instance_start(self, context, instance_uuid, @@ -2197,6 +2233,8 @@ class VlanManager(RPCAllocateFixedIP, FloatingIP, NetworkManager): def associate(self, context, network_uuid, associations): """Associate or disassociate host or project to network.""" + # NOTE(vish): This is no longer used but can't be removed until + # we major version the network_rpcapi to 2.0. network_id = self.get_network(context, network_uuid)['id'] if 'host' in associations: host = associations['host'] diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py index 080e4e92b..c180db47b 100644 --- a/nova/tests/integrated/test_api_samples.py +++ b/nova/tests/integrated/test_api_samples.py @@ -34,7 +34,6 @@ from nova import db from nova.db.sqlalchemy import models from nova import exception from nova.network import api as network_api -from nova.network import manager as network_manager from nova.openstack.common import cfg from nova.openstack.common import importutils from nova.openstack.common import jsonutils @@ -1511,7 +1510,7 @@ class CloudPipeSampleJsonTest(ApiSampleTestBase): 'vpn_public_port': 22} self.stubs.Set(pipelib.CloudPipe, 'get_encoded_zip', get_user_data) - self.stubs.Set(network_manager.NetworkManager, "get_network", + self.stubs.Set(network_api.API, "get", network_api_get) def generalize_subs(self, subs, vanilla_regexes): |