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
This commit is contained in:
parent
06f0e45712
commit
19558abd2b
|
@ -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.
|
||||
|
|
|
@ -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'),
|
||||
|
|
|
@ -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)
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue