reduce direct uses of oslo.config.cfg.CONF

no functional changes are intended.

Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
YAMAMOTO Takashi 2014-03-12 12:52:30 +09:00 committed by FUJITA Tomonori
parent 934fc1516f
commit 7b1d0eb9d6
15 changed files with 44 additions and 48 deletions

View File

@ -15,7 +15,6 @@
# limitations under the License.
import traceback
from oslo.config import cfg
try:
from neutronclient import client as q_client
@ -45,10 +44,7 @@ from ryu.lib.ovs import bridge
from ryu.lib.quantum_ifaces import QuantumIfaces
CONF = cfg.CONF
def _get_auth_token(logger):
def _get_auth_token(CONF, logger):
httpclient = q_client.HTTPClient(
username=CONF.neutron_admin_username,
tenant_name=CONF.neutron_admin_tenant_name,
@ -65,7 +61,7 @@ def _get_auth_token(logger):
return httpclient.auth_token
def _get_quantum_client(token):
def _get_quantum_client(CONF, token):
if token:
my_client = q_clientv2.Client(
endpoint_url=CONF.neutron_url,
@ -130,14 +126,15 @@ class OVSPort(object):
class OVSSwitch(object):
def __init__(self, dpid, nw, ifaces, logger):
def __init__(self, CONF, dpid, nw, ifaces, logger):
# TODO: clean up
self.CONF = CONF
self.dpid = dpid
self.network_api = nw
self.ifaces = ifaces
self.logger = logger
self._q_api = None # lazy initialization
self.ctrl_addr = CONF.neutron_controller_addr
self.ctrl_addr = self.CONF.neutron_controller_addr
if not self.ctrl_addr:
raise ValueError('option neutron_controler_addr must be speicfied')
@ -153,9 +150,9 @@ class OVSSwitch(object):
def q_api(self):
if self._q_api is None:
token = None
if CONF.neutron_auth_strategy:
token = _get_auth_token(self.logger)
self._q_api = _get_quantum_client(token)
if self.CONF.neutron_auth_strategy:
token = _get_auth_token(self.CONF, self.logger)
self._q_api = _get_quantum_client(self.CONF, token)
return self._q_api
def set_ovsdb_addr(self, dpid, ovsdb_addr):
@ -176,7 +173,7 @@ class OVSSwitch(object):
self.ovsdb_addr = ovsdb_addr
if self.ovs_bridge is None:
self.logger.debug('ovsdb: adding ports %s', self.ports)
ovs_bridge = bridge.OVSBridge(dpid, ovsdb_addr)
ovs_bridge = bridge.OVSBridge(self.CONF, dpid, ovsdb_addr)
self.ovs_bridge = ovs_bridge
ovs_bridge.init()
# TODO: for multi-controller
@ -352,7 +349,8 @@ class QuantumAdapter(app_manager.RyuApp):
ovs_switch = self.dps.get(dpid)
if not ovs_switch:
if create:
ovs_switch = OVSSwitch(dpid, self.nw, self.ifaces, self.logger)
ovs_switch = OVSSwitch(self.CONF, dpid, self.nw, self.ifaces,
self.logger)
self.dps[dpid] = ovs_switch
else:
self.logger.debug('ovs switch %s is already known', dpid)

View File

@ -124,7 +124,7 @@ class SimpleVLAN(app_manager.RyuApp):
self.logger.debug('ovs_port_update dpid %s port_no %s', dpid, port_no)
# ovs-vsctl --db=ovsdb_addr --timeout=2
# set Port port.name tag=tunnel_key
ovs_br = bridge.OVSBridge(dpid, ovsdb_addr, 2)
ovs_br = bridge.OVSBridge(self.CONF, dpid, ovsdb_addr, 2)
# ofp_phy_port::name is zero-padded
port_name = port.name.rstrip('\x00')
try:

View File

@ -17,7 +17,7 @@
# This module updates OVS tunnel ports for OpenStack integration.
import collections
from oslo.config import cfg
from ryu import cfg
import logging
import netaddr
@ -34,12 +34,6 @@ from ryu.lib import hub
from ryu.lib.ovs import bridge as ovs_bridge
CONF = cfg.CONF
CONF.register_opts([
cfg.StrOpt('tunnel-type', default='gre',
help='tunnel type for ovs tunnel port')
])
_TUNNEL_TYPE_TO_NW_ID = {
'gre': rest_nw_id.NW_ID_VPORT_GRE,
}
@ -104,15 +98,15 @@ class TunnelPort(object):
class TunnelDP(object):
def __init__(self, dpid, ovsdb_addr, tunnel_ip, tunnel_type, conf_switch_,
network_api, tunnel_api, logger):
def __init__(self, CONF, dpid, ovsdb_addr, tunnel_ip, tunnel_type,
conf_switch_, network_api, tunnel_api, logger):
super(TunnelDP, self).__init__()
self.dpid = dpid
self.network_api = network_api
self.tunnel_api = tunnel_api
self.logger = logger
self.ovs_bridge = ovs_bridge.OVSBridge(dpid, ovsdb_addr)
self.ovs_bridge = ovs_bridge.OVSBridge(CONF, dpid, ovsdb_addr)
self.tunnel_ip = tunnel_ip
self.tunnel_type = tunnel_type
@ -355,7 +349,11 @@ class TunnelPortUpdater(app_manager.RyuApp):
def __init__(self, *args, **kwargs):
super(TunnelPortUpdater, self).__init__(args, kwargs)
self.tunnel_type = CONF.tunnel_type
self.CONF.register_opts([
cfg.StrOpt('tunnel-type', default='gre',
help='tunnel type for ovs tunnel port')
])
self.tunnel_type = self.CONF.tunnel_type
self.cs = kwargs['conf_switch']
self.nw = kwargs['network']
self.tunnels = kwargs['tunnels']
@ -373,7 +371,7 @@ class TunnelPortUpdater(app_manager.RyuApp):
ovs_tunnel_addr)
if dpid not in self.tunnel_dpset:
# TODO:XXX changing ovsdb_addr, ovs_tunnel_addr
tunnel_dp = TunnelDP(dpid, ovsdb_addr, ovs_tunnel_addr,
tunnel_dp = TunnelDP(self.CONF, dpid, ovsdb_addr, ovs_tunnel_addr,
self.tunnel_type, self.cs,
self.network_api, self.tunnel_api,
self.logger)

View File

@ -16,7 +16,7 @@
import inspect
from oslo.config import cfg
from ryu import cfg
import webob.dec
from ryu.lib import hub

View File

@ -28,7 +28,7 @@ hub.patch()
# eg. oslo.config.cfg.
import ryu.contrib
from oslo.config import cfg
from ryu import cfg
import logging
import sys

View File

@ -25,7 +25,7 @@
import ryu.contrib
from oslo.config import cfg
from ryu import cfg
import cmd
import sys

View File

@ -29,7 +29,7 @@ hub.patch()
# eg. oslo.config.cfg.
import ryu.contrib
from oslo.config import cfg
from ryu import cfg
import sys
from neutron.openstack.common import log as os_logging

View File

@ -31,7 +31,7 @@
import ryu.contrib
from oslo.config import cfg
from ryu import cfg
import cmd
import signal

View File

@ -15,7 +15,7 @@
# limitations under the License.
import contextlib
from oslo.config import cfg
from ryu import cfg
import logging
from ryu.lib import hub
from ryu.lib.hub import StreamServer

View File

@ -17,7 +17,7 @@
global flags
"""
from oslo.config import cfg
from ryu import cfg
CONF = cfg.CONF

View File

@ -19,7 +19,7 @@ slimmed down version of OVSBridge in quantum agent
"""
import functools
from oslo.config import cfg
from ryu import cfg
import logging
import ryu.exception as ryu_exc
@ -88,7 +88,8 @@ class TunnelPort(object):
class OVSBridge(object):
def __init__(self, datapath_id, ovsdb_addr, timeout=None, exception=None):
def __init__(self, CONF, datapath_id, ovsdb_addr, timeout=None,
exception=None):
super(OVSBridge, self).__init__()
self.datapath_id = datapath_id
self.vsctl = ovs_vsctl.VSCtl(ovsdb_addr)

View File

@ -15,7 +15,7 @@
# limitations under the License.
from __future__ import print_function
from oslo.config import cfg
from ryu import cfg
import inspect
import platform
import logging

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from oslo.config import cfg
from ryu import cfg
import socket
import netaddr
@ -26,11 +26,6 @@ from ryu.lib import hub
from ryu.lib import mac
VRRP_RPC_PORT = 50004 # random
CONF = cfg.CONF
CONF.register_opts([
cfg.IntOpt('vrrp-rpc-port', default=VRRP_RPC_PORT,
help='port for vrrp rpc interface')])
class RPCError(Exception):
@ -49,6 +44,10 @@ class Peer(object):
class RpcVRRPManager(app_manager.RyuApp):
def __init__(self, *args, **kwargs):
super(RpcVRRPManager, self).__init__(*args, **kwargs)
self.CONF.register_opts([
cfg.IntOpt('vrrp-rpc-port', default=VRRP_RPC_PORT,
help='port for vrrp rpc interface')])
self._args = args
self._kwargs = kwargs
self._peers = []
@ -90,7 +89,7 @@ class RpcVRRPManager(app_manager.RyuApp):
hub.spawn(self._peer_loop_thread, peer)
def _peer_accept_thread(self):
server = hub.StreamServer(('', CONF.vrrp_rpc_port),
server = hub.StreamServer(('', self.CONF.vrrp_rpc_port),
self.peer_accept_handler)
server.serve_forever()

View File

@ -21,7 +21,7 @@ import signal
import sys
import traceback
from oslo.config import cfg
from ryu import cfg
# import all packet libraries.
PKT_LIB_PATH = 'ryu.lib.packet'

View File

@ -17,7 +17,7 @@ import logging
import struct
import time
import json
from oslo.config import cfg
from ryu import cfg
from ryu.topology import event
from ryu.base import app_manager
@ -453,10 +453,10 @@ class Switches(app_manager.RyuApp):
self.links = LinkState() # Link class -> timestamp
self.is_active = True
self.link_discovery = CONF.observe_links
self.link_discovery = self.CONF.observe_links
if self.link_discovery:
self.install_flow = CONF.install_lldp_flow
self.explicit_drop = CONF.explicit_drop
self.install_flow = self.CONF.install_lldp_flow
self.explicit_drop = self.CONF.explicit_drop
self.lldp_event = hub.Event()
self.link_event = hub.Event()
self.threads.append(hub.spawn(self.lldp_loop))