Config option for model handlers and backends

The model handlers and their corresponding backends can now be
specified in the configuration file of the shim layer. For every
model handler, one particular backend can be specified in a
dict.

Change-Id: I5866e921850b9bfc16f5815744f692bfe432b330
Signed-off-by: Georg Kunz <georg.kunz@ericsson.com>
This commit is contained in:
Georg Kunz 2017-01-14 02:36:27 +01:00
parent 5cda5853c3
commit eb89344383
5 changed files with 59 additions and 16 deletions

View File

@ -11,6 +11,11 @@ etcd_port = 2379
# host_list = host1,host2,host3
host_list = *
# Select the model to load with the corresponding backend. This config option is a dict
# where the key represents the name of the model and the value the name of the backend
# which is to be used for this model.
handlers = net-l3vpn:net-l3vpn-odl
[shim_odl]
# IP of the OpenDaylight RESTconf interface. Typically needs to be changed after installation.

View File

@ -27,8 +27,8 @@ LOG = logging.getLogger(__name__)
class ApiNetL3VPN(ApiModelBase):
def __init__(self, backend):
super(self.__class__, self).__init__("net-l3vpn", backend)
def __init__(self):
super(self.__class__, self).__init__("net-l3vpn")
self.resync_mode = False
self.model.vpn_instances = dict()
self.model.vpn_ports = dict()

View File

@ -22,7 +22,7 @@ from gluon.shim.model import Model
class ApiModelBase(object):
def __init__(self, _name, _backend):
def __init__(self, _name):
"""Init Method.
:param _name: name of the API Servce (e.g. net-l3vpn)
@ -30,9 +30,11 @@ class ApiModelBase(object):
:returns: None
"""
self.model = Model() # Internal Model for the API Service
self.backend = _backend # ControllerModelBase
self.name = _name
def init(self, backend):
self.backend = backend # ControllerModelBase
def handle_object_change(self, object, key, attributes, shim_data):
"""Called to update model based on changes to etcd database.

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import etcd
import json
import os
import sys
@ -21,13 +22,11 @@ import time
from Queue import Queue
from threading import Thread
import etcd
from oslo_config import cfg
from oslo_log import log as logging
from gluon.shim.api_models.net_l3vpn import ApiNetL3VPN
from gluon.shim.backends.opendaylight.odl_net_l3vpn import OdlNetL3VPN
from stevedore import extension
from gluon.shim.utils import pretty_print_message
@ -96,14 +95,40 @@ def process_message(message):
def setup_app():
#
# This should be config file driven to define the
# APIs that are handled and the backend to handle each API
#
backend = OdlNetL3VPN()
handler = ApiNetL3VPN(backend)
ShimData.api_handlers[handler.name] = handler
handler.load_model(ShimData)
api_models = extension.ExtensionManager(
namespace='gluon.shim.models',
invoke_on_load=True
)
backends = extension.ExtensionManager(
namespace='gluon.shim.backends',
invoke_on_load=True
)
def init_model(model, backends):
if model.obj.name in CONF.shim.handlers:
backend_name = CONF.shim.handlers[model.obj.name]
if backend_name in backends:
backend = backends[backend_name]
model.obj.init(backend.obj)
LOG.info('Loaded handler "%s" with backend "%s"' %
(model.obj.name, backend_name))
return model.obj
else:
LOG.error('Cannot load backend for handler "%s": '
'Selected backend "%s" not found.' %
(model.obj.name, backend_name))
else:
LOG.info('Handler "%s" not selected in config file. '
'Skipping initialization.' %
model.obj.name)
handlers = api_models.map(init_model, backends)
for handler in handlers:
if handler is not None:
ShimData.api_handlers[handler.name] = handler
handler.load_model(ShimData)
def prepare_service(argv=()):
@ -123,6 +148,10 @@ def main():
default='*',
help='Comma separated list of hostnames managed by '
'this server'),
cfg.DictOpt('handlers',
default={'net-l3vpn': 'net-l3vpn-odl'},
help='Dict for selecting the handlers '
'and their corresponding backend.')
]
opt_group = cfg.OptGroup(name='shim',
title='Options for the sample shim service')

View File

@ -39,6 +39,13 @@ gluon.backends =
gluon.managers =
net-l3vpn = gluon.managers.models.net_l3vpn:Provider
gluon.shim.models =
net-l3vpn = gluon.shim.api_models.net_l3vpn:ApiNetL3VPN
gluon.shim.backends =
net-l3vpn-odl = gluon.shim.backends.opendaylight.odl_net_l3vpn:OdlNetL3VPN
net-l3vpn-dummy = gluon.shim.backends.dummy_net_l3vpn:DummyNetL3VPN
neutron.core_plugins =
gluon = gluon.plugin.core:GluonPlugin