diff options
author | Mark McLoughlin <markmc@redhat.com> | 2012-12-12 08:12:11 +0000 |
---|---|---|
committer | Mark McLoughlin <markmc@redhat.com> | 2012-12-16 22:24:07 +0000 |
commit | 19558abd2b174f16d74809cd159451effc6d2ac2 (patch) | |
tree | 8b1f2cef454169bb573ac609323001406b8e3a0e | |
parent | 06f0e45712288525d0ae31d133efe30156a1ed71 (diff) | |
download | nova-19558abd2b174f16d74809cd159451effc6d2ac2.tar.gz nova-19558abd2b174f16d74809cd159451effc6d2ac2.tar.xz nova-19558abd2b174f16d74809cd159451effc6d2ac2.zip |
Move network_driver into new nova.network.driver
Add a new load_network_driver() function which constrains the use of the
network_driver option and move the option into nova.network.driver.
blueprint: scope-config-opts
Change-Id: I0a839765890093dc871b48435cfd113e0f8e46c4
-rw-r--r-- | nova/api/manager.py | 8 | ||||
-rw-r--r-- | nova/config.py | 3 | ||||
-rw-r--r-- | nova/network/driver.py | 44 | ||||
-rw-r--r-- | nova/network/manager.py | 6 | ||||
-rw-r--r-- | nova/tests/network/test_linux_net.py | 7 |
5 files changed, 50 insertions, 18 deletions
diff --git a/nova/api/manager.py b/nova/api/manager.py index 04607d751..e9b07aa92 100644 --- a/nova/api/manager.py +++ b/nova/api/manager.py @@ -17,11 +17,7 @@ # under the License. from nova import manager -from nova.openstack.common import cfg -from nova.openstack.common import importutils - -CONF = cfg.CONF -CONF.import_opt('network_driver', 'nova.config') +from nova.network import driver class MetadataManager(manager.Manager): @@ -32,7 +28,7 @@ class MetadataManager(manager.Manager): """ def __init__(self, *args, **kwargs): super(MetadataManager, self).__init__(*args, **kwargs) - self.network_driver = importutils.import_module(CONF.network_driver) + self.network_driver = driver.load_network_driver() def init_host(self): """Perform any initialization. diff --git a/nova/config.py b/nova/config.py index 2ff0b2711..4f4fbe822 100644 --- a/nova/config.py +++ b/nova/config.py @@ -158,9 +158,6 @@ global_opts = [ default=None, help='The default format an ephemeral_volume will be ' 'formatted with on creation.'), - cfg.StrOpt('network_driver', - default='nova.network.linux_net', - help='Driver to use for network creation'), cfg.BoolOpt('use_ipv6', default=False, help='use ipv6'), diff --git a/nova/network/driver.py b/nova/network/driver.py new file mode 100644 index 000000000..4caff4575 --- /dev/null +++ b/nova/network/driver.py @@ -0,0 +1,44 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2012 Red Hat, Inc. +# +# 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. + +import sys + +from nova.openstack.common import cfg +from nova.openstack.common import importutils +from nova.openstack.common import log as logging + +driver_opts = [ + cfg.StrOpt('network_driver', + default='nova.network.linux_net', + help='Driver to use for network creation'), +] +CONF = cfg.CONF +CONF.register_opts(driver_opts) + +LOG = logging.getLogger(__name__) + + +def load_network_driver(network_driver=None): + if not network_driver: + network_driver = CONF.network_driver + + if not network_driver: + LOG.error(_("Network driver option required, but not specified")) + sys.exit(1) + + LOG.info(_("Loading network driver '%s'") % CONF.network_driver) + + return importutils.import_module(CONF.network_driver) diff --git a/nova/network/manager.py b/nova/network/manager.py index c61a60a99..d36eb197d 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -60,6 +60,7 @@ from nova import exception from nova import ipv6 from nova import manager from nova.network import api as network_api +from nova.network import driver from nova.network import model as network_model from nova.network import rpcapi as network_rpcapi from nova.openstack.common import cfg @@ -189,7 +190,6 @@ network_opts = [ CONF = cfg.CONF CONF.register_opts(network_opts) CONF.import_opt('fake_network', 'nova.config') -CONF.import_opt('network_driver', 'nova.config') CONF.import_opt('use_ipv6', 'nova.config') CONF.import_opt('my_ip', 'nova.config') @@ -909,9 +909,7 @@ class NetworkManager(manager.SchedulerDependentManager): required_create_args = [] def __init__(self, network_driver=None, *args, **kwargs): - if not network_driver: - network_driver = CONF.network_driver - self.driver = importutils.import_module(network_driver) + self.driver = driver.load_network_driver(network_driver) self.instance_dns_manager = importutils.import_object( CONF.instance_dns_manager) self.instance_dns_domain = CONF.instance_dns_domain diff --git a/nova/tests/network/test_linux_net.py b/nova/tests/network/test_linux_net.py index 68aaa6251..243b0ee56 100644 --- a/nova/tests/network/test_linux_net.py +++ b/nova/tests/network/test_linux_net.py @@ -21,16 +21,14 @@ import mox from nova import context from nova import db +from nova.network import driver from nova.network import linux_net -from nova.openstack.common import cfg from nova.openstack.common import fileutils from nova.openstack.common import importutils from nova.openstack.common import log as logging from nova import test from nova import utils -CONF = cfg.CONF -CONF.import_opt('network_driver', 'nova.config') LOG = logging.getLogger(__name__) HOST = "testhost" @@ -214,8 +212,7 @@ class LinuxNetworkTestCase(test.TestCase): def setUp(self): super(LinuxNetworkTestCase, self).setUp() - network_driver = CONF.network_driver - self.driver = importutils.import_module(network_driver) + self.driver = driver.load_network_driver() self.driver.db = db self.context = context.RequestContext('testuser', 'testproject', is_admin=True) |