Refactor vitrage to use global CONF instead of local one
Remove usage of local config object in Vitrage services and tests. Instead, it's been replaced with the global CONF object. The structure of the code becomes more like in other OpenStack projects. Also, this change provides an opportunity to introduce migrations and tests for them. Story: 2004059 Task: 27065 Change-Id: I37544a350adf8ca38a6fc4ff5d0fd96e38a3f922
This commit is contained in:
parent
7c76bc764b
commit
66c608cb56
@ -22,9 +22,8 @@ LOG = log.getLogger(__name__)
|
||||
|
||||
class SampleDriver(DriverBase):
|
||||
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
super(SampleDriver, self).__init__()
|
||||
self.cfg = conf
|
||||
|
||||
@staticmethod
|
||||
def get_event_types():
|
||||
|
@ -28,8 +28,8 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
class SampleTransformer(ResourceTransformerBase):
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super(SampleTransformer, self).__init__(transformers, conf)
|
||||
def __init__(self, transformers):
|
||||
super(SampleTransformer, self).__init__(transformers)
|
||||
|
||||
def _create_snapshot_entity_vertex(self, entity_event):
|
||||
return self._create_vertex(entity_event)
|
||||
|
@ -22,9 +22,8 @@ LOG = log.getLogger(__name__)
|
||||
|
||||
class {{cookiecutter.name|capitalize}}Driver(DriverBase):
|
||||
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
super({{cookiecutter.name|capitalize}}Driver, self).__init__()
|
||||
self.cfg = conf
|
||||
|
||||
@staticmethod
|
||||
def get_event_types():
|
||||
|
@ -28,8 +28,8 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
class {{cookiecutter.name|capitalize}}Transformer(ResourceTransformerBase):
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super({{cookiecutter.name|capitalize}}Transformer, self).__init__(transformers, conf)
|
||||
def __init__(self, transformers:
|
||||
super({{cookiecutter.name|capitalize}}Transformer, self).__init__(transformers)
|
||||
|
||||
def _create_snapshot_entity_vertex(self, entity_event):
|
||||
return self._create_vertex(entity_event)
|
||||
|
@ -17,14 +17,17 @@ import sys
|
||||
import cotyledon
|
||||
from futurist import periodics
|
||||
from futurist import ThreadPoolExecutor
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
import oslo_messaging
|
||||
from tools.load_generator.notification_info import * # noqa
|
||||
|
||||
from vitrage.common import config
|
||||
from vitrage.messaging import get_transport
|
||||
from vitrage import service
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
EXISTING_COMPUTES_NUM = 64
|
||||
@ -62,12 +65,12 @@ to avoid Vitrage consistency deleting the created resources.
|
||||
|
||||
|
||||
class StressNotificationsService(cotyledon.Service):
|
||||
def __init__(self, worker_id, conf):
|
||||
def __init__(self, worker_id):
|
||||
super(StressNotificationsService, self).__init__(worker_id)
|
||||
self.oslo_notifier = None
|
||||
topics = conf.datasources.notification_topics
|
||||
topics = CONF.datasources.notification_topics
|
||||
self.oslo_notifier = oslo_messaging.Notifier(
|
||||
get_transport(conf),
|
||||
get_transport(),
|
||||
driver='messagingv2',
|
||||
publisher_id='vitrage.stress',
|
||||
topics=topics)
|
||||
@ -141,9 +144,9 @@ def create_vm(instance_num, compute_num):
|
||||
|
||||
|
||||
def main():
|
||||
conf = service.prepare_service()
|
||||
config.parse_config(sys.argv)
|
||||
sm = cotyledon.ServiceManager()
|
||||
sm.add(StressNotificationsService, args=(conf,))
|
||||
sm.add(StressNotificationsService)
|
||||
sm.run()
|
||||
|
||||
|
||||
|
@ -27,6 +27,8 @@ from werkzeug import serving
|
||||
|
||||
from vitrage.api import hooks
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
# NOTE(sileht): pastedeploy uses ConfigParser to handle
|
||||
@ -40,13 +42,13 @@ APPCONFIGS = {}
|
||||
|
||||
|
||||
def setup_app(root, conf=None):
|
||||
app_hooks = [hooks.ConfigHook(conf),
|
||||
app_hooks = [hooks.ConfigHook(),
|
||||
hooks.TranslationHook(),
|
||||
hooks.GCHook(),
|
||||
hooks.RPCHook(conf),
|
||||
hooks.RPCHook(),
|
||||
hooks.ContextHook(),
|
||||
hooks.DBHook(conf),
|
||||
hooks.CoordinatorHook(conf)]
|
||||
hooks.DBHook(),
|
||||
hooks.CoordinatorHook()]
|
||||
|
||||
app = pecan.make_app(
|
||||
root,
|
||||
@ -57,53 +59,52 @@ def setup_app(root, conf=None):
|
||||
return app
|
||||
|
||||
|
||||
def load_app(conf):
|
||||
def load_app():
|
||||
global APPCONFIGS
|
||||
|
||||
# Build the WSGI app
|
||||
cfg_path = conf.api.paste_config
|
||||
cfg_path = CONF.api.paste_config
|
||||
if not os.path.isabs(cfg_path):
|
||||
cfg_path = conf.find_file(cfg_path)
|
||||
cfg_path = CONF.find_file(cfg_path)
|
||||
|
||||
if cfg_path is None or not os.path.exists(cfg_path):
|
||||
raise cfg.ConfigFilesNotFoundError([conf.api.paste_config])
|
||||
raise cfg.ConfigFilesNotFoundError([CONF.api.paste_config])
|
||||
|
||||
config = dict(conf=conf)
|
||||
config = dict(conf=CONF)
|
||||
configkey = uuidutils.generate_uuid()
|
||||
APPCONFIGS[configkey] = config
|
||||
|
||||
LOG.info('Full WSGI config used: %s', cfg_path)
|
||||
|
||||
appname = "vitrage+" + conf.api.auth_mode
|
||||
appname = "vitrage+" + CONF.api.auth_mode
|
||||
return deploy.loadapp("config:" + cfg_path, name=appname,
|
||||
global_conf={'configkey': configkey})
|
||||
|
||||
|
||||
def build_server(conf):
|
||||
def build_server():
|
||||
uwsgi = spawn.find_executable("uwsgi")
|
||||
if not uwsgi:
|
||||
LOG.warning('uwsgi not installed, starting a TEST server')
|
||||
build_simple_server(conf)
|
||||
build_simple_server()
|
||||
else:
|
||||
build_uwsgi_server(conf, uwsgi)
|
||||
build_uwsgi_server(uwsgi)
|
||||
|
||||
|
||||
def wsgi_file():
|
||||
return path.join(path.dirname(__file__), 'app.wsgi')
|
||||
|
||||
|
||||
def build_uwsgi_server(conf, uwsgi):
|
||||
def build_uwsgi_server(uwsgi):
|
||||
|
||||
args = [
|
||||
"--if-not-plugin", "python", "--plugin", "python", "--endif",
|
||||
"--http-socket", "%s:%d" % (conf.api.host, conf.api.port),
|
||||
"--http-socket", "%s:%d" % (CONF.api.host, CONF.api.port),
|
||||
"--master",
|
||||
"--enable-threads",
|
||||
"--thunder-lock",
|
||||
"--hook-master-start", "unix_signal:15 gracefully_kill_them_all",
|
||||
"--die-on-term",
|
||||
"--processes", str(math.floor(conf.api.workers * 1.5)),
|
||||
"--threads", str(conf.api.workers),
|
||||
"--processes", str(math.floor(CONF.api.workers * 1.5)),
|
||||
"--threads", str(CONF.api.workers),
|
||||
"--lazy-apps",
|
||||
"--chdir", "/",
|
||||
"--buffer-size", "65535",
|
||||
@ -119,14 +120,14 @@ def build_uwsgi_server(conf, uwsgi):
|
||||
return os.execl(uwsgi, uwsgi, *args)
|
||||
|
||||
|
||||
def build_simple_server(conf):
|
||||
app = load_app(conf)
|
||||
def build_simple_server():
|
||||
app = load_app()
|
||||
# Create the WSGI server and start it
|
||||
host, port = conf.api.host, conf.api.port
|
||||
host, port = CONF.api.host, CONF.api.port
|
||||
|
||||
LOG.info('Starting server in PID %s', os.getpid())
|
||||
LOG.info('Configuration:')
|
||||
conf.log_opt_values(LOG, log.INFO)
|
||||
CONF.log_opt_values(LOG, log.INFO)
|
||||
|
||||
if host == '0.0.0.0':
|
||||
LOG.info(
|
||||
@ -139,7 +140,7 @@ def build_simple_server(conf):
|
||||
LOG.info('"DANGER! For testing only, do not use in production"')
|
||||
|
||||
serving.run_simple(host, port,
|
||||
app, processes=conf.api.workers)
|
||||
app, processes=CONF.api.workers)
|
||||
|
||||
|
||||
def app_factory(global_config, **local_conf):
|
||||
|
@ -14,8 +14,8 @@
|
||||
See http://pecan.readthedocs.org/en/latest/deployment.html for details.
|
||||
"""
|
||||
from vitrage.api import app
|
||||
from vitrage import service
|
||||
from vitrage.common import config
|
||||
|
||||
# Initialize the oslo configuration library and logging
|
||||
conf = service.prepare_service()
|
||||
application = app.load_app(conf)
|
||||
config.parse_config([])
|
||||
application = app.load_app()
|
||||
|
@ -12,6 +12,7 @@
|
||||
import gc
|
||||
import oslo_messaging
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_context import context
|
||||
from oslo_policy import policy
|
||||
from pecan import hooks
|
||||
@ -22,31 +23,32 @@ from vitrage import messaging
|
||||
from vitrage import rpc as vitrage_rpc
|
||||
from vitrage import storage
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class ConfigHook(hooks.PecanHook):
|
||||
"""Attach the configuration and policy enforcer object to the request. """
|
||||
|
||||
def __init__(self, conf):
|
||||
self.conf = conf
|
||||
self.enforcer = policy.Enforcer(conf)
|
||||
def __init__(self):
|
||||
self.enforcer = policy.Enforcer(CONF)
|
||||
self._register_rules()
|
||||
|
||||
def _register_rules(self):
|
||||
self.enforcer.register_defaults(policies.list_rules())
|
||||
|
||||
def before(self, state):
|
||||
state.request.cfg = self.conf
|
||||
state.request.cfg = CONF
|
||||
state.request.enforcer = self.enforcer
|
||||
|
||||
|
||||
class RPCHook(hooks.PecanHook):
|
||||
"""Create and attach an rpc to the request. """
|
||||
|
||||
def __init__(self, conf):
|
||||
transport = messaging.get_rpc_transport(conf)
|
||||
target = oslo_messaging.Target(topic=conf.rpc_topic)
|
||||
def __init__(self):
|
||||
transport = messaging.get_rpc_transport()
|
||||
target = oslo_messaging.Target(topic=CONF.rpc_topic)
|
||||
self.client = vitrage_rpc.get_client(transport, target)
|
||||
self.check_backend = conf.api.check_backend
|
||||
self.check_backend = CONF.api.check_backend
|
||||
|
||||
def on_route(self, state):
|
||||
state.request.client = self.client
|
||||
@ -87,8 +89,8 @@ class ContextHook(hooks.PecanHook):
|
||||
|
||||
class DBHook(hooks.PecanHook):
|
||||
|
||||
def __init__(self, conf):
|
||||
self.storage = storage.get_connection_from_config(conf)
|
||||
def __init__(self):
|
||||
self.storage = storage.get_connection_from_config()
|
||||
|
||||
def before(self, state):
|
||||
state.request.storage = self.storage
|
||||
@ -102,8 +104,8 @@ class GCHook(hooks.PecanHook):
|
||||
|
||||
class CoordinatorHook(hooks.PecanHook):
|
||||
|
||||
def __init__(self, conf):
|
||||
self.coordinator = coordination.Coordinator(conf)
|
||||
def __init__(self):
|
||||
self.coordinator = coordination.Coordinator()
|
||||
self.coordinator.start()
|
||||
self.coordinator.join_group()
|
||||
|
||||
|
@ -76,9 +76,8 @@ RESOURCES_ALL_QUERY = {
|
||||
|
||||
class EntityGraphApisBase(object):
|
||||
|
||||
def __init__(self, entity_graph, conf, api_lock, db=None):
|
||||
def __init__(self, entity_graph, api_lock, db=None):
|
||||
self.entity_graph = entity_graph
|
||||
self.conf = conf
|
||||
self.db = db
|
||||
self.api_lock = api_lock
|
||||
|
||||
|
@ -32,8 +32,7 @@ LOG = log.getLogger(__name__)
|
||||
info={}, hide_args=False, trace_private=False)
|
||||
class EventApis(object):
|
||||
|
||||
def __init__(self, conf):
|
||||
self.conf = conf
|
||||
def __init__(self):
|
||||
self._init_oslo_notifier()
|
||||
|
||||
def post(self, ctx, event_time, event_type, details):
|
||||
@ -65,7 +64,7 @@ class EventApis(object):
|
||||
self.publisher = 'api_%s' % socket.gethostname()
|
||||
|
||||
self.oslo_notifier = oslo_messaging.Notifier(
|
||||
get_transport(self.conf),
|
||||
get_transport(),
|
||||
driver='messagingv2',
|
||||
publisher_id=self.publisher,
|
||||
topics=['vitrage_notifications'])
|
||||
|
@ -19,8 +19,7 @@ LOG = log.getLogger(__name__)
|
||||
|
||||
class OperationalApis(object):
|
||||
|
||||
def __init__(self, conf, graph):
|
||||
self.conf = conf
|
||||
def __init__(self, graph):
|
||||
self.graph = graph
|
||||
|
||||
def is_alive(self, ctx):
|
||||
|
@ -31,9 +31,6 @@ LOG = log.getLogger(__name__)
|
||||
info={}, hide_args=False, trace_private=False)
|
||||
class ResourceApis(base.EntityGraphApisBase):
|
||||
|
||||
def __init__(self, entity_graph, conf, api_lock):
|
||||
super(ResourceApis, self).__init__(entity_graph, conf, api_lock)
|
||||
|
||||
@timed_method(log_results=True)
|
||||
@base.lock_graph
|
||||
def get_resources(self, ctx, resource_type=None, all_tenants=False,
|
||||
|
@ -34,9 +34,6 @@ LOG = log.getLogger(__name__)
|
||||
info={}, hide_args=False, trace_private=False)
|
||||
class TopologyApis(base.EntityGraphApisBase):
|
||||
|
||||
def __init__(self, entity_graph, conf, api_lock):
|
||||
super(TopologyApis, self).__init__(entity_graph, conf, api_lock)
|
||||
|
||||
@timed_method(log_results=True)
|
||||
@base.lock_graph
|
||||
def get_topology(self, ctx, graph_type, depth, query, root, all_tenants):
|
||||
|
@ -34,8 +34,7 @@ Result = namedtuple("Result", ["is_valid", "message"])
|
||||
class WebhookApis(object):
|
||||
DELETED_ROWS_SUCCESS = 1
|
||||
|
||||
def __init__(self, conf, db):
|
||||
self.conf = conf
|
||||
def __init__(self, db):
|
||||
self.db_conn = db
|
||||
|
||||
def delete_webhook(self, ctx, id):
|
||||
|
@ -16,13 +16,13 @@ import sys
|
||||
|
||||
from vitrage.api import app
|
||||
from vitrage.cli import VITRAGE_TITLE
|
||||
from vitrage import service
|
||||
from vitrage.common import config
|
||||
|
||||
|
||||
def main():
|
||||
print(VITRAGE_TITLE)
|
||||
conf = service.prepare_service()
|
||||
app.build_server(conf)
|
||||
config.parse_config(sys.argv)
|
||||
app.build_server()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -16,10 +16,10 @@ from oslo_log import log
|
||||
import sys
|
||||
|
||||
from vitrage.cli import VITRAGE_TITLE
|
||||
from vitrage.common import config
|
||||
from vitrage.common.utils import spawn
|
||||
from vitrage.entity_graph.graph_init import VitrageGraphInit
|
||||
from vitrage.entity_graph.workers import GraphWorkersManager
|
||||
from vitrage import service
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
@ -27,19 +27,19 @@ LOG = log.getLogger(__name__)
|
||||
def main():
|
||||
"""Main method of vitrage-graph"""
|
||||
|
||||
conf = service.prepare_service()
|
||||
LOG.info(VITRAGE_TITLE)
|
||||
|
||||
workers = GraphWorkersManager(conf)
|
||||
spawn(init, conf, workers)
|
||||
config.parse_config(sys.argv)
|
||||
workers = GraphWorkersManager()
|
||||
spawn(init, workers)
|
||||
workers.run()
|
||||
|
||||
|
||||
def init(conf, workers):
|
||||
def init(workers):
|
||||
# Because fork duplicates the process memory.
|
||||
# We should only create master process resources after workers are forked.
|
||||
workers.wait_for_worker_start()
|
||||
VitrageGraphInit(conf, workers).run()
|
||||
VitrageGraphInit(workers).run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
@ -16,15 +16,15 @@ import cotyledon
|
||||
import sys
|
||||
|
||||
from vitrage.cli import VITRAGE_TITLE
|
||||
from vitrage.common import config
|
||||
from vitrage.machine_learning.service import MachineLearningService
|
||||
from vitrage import service
|
||||
|
||||
|
||||
def main():
|
||||
print(VITRAGE_TITLE)
|
||||
conf = service.prepare_service()
|
||||
config.parse_config(sys.argv)
|
||||
sm = cotyledon.ServiceManager()
|
||||
sm.add(MachineLearningService, args=(conf,))
|
||||
sm.add(MachineLearningService)
|
||||
sm.run()
|
||||
|
||||
|
||||
|
@ -15,15 +15,15 @@ import cotyledon
|
||||
import sys
|
||||
|
||||
from vitrage.cli import VITRAGE_TITLE
|
||||
from vitrage.common import config
|
||||
from vitrage.notifier.service import VitrageNotifierService
|
||||
from vitrage import service
|
||||
|
||||
|
||||
def main():
|
||||
print(VITRAGE_TITLE)
|
||||
conf = service.prepare_service()
|
||||
config.parse_config(sys.argv)
|
||||
sm = cotyledon.ServiceManager()
|
||||
sm.add(VitrageNotifierService, args=(conf,))
|
||||
sm.add(VitrageNotifierService)
|
||||
sm.run()
|
||||
|
||||
|
||||
|
@ -16,9 +16,10 @@ import sys
|
||||
|
||||
import cotyledon
|
||||
from oslo_log import log
|
||||
|
||||
from vitrage.cli import VITRAGE_TITLE
|
||||
from vitrage.common import config
|
||||
from vitrage.persistency.service import PersistorService
|
||||
from vitrage import service
|
||||
from vitrage import storage
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
@ -26,10 +27,10 @@ LOG = log.getLogger(__name__)
|
||||
|
||||
def main():
|
||||
print(VITRAGE_TITLE)
|
||||
conf = service.prepare_service()
|
||||
db_connection = storage.get_connection_from_config(conf)
|
||||
config.parse_config(sys.argv)
|
||||
db_connection = storage.get_connection_from_config()
|
||||
sm = cotyledon.ServiceManager()
|
||||
sm.add(PersistorService, args=(conf, db_connection))
|
||||
sm.add(PersistorService, args=(db_connection,))
|
||||
sm.run()
|
||||
|
||||
|
||||
|
@ -15,16 +15,17 @@
|
||||
import sys
|
||||
|
||||
import cotyledon
|
||||
|
||||
from vitrage.cli import VITRAGE_TITLE
|
||||
from vitrage import service
|
||||
from vitrage.common import config
|
||||
from vitrage.snmp_parsing.service import SnmpParsingService
|
||||
|
||||
|
||||
def main():
|
||||
print(VITRAGE_TITLE)
|
||||
conf = service.prepare_service()
|
||||
config.parse_config(sys.argv)
|
||||
sm = cotyledon.ServiceManager()
|
||||
sm.add(SnmpParsingService, args=(conf,))
|
||||
sm.add(SnmpParsingService)
|
||||
sm.run()
|
||||
|
||||
|
||||
|
@ -12,21 +12,23 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import sys
|
||||
|
||||
from vitrage.cli import VITRAGE_TITLE
|
||||
from vitrage import service
|
||||
from vitrage.common import config
|
||||
from vitrage import storage
|
||||
|
||||
|
||||
def dbsync():
|
||||
print(VITRAGE_TITLE)
|
||||
conf = service.prepare_service()
|
||||
storage.get_connection_from_config(conf).upgrade()
|
||||
config.parse_config(sys.argv)
|
||||
storage.get_connection_from_config().upgrade()
|
||||
|
||||
|
||||
def purge_data():
|
||||
print(VITRAGE_TITLE)
|
||||
conf = service.prepare_service()
|
||||
db = storage.get_connection_from_config(conf)
|
||||
config.parse_config(sys.argv)
|
||||
db = storage.get_connection_from_config()
|
||||
db.active_actions.delete()
|
||||
db.events.delete()
|
||||
db.graph_snapshots.delete()
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright 2015 - Alcatel-Lucent
|
||||
#
|
||||
# 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
|
||||
@ -10,7 +10,6 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_db import options as db_options
|
||||
from oslo_log import log
|
||||
@ -20,47 +19,43 @@ from osprofiler import opts as osprofiler_opts
|
||||
from vitrage import keystone_client
|
||||
from vitrage import messaging
|
||||
from vitrage import opts
|
||||
from vitrage.opts import register_opts
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
def prepare_service(args=None, conf=None, config_files=None):
|
||||
def parse_config(args, default_config_files=None):
|
||||
set_defaults()
|
||||
if conf is None:
|
||||
conf = cfg.ConfigOpts()
|
||||
log.register_options(conf)
|
||||
policy_opts.set_defaults(conf)
|
||||
osprofiler_opts.set_defaults(conf)
|
||||
db_options.set_defaults(conf)
|
||||
log.register_options(CONF)
|
||||
policy_opts.set_defaults(CONF)
|
||||
osprofiler_opts.set_defaults(CONF)
|
||||
db_options.set_defaults(CONF)
|
||||
|
||||
for group, options in opts.list_opts():
|
||||
conf.register_opts(list(options),
|
||||
CONF.register_opts(list(options),
|
||||
group=None if group == 'DEFAULT' else group)
|
||||
|
||||
conf(args, project='vitrage', validate_default_values=True,
|
||||
default_config_files=config_files)
|
||||
CONF(args[1:], project='vitrage', validate_default_values=True,
|
||||
default_config_files=default_config_files)
|
||||
|
||||
if conf.profiler.enabled:
|
||||
if CONF.profiler.enabled:
|
||||
osprofiler_initializer.init_from_conf(
|
||||
conf=conf,
|
||||
conf=CONF,
|
||||
context=None,
|
||||
project="vitrage",
|
||||
service="api",
|
||||
host=conf.api.host)
|
||||
project='vitrage',
|
||||
service='api',
|
||||
host=CONF.api.host
|
||||
)
|
||||
|
||||
for datasource in conf.datasources.types:
|
||||
register_opts(conf, datasource, conf.datasources.path)
|
||||
for datasource in CONF.datasources.types:
|
||||
opts.register_opts(datasource, CONF.datasources.path)
|
||||
|
||||
keystone_client.register_keystoneauth_opts(conf)
|
||||
|
||||
log.setup(conf, 'vitrage')
|
||||
conf.log_opt_values(LOG, log.DEBUG)
|
||||
keystone_client.register_keystoneauth_opts()
|
||||
log.setup(CONF, 'vitrage')
|
||||
CONF.log_opt_values(LOG, log.DEBUG)
|
||||
messaging.setup()
|
||||
|
||||
return conf
|
||||
|
||||
|
||||
def set_defaults():
|
||||
from oslo_middleware import cors
|
@ -20,16 +20,17 @@ import six
|
||||
import tenacity
|
||||
import tooz.coordination
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from oslo_utils import timeutils
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class Coordinator(object):
|
||||
def __init__(self, conf, my_id=None):
|
||||
self.conf = conf
|
||||
self.backend_url = self.conf.coordination.backend_url
|
||||
def __init__(self, my_id=None):
|
||||
self.backend_url = CONF.coordination.backend_url
|
||||
self.my_id = my_id or ' '.join(psutil.Process(os.getpid()).cmdline())
|
||||
self.coordinator = None
|
||||
if self.backend_url:
|
||||
|
@ -19,10 +19,10 @@ from vitrage.coordination.coordination import Coordinator
|
||||
|
||||
class Service(cotyledon.Service):
|
||||
|
||||
def __init__(self, worker_id, conf):
|
||||
def __init__(self, worker_id):
|
||||
super(Service, self).__init__(worker_id)
|
||||
self.coordinator = Coordinator(conf, '%s worker(%s)' % (self.name,
|
||||
worker_id))
|
||||
self.coordinator = Coordinator('%s worker(%s)' % (self.name,
|
||||
worker_id))
|
||||
|
||||
def run(self):
|
||||
self.coordinator.start()
|
||||
|
@ -22,9 +22,6 @@ from vitrage.datasources import transformer_base as tbase
|
||||
|
||||
class AlarmTransformerBase(tbase.TransformerBase):
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super(AlarmTransformerBase, self).__init__(transformers, conf)
|
||||
|
||||
def _ok_status(self, entity_event):
|
||||
pass
|
||||
|
||||
|
@ -32,10 +32,9 @@ LOG = log.getLogger(__name__)
|
||||
|
||||
class AodhDriver(AlarmDriverBase):
|
||||
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
super(AodhDriver, self).__init__()
|
||||
self._client = None
|
||||
self.conf = conf
|
||||
self._init_aodh_event_actions()
|
||||
self._init_convert_aodh_alarm_rule_actions()
|
||||
self._init_alarm_type_to_rule()
|
||||
@ -86,7 +85,7 @@ class AodhDriver(AlarmDriverBase):
|
||||
@property
|
||||
def client(self):
|
||||
if not self._client:
|
||||
self._client = os_clients.aodh_client(self.conf)
|
||||
self._client = os_clients.aodh_client()
|
||||
return self._client
|
||||
|
||||
def _vitrage_type(self):
|
||||
|
@ -38,9 +38,6 @@ class AodhTransformer(AlarmTransformerBase):
|
||||
AodhEventType.DELETION: GraphAction.DELETE_ENTITY,
|
||||
}
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super(AodhTransformer, self).__init__(transformers, conf)
|
||||
|
||||
def _create_snapshot_entity_vertex(self, entity_event):
|
||||
if _is_vitrage_alarm(entity_event):
|
||||
return self._create_merge_alarm_vertex(entity_event)
|
||||
|
@ -32,17 +32,16 @@ LOG = log.getLogger(__name__)
|
||||
|
||||
class CeilometerDriver(AlarmDriverBase):
|
||||
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
super(CeilometerDriver, self).__init__()
|
||||
self._client = None
|
||||
self.conf = conf
|
||||
self._init_aodh_event_actions()
|
||||
self._cache_all_alarms()
|
||||
|
||||
@property
|
||||
def client(self):
|
||||
if not self._client:
|
||||
self._client = os_clients.ceilometer_client(self.conf)
|
||||
self._client = os_clients.ceilometer_client()
|
||||
return self._client
|
||||
|
||||
def _vitrage_type(self):
|
||||
|
@ -41,9 +41,6 @@ class CeilometerTransformer(AlarmTransformerBase):
|
||||
CeilEventType.DELETION: GraphAction.DELETE_ENTITY,
|
||||
}
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super(CeilometerTransformer, self).__init__(transformers, conf)
|
||||
|
||||
def _create_snapshot_entity_vertex(self, entity_event):
|
||||
if _is_vitrage_alarm(entity_event):
|
||||
return self._create_merge_alarm_vertex(entity_event)
|
||||
|
@ -21,15 +21,14 @@ from vitrage import os_clients
|
||||
|
||||
class CinderVolumeDriver(DriverBase):
|
||||
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
super(CinderVolumeDriver, self).__init__()
|
||||
self._client = None
|
||||
self.conf = conf
|
||||
|
||||
@property
|
||||
def client(self):
|
||||
if not self._client:
|
||||
self._client = os_clients.cinder_client(self.conf)
|
||||
self._client = os_clients.cinder_client()
|
||||
return self._client
|
||||
|
||||
@staticmethod
|
||||
|
@ -39,9 +39,6 @@ class CinderVolumeTransformer(ResourceTransformerBase):
|
||||
'volume.attach.end': GraphAction.UPDATE_RELATIONSHIP
|
||||
}
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super(CinderVolumeTransformer, self).__init__(transformers, conf)
|
||||
|
||||
def _create_snapshot_entity_vertex(self, entity_event):
|
||||
|
||||
volume_name = extract_field_value(entity_event,
|
||||
|
@ -12,6 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
from vitrage.common.constants import DatasourceAction
|
||||
@ -24,17 +25,17 @@ from vitrage.datasources.collectd.properties\
|
||||
import CollectdProperties as CProps
|
||||
from vitrage.utils import file as file_utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class CollectdDriver(AlarmDriverBase):
|
||||
conf_map = None
|
||||
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
super(CollectdDriver, self).__init__()
|
||||
self.conf = conf
|
||||
if not CollectdDriver.conf_map:
|
||||
mapper = CollectdDriver._configuration_mapping(conf)
|
||||
mapper = CollectdDriver._configuration_mapping()
|
||||
if mapper:
|
||||
CollectdDriver.conf_map = CollectdMapper(mapper)
|
||||
|
||||
@ -59,9 +60,9 @@ class CollectdDriver(AlarmDriverBase):
|
||||
and alarm[CProps.RESOURCE_NAME] is not None
|
||||
|
||||
@staticmethod
|
||||
def _configuration_mapping(conf):
|
||||
def _configuration_mapping():
|
||||
try:
|
||||
collectd_config_file = conf.collectd[DSOpts.CONFIG_FILE]
|
||||
collectd_config_file = CONF.collectd[DSOpts.CONFIG_FILE]
|
||||
collectd_config = file_utils.load_yaml_file(collectd_config_file)
|
||||
collectd_config_elements = collectd_config[COLLECTD_DATASOURCE]
|
||||
|
||||
|
@ -28,9 +28,6 @@ from vitrage.utils.datetime import format_unix_timestamp
|
||||
|
||||
class CollectdTransformer(AlarmTransformerBase):
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super(CollectdTransformer, self).__init__(transformers, conf)
|
||||
|
||||
def _create_snapshot_entity_vertex(self, entity_event):
|
||||
# The Collectd datasource does not support snapshot mode
|
||||
return None
|
||||
|
@ -29,8 +29,8 @@ class ConsistencyTransformer(ResourceTransformerBase):
|
||||
GraphAction.REMOVE_DELETED_ENTITY: GraphAction.REMOVE_DELETED_ENTITY
|
||||
}
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super(ConsistencyTransformer, self).__init__(transformers, conf)
|
||||
def __init__(self, transformers):
|
||||
super(ConsistencyTransformer, self).__init__(transformers)
|
||||
|
||||
def _create_snapshot_entity_vertex(self, entity_event):
|
||||
return self._create_vertex(entity_event)
|
||||
|
@ -32,9 +32,8 @@ LOG = log.getLogger(__name__)
|
||||
class DoctorDriver(AlarmDriverBase):
|
||||
AlarmKey = namedtuple('AlarmKey', ['alarm_name', 'hostname'])
|
||||
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
super(DoctorDriver, self).__init__()
|
||||
self.conf = conf
|
||||
self._client = None
|
||||
|
||||
def _vitrage_type(self):
|
||||
|
@ -35,9 +35,6 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
class DoctorTransformer(AlarmTransformerBase):
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super(DoctorTransformer, self).__init__(transformers, conf)
|
||||
|
||||
def _create_snapshot_entity_vertex(self, entity_event):
|
||||
# The Doctor monitor does not support snapshot mode
|
||||
return None
|
||||
|
@ -29,9 +29,6 @@ class DriverBase(object):
|
||||
|
||||
_datasource_name = None
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_all(self, datasource_action):
|
||||
pass
|
||||
|
@ -12,6 +12,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
from vitrage.common.constants import DatasourceAction
|
||||
from vitrage.common.constants import DatasourceProperties as DSProps
|
||||
from vitrage.common.constants import GraphAction
|
||||
@ -27,6 +29,8 @@ from vitrage.datasources.nova.instance.driver import InstanceDriver
|
||||
from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE
|
||||
from vitrage import os_clients
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class HeatStackDriver(DriverBase):
|
||||
|
||||
@ -44,21 +48,20 @@ class HeatStackDriver(DriverBase):
|
||||
'OS::Neutron::Port': PortDriver
|
||||
}
|
||||
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
super(HeatStackDriver, self).__init__()
|
||||
self._client = None
|
||||
self._conf = conf
|
||||
self._filter_resource_types()
|
||||
|
||||
@property
|
||||
def client(self):
|
||||
if not self._client:
|
||||
self._client = os_clients.heat_client(self._conf)
|
||||
self._client = os_clients.heat_client()
|
||||
return self._client
|
||||
|
||||
@staticmethod
|
||||
def get_topic(conf):
|
||||
return conf[HEAT_STACK_DATASOURCE].notification_topic
|
||||
def get_topic():
|
||||
return CONF[HEAT_STACK_DATASOURCE].notification_topic
|
||||
|
||||
@staticmethod
|
||||
def get_event_types():
|
||||
@ -93,7 +96,7 @@ class HeatStackDriver(DriverBase):
|
||||
return self.client.stacks.get(_id).to_dict()['parent']
|
||||
|
||||
def _filter_resource_types(self):
|
||||
types = self._conf.datasources.types
|
||||
types = CONF.datasources.types
|
||||
|
||||
self.RESOURCE_TYPE = {key: value for key, value in
|
||||
self.RESOURCE_TYPE.items() if value in types}
|
||||
|
@ -46,9 +46,6 @@ class HeatStackTransformer(ResourceTransformerBase):
|
||||
'orchestration.stack.delete.end': GraphAction.DELETE_ENTITY,
|
||||
}
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super(HeatStackTransformer, self).__init__(transformers, conf)
|
||||
|
||||
def _create_snapshot_entity_vertex(self, entity_event):
|
||||
|
||||
stack_name = extract_field_value(entity_event, StackProps.STACK_NAME)
|
||||
|
@ -14,11 +14,13 @@
|
||||
|
||||
import re
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
from vitrage.common.constants import DatasourceOpts as DSOpts
|
||||
from vitrage.utils import file as file_utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
KAPACITOR_HOST = 'kapacitor_host'
|
||||
KAPACITOR = 'kapacitor'
|
||||
@ -30,9 +32,9 @@ VITRAGE_RESOURCE = 'vitrage_resource'
|
||||
|
||||
|
||||
class KapacitorConfig(object):
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
try:
|
||||
kapacitor_config_file = conf.kapacitor[DSOpts.CONFIG_FILE]
|
||||
kapacitor_config_file = CONF.kapacitor[DSOpts.CONFIG_FILE]
|
||||
kapacitor_config = file_utils.load_yaml_file(kapacitor_config_file)
|
||||
kapacitor = kapacitor_config[KAPACITOR]
|
||||
|
||||
|
@ -32,12 +32,11 @@ class KapacitorDriver(AlarmDriverBase):
|
||||
ServiceKey = namedtuple('ServiceKey', ['hostname', 'alarmid'])
|
||||
conf_map = None
|
||||
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
super(KapacitorDriver, self).__init__()
|
||||
self.cfg = conf
|
||||
|
||||
if not KapacitorDriver.conf_map:
|
||||
self.conf_map = KapacitorConfig(conf)
|
||||
self.conf_map = KapacitorConfig()
|
||||
self._client = None
|
||||
|
||||
@staticmethod
|
||||
|
@ -34,9 +34,6 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
class KapacitorTransformer(AlarmTransformerBase):
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super(KapacitorTransformer, self).__init__(transformers, conf)
|
||||
|
||||
def _create_snapshot_entity_vertex(self, entity_event):
|
||||
return self._create_vertex(entity_event)
|
||||
|
||||
|
@ -14,36 +14,37 @@
|
||||
|
||||
from kubernetes import client
|
||||
from kubernetes import config
|
||||
from oslo_log import cfg
|
||||
from oslo_log import log
|
||||
from vitrage.datasources.driver_base import DriverBase
|
||||
from vitrage.datasources.kubernetes.properties import KUBERNETES_DATASOURCE
|
||||
from vitrage.datasources.kubernetes.properties import KubernetesProperties\
|
||||
as kubProp
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class KubernetesDriver(DriverBase):
|
||||
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
super(KubernetesDriver, self).__init__()
|
||||
self._client = None
|
||||
self.conf = conf
|
||||
|
||||
@property
|
||||
def client(self):
|
||||
if not self._client:
|
||||
self._client = self._k8s_client(self.conf)
|
||||
self._client = self._k8s_client()
|
||||
return self._client
|
||||
|
||||
@staticmethod
|
||||
def _k8s_client(conf):
|
||||
def _k8s_client():
|
||||
try:
|
||||
if not conf.kubernetes.config_file:
|
||||
if not CONF.kubernetes.config_file:
|
||||
LOG.warning('kubernetes config file is not defined')
|
||||
return
|
||||
|
||||
kubeconf = conf.kubernetes.config_file
|
||||
kubeconf = CONF.kubernetes.config_file
|
||||
config.load_kube_config(config_file=kubeconf)
|
||||
k8s_client = client.CoreV1Api()
|
||||
if k8s_client is None:
|
||||
|
@ -11,6 +11,7 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
||||
from vitrage.common.constants import DatasourceProperties as DSProps
|
||||
@ -32,13 +33,11 @@ from vitrage.datasources.kubernetes.properties import \
|
||||
KubernetesProperties as kubProp
|
||||
from vitrage.utils import file as file_utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class KubernetesTransformer(ResourceTransformerBase):
|
||||
def __init__(self, transformers, conf):
|
||||
super(KubernetesTransformer, self).__init__(transformers, conf)
|
||||
self.conf = conf
|
||||
|
||||
def _create_vertex(self, entity_event):
|
||||
metadata = {
|
||||
@ -84,7 +83,7 @@ class KubernetesTransformer(ResourceTransformerBase):
|
||||
return KUBERNETES_DATASOURCE
|
||||
|
||||
def _get_cluster_name(self):
|
||||
kubeconf = file_utils.load_yaml_file(self.conf.kubernetes.config_file)
|
||||
kubeconf = file_utils.load_yaml_file(CONF.kubernetes.config_file)
|
||||
if not kubeconf:
|
||||
return None
|
||||
contexts = kubeconf['contexts']
|
||||
|
@ -28,15 +28,14 @@ LOG = log.getLogger(__name__)
|
||||
|
||||
class MonascaDriver(AlarmDriverBase):
|
||||
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
super(MonascaDriver, self).__init__()
|
||||
self.conf = conf
|
||||
self.__client = None
|
||||
|
||||
@property
|
||||
def client(self):
|
||||
if not self.__client:
|
||||
self.__client = os_clients.monasca_client(self.conf)
|
||||
self.__client = os_clients.monasca_client()
|
||||
return self.__client
|
||||
|
||||
def _vitrage_type(self):
|
||||
|
@ -14,11 +14,13 @@
|
||||
|
||||
import re
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
from vitrage.common.constants import DatasourceOpts as DSOpts
|
||||
from vitrage.utils import file as file_utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
NAGIOS_HOST = 'nagios_host'
|
||||
NAGIOS = 'nagios'
|
||||
@ -28,9 +30,9 @@ NAME = 'name'
|
||||
|
||||
|
||||
class NagiosConfig(object):
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
try:
|
||||
nagios_config_file = conf.nagios[DSOpts.CONFIG_FILE]
|
||||
nagios_config_file = CONF.nagios[DSOpts.CONFIG_FILE]
|
||||
nagios_config = file_utils.load_yaml_file(nagios_config_file)
|
||||
nagios = nagios_config[NAGIOS] # nagios root in the yaml file
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
import requests
|
||||
|
||||
@ -26,16 +27,16 @@ from vitrage.datasources.nagios.properties import NagiosProperties\
|
||||
as NagiosProps
|
||||
from vitrage.datasources.nagios.properties import NagiosTestStatus
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class NagiosDriver(AlarmDriverBase):
|
||||
ServiceKey = namedtuple('ServiceKey', ['hostname', 'service'])
|
||||
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
super(NagiosDriver, self).__init__()
|
||||
self.conf = conf
|
||||
self.config = NagiosConfig(conf)
|
||||
self.config = NagiosConfig()
|
||||
|
||||
def _vitrage_type(self):
|
||||
return NAGIOS_DATASOURCE
|
||||
@ -45,9 +46,9 @@ class NagiosDriver(AlarmDriverBase):
|
||||
service=alarm[NagiosProps.SERVICE])
|
||||
|
||||
def _get_alarms(self):
|
||||
nagios_user = self.conf.nagios.user
|
||||
nagios_password = self.conf.nagios.password
|
||||
nagios_url = self.conf.nagios.url
|
||||
nagios_user = CONF.nagios.user
|
||||
nagios_password = CONF.nagios.password
|
||||
nagios_url = CONF.nagios.url
|
||||
|
||||
if not nagios_user:
|
||||
return []
|
||||
|
@ -27,9 +27,6 @@ from vitrage.utils import datetime as datetime_utils
|
||||
|
||||
class NagiosTransformer(AlarmTransformerBase):
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super(NagiosTransformer, self).__init__(transformers, conf)
|
||||
|
||||
def _create_snapshot_entity_vertex(self, entity_event):
|
||||
return self._create_vertex(entity_event)
|
||||
|
||||
|
@ -18,13 +18,12 @@ from vitrage import os_clients
|
||||
|
||||
|
||||
class NeutronBase(DriverBase):
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
super(NeutronBase, self).__init__()
|
||||
self._client = None
|
||||
self.conf = conf
|
||||
|
||||
@property
|
||||
def client(self):
|
||||
if not self._client:
|
||||
self._client = os_clients.neutron_client(self.conf)
|
||||
self._client = os_clients.neutron_client()
|
||||
return self._client
|
||||
|
@ -40,9 +40,6 @@ class NetworkTransformer(ResourceTransformerBase):
|
||||
'network.delete.end': GraphAction.DELETE_ENTITY,
|
||||
}
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super(NetworkTransformer, self).__init__(transformers, conf)
|
||||
|
||||
def _create_snapshot_entity_vertex(self, entity_event):
|
||||
|
||||
name = entity_event[NetworkProps.NAME]
|
||||
|
@ -51,9 +51,6 @@ class PortTransformer(ResourceTransformerBase):
|
||||
'port.delete.end': GraphAction.DELETE_ENTITY,
|
||||
}
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super(PortTransformer, self).__init__(transformers, conf)
|
||||
|
||||
def _create_snapshot_entity_vertex(self, entity_event):
|
||||
|
||||
name = entity_event[PortProps.NAME]\
|
||||
|
@ -33,9 +33,6 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
class HostTransformer(ResourceTransformerBase):
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super(HostTransformer, self).__init__(transformers, conf)
|
||||
|
||||
def _create_snapshot_entity_vertex(self, entity_event):
|
||||
return self._create_vertex(entity_event,
|
||||
entity_event.get(HostProps.HOST))
|
||||
|
@ -12,6 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
from vitrage.common.constants import DatasourceAction
|
||||
from vitrage.common.constants import DatasourceProperties as DSProps
|
||||
from vitrage.common.constants import GraphAction
|
||||
@ -19,6 +20,8 @@ from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE
|
||||
from vitrage.datasources.nova.nova_driver_base import NovaDriverBase
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
# versioned notifications
|
||||
VERSIONED_NOTIFICATIONS = {
|
||||
'instance.create.end',
|
||||
@ -114,7 +117,7 @@ class InstanceDriver(NovaDriverBase):
|
||||
*self.properties_to_filter_out())
|
||||
|
||||
def enrich_event(self, event, event_type):
|
||||
use_versioned = self.conf.use_nova_versioned_notifications
|
||||
use_versioned = CONF.use_nova_versioned_notifications
|
||||
|
||||
# Send to the processor only events of the matching types. Nova may
|
||||
# send both versioned and legacy notifications, and we don't want to
|
||||
|
@ -11,6 +11,8 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
|
||||
from vitrage.common.constants import DatasourceProperties as DSProps
|
||||
@ -32,6 +34,7 @@ from vitrage.datasources import transformer_base as tbase
|
||||
from vitrage.datasources.transformer_base import extract_field_value
|
||||
import vitrage.graph.utils as graph_utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -47,9 +50,6 @@ class InstanceTransformer(ResourceTransformerBase):
|
||||
'instance.delete.end': GraphAction.DELETE_ENTITY,
|
||||
}
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super(InstanceTransformer, self).__init__(transformers, conf)
|
||||
|
||||
def _create_snapshot_entity_vertex(self, entity_event):
|
||||
LOG.debug('got snapshot')
|
||||
return self._create_vertex(entity_event)
|
||||
@ -134,7 +134,7 @@ class InstanceTransformer(ResourceTransformerBase):
|
||||
"""Return an object that extracts the field values from the event"""
|
||||
if tbase.is_update_event(event):
|
||||
return self.versioned_notifications_extractor if \
|
||||
self.conf.use_nova_versioned_notifications is True else \
|
||||
CONF.use_nova_versioned_notifications is True else \
|
||||
self.legacy_notifications_extractor
|
||||
else:
|
||||
return self.snapshot_extractor
|
||||
|
@ -18,13 +18,12 @@ from vitrage import os_clients
|
||||
|
||||
|
||||
class NovaDriverBase(DriverBase):
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
super(NovaDriverBase, self).__init__()
|
||||
self._client = None
|
||||
self.conf = conf
|
||||
|
||||
@property
|
||||
def client(self):
|
||||
if not self._client:
|
||||
self._client = os_clients.nova_client(self.conf)
|
||||
self._client = os_clients.nova_client()
|
||||
return self._client
|
||||
|
@ -38,9 +38,6 @@ class ZoneTransformer(ResourceTransformerBase):
|
||||
STATE_AVAILABLE = 'available'
|
||||
STATE_UNAVAILABLE = 'unavailable'
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super(ZoneTransformer, self).__init__(transformers, conf)
|
||||
|
||||
def _create_snapshot_entity_vertex(self, entity_event):
|
||||
|
||||
zone_name = extract_field_value(entity_event, ZoneProps.ZONE_NAME)
|
||||
|
@ -16,6 +16,7 @@ import socket
|
||||
|
||||
from collections import namedtuple
|
||||
from ipaddress import ip_address
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
import requests
|
||||
import six
|
||||
@ -46,6 +47,7 @@ from vitrage.datasources.prometheus.properties \
|
||||
from vitrage import os_clients
|
||||
from vitrage.utils import file as file_utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
PROMETHEUS_EVENT_TYPE = 'prometheus.alarm'
|
||||
@ -132,17 +134,16 @@ class PrometheusDriver(AlarmDriverBase):
|
||||
PCFProps.RESOURCE])
|
||||
conf_map = {}
|
||||
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
super(PrometheusDriver, self).__init__()
|
||||
self.conf = conf
|
||||
self._client = None
|
||||
self._nova_client = None
|
||||
self.conf_map = self._configuration_mapping(conf)
|
||||
self.conf_map = self._configuration_mapping()
|
||||
|
||||
@property
|
||||
def nova_client(self):
|
||||
if not self._nova_client:
|
||||
self._nova_client = os_clients.nova_client(self.conf)
|
||||
self._nova_client = os_clients.nova_client()
|
||||
return self._nova_client
|
||||
|
||||
def _vitrage_type(self):
|
||||
@ -167,8 +168,8 @@ class PrometheusDriver(AlarmDriverBase):
|
||||
old_alarm.get(PAlertProps.STATUS)
|
||||
|
||||
def _get_all_alarms(self):
|
||||
alertmanager_url = self.conf.prometheus.alertmanager_url
|
||||
receiver = self.conf.prometheus.receiver
|
||||
alertmanager_url = CONF.prometheus.alertmanager_url
|
||||
receiver = CONF.prometheus.receiver
|
||||
if not alertmanager_url:
|
||||
LOG.warning('Alertmanager url is not defined')
|
||||
return []
|
||||
@ -209,8 +210,8 @@ class PrometheusDriver(AlarmDriverBase):
|
||||
return []
|
||||
|
||||
@staticmethod
|
||||
def _configuration_mapping(conf):
|
||||
prometheus_config_file = conf.prometheus[DSOpts.CONFIG_FILE]
|
||||
def _configuration_mapping():
|
||||
prometheus_config_file = CONF.prometheus[DSOpts.CONFIG_FILE]
|
||||
try:
|
||||
prometheus_config = \
|
||||
file_utils.load_yaml_file(prometheus_config_file)
|
||||
|
@ -38,9 +38,6 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
class PrometheusTransformer(AlarmTransformerBase):
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super(PrometheusTransformer, self).__init__(transformers, conf)
|
||||
|
||||
def _create_snapshot_entity_vertex(self, entity_event):
|
||||
return self._create_vertex(entity_event)
|
||||
|
||||
|
@ -16,6 +16,4 @@ from vitrage.datasources import transformer_base as tbase
|
||||
|
||||
|
||||
class ResourceTransformerBase(tbase.TransformerBase):
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super(ResourceTransformerBase, self).__init__(transformers, conf)
|
||||
pass
|
||||
|
@ -16,6 +16,7 @@ from itertools import chain
|
||||
from jsonschema import validate
|
||||
from six.moves import reduce
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
from vitrage.common.constants import DatasourceProperties as DSProps
|
||||
@ -26,6 +27,7 @@ from vitrage.datasources.static import STATIC_SCHEMA
|
||||
from vitrage.datasources.static import StaticFields
|
||||
from vitrage.utils import file as file_utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
@ -35,9 +37,8 @@ class StaticDriver(DriverBase):
|
||||
StaticFields.TYPE,
|
||||
StaticFields.ID}
|
||||
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
super(StaticDriver, self).__init__()
|
||||
self.cfg = conf
|
||||
self.entities_cache = []
|
||||
|
||||
@staticmethod
|
||||
@ -77,7 +78,7 @@ class StaticDriver(DriverBase):
|
||||
return self.entities_cache
|
||||
|
||||
def _get_all_entities(self):
|
||||
files = file_utils.list_files(self.cfg.static.directory, '.yaml', True)
|
||||
files = file_utils.list_files(CONF.static.directory, '.yaml', True)
|
||||
return list(reduce(chain, [self._get_entities_from_file(path)
|
||||
for path in files], []))
|
||||
|
||||
|
@ -29,9 +29,6 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
class StaticTransformer(ResourceTransformerBase):
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super(StaticTransformer, self).__init__(transformers, conf)
|
||||
|
||||
def _create_snapshot_entity_vertex(self, entity_event):
|
||||
return self._create_vertex(entity_event)
|
||||
|
||||
|
@ -17,6 +17,7 @@ import abc
|
||||
from collections import namedtuple
|
||||
import six
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import uuidutils
|
||||
|
||||
@ -35,6 +36,7 @@ import vitrage.graph.utils as graph_utils
|
||||
from vitrage.utils import datetime as datetime_utils
|
||||
from vitrage.utils import opt_exists
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
EntityWrapper = \
|
||||
@ -109,8 +111,7 @@ class TransformerBase(object):
|
||||
|
||||
key_to_uuid_cache = {}
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
self.conf = conf
|
||||
def __init__(self, transformers):
|
||||
self.transformers = transformers
|
||||
|
||||
def transform(self, entity_event):
|
||||
@ -138,11 +139,11 @@ class TransformerBase(object):
|
||||
|
||||
def _create_entity_vertex(self, entity_event):
|
||||
if is_update_event(entity_event) and \
|
||||
opt_exists(self.conf, self.get_vitrage_type()) and \
|
||||
opt_exists(self.conf[self.get_vitrage_type()],
|
||||
opt_exists(CONF, self.get_vitrage_type()) and \
|
||||
opt_exists(CONF[self.get_vitrage_type()],
|
||||
DSOpts.UPDATE_METHOD):
|
||||
update_method = \
|
||||
self.conf[self.get_vitrage_type()].update_method.lower()
|
||||
CONF[self.get_vitrage_type()].update_method.lower()
|
||||
if update_method == UpdateMethod.PUSH:
|
||||
vertex = self._create_update_entity_vertex(entity_event)
|
||||
return self.update_uuid_in_vertex(vertex)
|
||||
|
@ -27,8 +27,8 @@ LOG = log.getLogger(__name__)
|
||||
|
||||
class TroveClusterDriver(TroveDriverBase):
|
||||
|
||||
def __init__(self, conf):
|
||||
super(TroveClusterDriver, self).__init__(conf)
|
||||
def __init__(self):
|
||||
super(TroveClusterDriver, self).__init__()
|
||||
self._cached_entities = []
|
||||
|
||||
def _get_vitrage_type(self):
|
||||
|
@ -26,8 +26,8 @@ LOG = log.getLogger(__name__)
|
||||
|
||||
class TroveInstanceDriver(TroveDriverBase):
|
||||
|
||||
def __init__(self, conf):
|
||||
super(TroveInstanceDriver, self).__init__(conf)
|
||||
def __init__(self):
|
||||
super(TroveInstanceDriver, self).__init__()
|
||||
self._cached_entities = []
|
||||
|
||||
def _get_vitrage_type(self):
|
||||
|
@ -23,16 +23,15 @@ from vitrage import os_clients
|
||||
|
||||
class TroveDriverBase(DriverBase):
|
||||
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
super(TroveDriverBase, self).__init__()
|
||||
self.conf = conf
|
||||
self.__client = None
|
||||
self.__cached_entities = []
|
||||
|
||||
@property
|
||||
def client(self):
|
||||
if not self.__client:
|
||||
self.__client = os_clients.trove_client(self.conf)
|
||||
self.__client = os_clients.trove_client()
|
||||
return self.__client
|
||||
|
||||
def get_all(self, datasource_action):
|
||||
|
@ -11,34 +11,38 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_utils import importutils as utils
|
||||
|
||||
from vitrage.common.constants import DatasourceOpts as DSOpts
|
||||
from vitrage.common.constants import UpdateMethod
|
||||
from vitrage.utils import opt_exists
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
drivers = {}
|
||||
|
||||
|
||||
# noinspection PyProtectedMember
|
||||
def get_drivers_by_name(conf, driver_names):
|
||||
def get_drivers_by_name(driver_names):
|
||||
for d_name in driver_names:
|
||||
if not drivers.get(d_name):
|
||||
drivers[d_name] = utils.import_object(conf[d_name].driver, conf)
|
||||
drivers[d_name] = utils.import_object(CONF[d_name].driver)
|
||||
drivers[d_name].__class__._datasource_name = d_name
|
||||
return [drivers[d_name] for d_name in driver_names]
|
||||
|
||||
|
||||
def get_pull_drivers_names(conf):
|
||||
return [name for name in conf.datasources.types
|
||||
if conf[name].update_method.lower() == UpdateMethod.PULL
|
||||
and opt_exists(conf[name], DSOpts.CHANGES_INTERVAL)]
|
||||
def get_pull_drivers_names():
|
||||
return [name for name in CONF.datasources.types
|
||||
if CONF[name].update_method.lower() == UpdateMethod.PULL
|
||||
and opt_exists(CONF[name], DSOpts.CHANGES_INTERVAL)]
|
||||
|
||||
|
||||
def get_push_drivers_names(conf):
|
||||
return [name for name in conf.datasources.types
|
||||
if conf[name].update_method.lower() == UpdateMethod.PUSH]
|
||||
def get_push_drivers_names():
|
||||
return [name for name in CONF.datasources.types
|
||||
if CONF[name].update_method.lower() == UpdateMethod.PUSH]
|
||||
|
||||
|
||||
def get_driver_class(conf, driver_name):
|
||||
return utils.import_class(conf[driver_name].driver)
|
||||
def get_driver_class(driver_name):
|
||||
return utils.import_class(CONF[driver_name].driver)
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from oslo_utils import importutils as utils
|
||||
|
||||
@ -29,6 +30,7 @@ from vitrage.datasources.zabbix.properties import ZabbixTriggerValue \
|
||||
from vitrage.datasources.zabbix import ZABBIX_DATASOURCE
|
||||
from vitrage.utils import file as file_utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
@ -36,30 +38,29 @@ class ZabbixDriver(AlarmDriverBase):
|
||||
ServiceKey = namedtuple('ServiceKey', ['hostname', 'triggerid'])
|
||||
conf_map = None
|
||||
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
super(ZabbixDriver, self).__init__()
|
||||
self.conf = conf
|
||||
if not ZabbixDriver.conf_map:
|
||||
ZabbixDriver.conf_map =\
|
||||
ZabbixDriver._configuration_mapping(conf)
|
||||
ZabbixDriver._configuration_mapping()
|
||||
self._client = None
|
||||
|
||||
def zabbix_client_login(self):
|
||||
if not self.conf.zabbix.user:
|
||||
if not CONF.zabbix.user:
|
||||
LOG.warning('Zabbix user is not defined')
|
||||
if not self.conf.zabbix.password:
|
||||
if not CONF.zabbix.password:
|
||||
LOG.warning('Zabbix password is not defined')
|
||||
if not self.conf.zabbix.url:
|
||||
if not CONF.zabbix.url:
|
||||
LOG.warning('Zabbix url is not defined')
|
||||
|
||||
try:
|
||||
if not self._client:
|
||||
self._client = utils.import_object(
|
||||
'pyzabbix.ZabbixAPI',
|
||||
self.conf.zabbix.url)
|
||||
CONF.zabbix.url)
|
||||
self._client.login(
|
||||
self.conf.zabbix.user,
|
||||
self.conf.zabbix.password)
|
||||
CONF.zabbix.user,
|
||||
CONF.zabbix.password)
|
||||
except Exception:
|
||||
LOG.exception('pyzabbix.ZabbixAPI error occurred.')
|
||||
self._client = None
|
||||
@ -154,9 +155,9 @@ class ZabbixDriver(AlarmDriverBase):
|
||||
return alarm[ZProps.VALUE]
|
||||
|
||||
@staticmethod
|
||||
def _configuration_mapping(conf):
|
||||
def _configuration_mapping():
|
||||
try:
|
||||
zabbix_config_file = conf.zabbix[DSOpts.CONFIG_FILE]
|
||||
zabbix_config_file = CONF.zabbix[DSOpts.CONFIG_FILE]
|
||||
zabbix_config = file_utils.load_yaml_file(zabbix_config_file)
|
||||
zabbix_config_elements = zabbix_config[ZABBIX_DATASOURCE]
|
||||
|
||||
|
@ -32,9 +32,6 @@ from vitrage.utils.datetime import format_unix_timestamp
|
||||
|
||||
class ZabbixTransformer(AlarmTransformerBase):
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super(ZabbixTransformer, self).__init__(transformers, conf)
|
||||
|
||||
def _create_snapshot_entity_vertex(self, entity_event):
|
||||
return self._create_vertex(entity_event)
|
||||
|
||||
|
@ -17,6 +17,8 @@ from oslo_config import cfg
|
||||
|
||||
from stevedore import driver
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
OPTS = [
|
||||
cfg.StrOpt('datasources_values_dir',
|
||||
default='/etc/vitrage/datasources_values',
|
||||
@ -35,10 +37,10 @@ OPTS = [
|
||||
EVALUATOR_TOPIC = 'vitrage.evaluator'
|
||||
|
||||
|
||||
def get_graph_driver(conf):
|
||||
def get_graph_driver():
|
||||
try:
|
||||
mgr = driver.DriverManager('vitrage.entity_graph',
|
||||
conf.entity_graph.graph_driver,
|
||||
CONF.entity_graph.graph_driver,
|
||||
invoke_on_load=True)
|
||||
return mgr.driver
|
||||
except ImportError:
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
from vitrage.common.constants import DatasourceAction
|
||||
@ -30,18 +31,17 @@ from vitrage.evaluator.actions.evaluator_event_transformer \
|
||||
from vitrage.messaging import VitrageNotifier
|
||||
from vitrage.utils.datetime import utcnow
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class ConsistencyEnforcer(object):
|
||||
|
||||
def __init__(self,
|
||||
conf,
|
||||
entity_graph,
|
||||
actions_callback=None):
|
||||
self.conf = conf
|
||||
self.actions_callback = actions_callback or VitrageNotifier(
|
||||
conf, 'vitrage_consistency', [EVALUATOR_TOPIC]).notify
|
||||
'vitrage_consistency', [EVALUATOR_TOPIC]).notify
|
||||
self.graph = entity_graph
|
||||
self._init_datasources_to_mark_deleted()
|
||||
|
||||
@ -73,7 +73,7 @@ class ConsistencyEnforcer(object):
|
||||
|
||||
def _find_outdated_entities_to_mark_as_deleted(self):
|
||||
vitrage_sample_tstmp = str(utcnow() - timedelta(
|
||||
seconds=2 * self.conf.datasources.snapshots_interval))
|
||||
seconds=2 * CONF.datasources.snapshots_interval))
|
||||
query = {
|
||||
'and': [
|
||||
{'!=': {VProps.VITRAGE_TYPE: VITRAGE_DATASOURCE}},
|
||||
@ -87,7 +87,7 @@ class ConsistencyEnforcer(object):
|
||||
|
||||
def _find_old_deleted_entities(self):
|
||||
vitrage_sample_tstmp = str(utcnow() - timedelta(
|
||||
seconds=self.conf.consistency.min_time_to_delete))
|
||||
seconds=CONF.consistency.min_time_to_delete))
|
||||
query = {
|
||||
'and': [
|
||||
{'==': {VProps.VITRAGE_IS_DELETED: True}},
|
||||
@ -140,8 +140,8 @@ class ConsistencyEnforcer(object):
|
||||
def _init_datasources_to_mark_deleted(self):
|
||||
self.datasources_to_mark_deleted = []
|
||||
|
||||
for driver_name in self.conf.datasources.types:
|
||||
driver_class = utils.get_driver_class(self.conf, driver_name)
|
||||
for driver_name in CONF.datasources.types:
|
||||
driver_class = utils.get_driver_class(driver_name)
|
||||
if driver_class.should_delete_outdated_entities():
|
||||
self.datasources_to_mark_deleted.append(driver_name)
|
||||
|
||||
|
@ -15,6 +15,7 @@ from collections import defaultdict
|
||||
import threading
|
||||
import time
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
import oslo_messaging
|
||||
|
||||
@ -22,18 +23,18 @@ from vitrage.common.constants import DatasourceAction
|
||||
from vitrage.datasources import utils
|
||||
from vitrage import messaging
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class DriverExec(object):
|
||||
|
||||
def __init__(self, conf, process_output_func, persist):
|
||||
self.conf = conf
|
||||
def __init__(self, process_output_func, persist):
|
||||
self.process_output_func = process_output_func
|
||||
self.persist = persist
|
||||
|
||||
def snapshot_get_all(self, action=DatasourceAction.INIT_SNAPSHOT):
|
||||
driver_names = self.conf.datasources.types
|
||||
driver_names = CONF.datasources.types
|
||||
LOG.info('get_all starting for %s', driver_names)
|
||||
t1 = time.time()
|
||||
events_count = 0
|
||||
@ -46,7 +47,7 @@ class DriverExec(object):
|
||||
def get_all(self, driver_name, action):
|
||||
try:
|
||||
LOCK_BY_DRIVER.acquire(driver_name)
|
||||
driver = utils.get_drivers_by_name(self.conf, [driver_name])[0]
|
||||
driver = utils.get_drivers_by_name([driver_name])[0]
|
||||
LOG.info("run driver get_all: %s", driver_name)
|
||||
events = driver.get_all(action)
|
||||
count = self.process_output_func(events)
|
||||
@ -65,7 +66,7 @@ class DriverExec(object):
|
||||
driver_name)
|
||||
return 0
|
||||
try:
|
||||
driver = utils.get_drivers_by_name(self.conf, [driver_name])[0]
|
||||
driver = utils.get_drivers_by_name([driver_name])[0]
|
||||
LOG.info("run driver get_changes: %s", driver_name)
|
||||
events = driver.get_changes(DatasourceAction.UPDATE)
|
||||
count = self.process_output_func(events)
|
||||
@ -81,23 +82,22 @@ class DriverExec(object):
|
||||
|
||||
class DriversNotificationEndpoint(object):
|
||||
|
||||
def __init__(self, conf, processor_func):
|
||||
self._conf = conf
|
||||
def __init__(self, processor_func):
|
||||
self._processor_func = processor_func
|
||||
self._enrich_event_methods = defaultdict(list)
|
||||
|
||||
def init(self):
|
||||
driver_names = utils.get_push_drivers_names(self._conf)
|
||||
push_drivers = utils.get_drivers_by_name(self._conf, driver_names)
|
||||
driver_names = utils.get_push_drivers_names()
|
||||
push_drivers = utils.get_drivers_by_name(driver_names)
|
||||
for driver in push_drivers:
|
||||
for event in driver.get_event_types():
|
||||
self._enrich_event_methods[event].append(driver.enrich_event)
|
||||
return self
|
||||
|
||||
def get_listener(self):
|
||||
topics = self._conf.datasources.notification_topics
|
||||
exchange = self._conf.datasources.notification_exchange
|
||||
transport = messaging.get_transport(self._conf)
|
||||
topics = CONF.datasources.notification_topics
|
||||
exchange = CONF.datasources.notification_exchange
|
||||
transport = messaging.get_transport()
|
||||
targets = [oslo_messaging.Target(exchange=exchange, topic=topic)
|
||||
for topic in topics]
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
import threading
|
||||
import time
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
import oslo_messaging
|
||||
|
||||
@ -33,24 +34,23 @@ from vitrage.graph.driver.networkx_graph import NXGraph
|
||||
from vitrage import messaging
|
||||
from vitrage import storage
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class VitrageGraphInit(object):
|
||||
def __init__(self, conf, workers):
|
||||
self.conf = conf
|
||||
self.graph = get_graph_driver(conf)('Entity Graph')
|
||||
self.db = db_connection = storage.get_connection_from_config(conf)
|
||||
def __init__(self, workers):
|
||||
self.graph = get_graph_driver()('Entity Graph')
|
||||
self.db = db_connection = storage.get_connection_from_config()
|
||||
self.workers = workers
|
||||
self.events_coordination = EventsCoordination(conf, self.process_event)
|
||||
self.persist = GraphPersistency(conf, db_connection, self.graph)
|
||||
self.events_coordination = EventsCoordination(self.process_event)
|
||||
self.persist = GraphPersistency(db_connection, self.graph)
|
||||
self.driver_exec = driver_exec.DriverExec(
|
||||
self.conf,
|
||||
self.events_coordination.handle_multiple_low_priority,
|
||||
self.persist)
|
||||
self.scheduler = Scheduler(conf, self.graph, self.driver_exec,
|
||||
self.scheduler = Scheduler(self.graph, self.driver_exec,
|
||||
self.persist)
|
||||
self.processor = Processor(conf, self.graph)
|
||||
self.processor = Processor(self.graph)
|
||||
|
||||
def run(self):
|
||||
LOG.info('Init Started')
|
||||
@ -114,7 +114,7 @@ class VitrageGraphInit(object):
|
||||
|
||||
def _add_graph_subscriptions(self):
|
||||
self.graph.subscribe(self.workers.submit_graph_update)
|
||||
vitrage_notifier = GraphNotifier(self.conf)
|
||||
vitrage_notifier = GraphNotifier()
|
||||
if vitrage_notifier.enabled:
|
||||
self.graph.subscribe(vitrage_notifier.notify_when_applicable)
|
||||
LOG.info('Subscribed vitrage notifier to graph changes')
|
||||
@ -122,14 +122,13 @@ class VitrageGraphInit(object):
|
||||
finalization=True)
|
||||
|
||||
def subscribe_presist_notifier(self):
|
||||
self.graph.subscribe(PersistNotifier(self.conf).notify_when_applicable)
|
||||
self.graph.subscribe(PersistNotifier().notify_when_applicable)
|
||||
|
||||
PRIORITY_DELAY = 0.05
|
||||
|
||||
|
||||
class EventsCoordination(object):
|
||||
def __init__(self, conf, do_work_func):
|
||||
self._conf = conf
|
||||
def __init__(self, do_work_func):
|
||||
self._lock = threading.Lock()
|
||||
self._high_event_finish_time = 0
|
||||
|
||||
@ -146,7 +145,6 @@ class EventsCoordination(object):
|
||||
|
||||
def start(self):
|
||||
self._low_pri_listener = driver_exec.DriversNotificationEndpoint(
|
||||
self._conf,
|
||||
self.handle_multiple_low_priority).init().get_listener()
|
||||
self._high_pri_listener = self._init_listener(
|
||||
EVALUATOR_TOPIC,
|
||||
@ -191,7 +189,7 @@ class EventsCoordination(object):
|
||||
if not topic:
|
||||
return
|
||||
return messaging.get_notification_listener(
|
||||
transport=messaging.get_transport(self._conf),
|
||||
transport=messaging.get_transport(),
|
||||
targets=[oslo_messaging.Target(topic=topic)],
|
||||
endpoints=[PushNotificationsEndpoint(callback)])
|
||||
|
||||
|
@ -24,8 +24,7 @@ LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class GraphPersistency(object):
|
||||
def __init__(self, conf, db, graph):
|
||||
self.conf = conf
|
||||
def __init__(self, db, graph):
|
||||
self.db = db
|
||||
self.graph = graph
|
||||
self.events_buffer = []
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
import os
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
from vitrage.common.constants import EntityCategory
|
||||
@ -23,6 +24,7 @@ from vitrage.entity_graph.mappings.resource_handler import \
|
||||
ResourceHandler
|
||||
from vitrage.utils import file as file_utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
@ -34,8 +36,7 @@ class DatasourceInfoMapper(object):
|
||||
PRIORITY_VALUES = 'priority_values'
|
||||
UNDEFINED_DATASOURCE = 'undefined datasource'
|
||||
|
||||
def __init__(self, conf):
|
||||
self.conf = conf
|
||||
def __init__(self):
|
||||
self.category_normalizer = self._init_category_normalizer()
|
||||
self.datasources_value_confs = self._load_value_configurations()
|
||||
|
||||
@ -62,7 +63,7 @@ class DatasourceInfoMapper(object):
|
||||
graph_vertex[VProps.VITRAGE_CATEGORY]
|
||||
|
||||
if vitrage_type in self.datasources_value_confs or \
|
||||
vitrage_type not in self.conf.datasources.types:
|
||||
vitrage_type not in CONF.datasources.types:
|
||||
value_properties = \
|
||||
self.category_normalizer[vitrage_category].value_properties()
|
||||
vitrage_operational_value, vitrage_aggregated_value, value_priority = \
|
||||
@ -115,11 +116,11 @@ class DatasourceInfoMapper(object):
|
||||
erroneous_datasources_conf = []
|
||||
|
||||
files = file_utils.list_files(
|
||||
self.conf.entity_graph.datasources_values_dir, '.yaml')
|
||||
CONF.entity_graph.datasources_values_dir, '.yaml')
|
||||
|
||||
for file_name in files:
|
||||
try:
|
||||
full_path = self.conf.entity_graph.datasources_values_dir \
|
||||
full_path = CONF.entity_graph.datasources_values_dir \
|
||||
+ '/' + file_name
|
||||
operational_values, priority_values = \
|
||||
self._retrieve_values_and_priorities_from_file(full_path)
|
||||
@ -227,7 +228,7 @@ class DatasourceInfoMapper(object):
|
||||
ok_datasources,
|
||||
error_datasources):
|
||||
|
||||
datasource_types = self.conf.datasources.types
|
||||
datasource_types = CONF.datasources.types
|
||||
datasources_with_state_conf = ok_datasources + error_datasources
|
||||
|
||||
for datasource_type in datasource_types:
|
||||
|
@ -11,6 +11,7 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
import oslo_messaging
|
||||
|
||||
@ -24,19 +25,21 @@ from vitrage.graph.driver.networkx_graph import edge_copy
|
||||
from vitrage.graph.driver.networkx_graph import vertex_copy
|
||||
from vitrage.messaging import get_transport
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class GraphNotifier(object):
|
||||
"""Allows writing to message bus"""
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
self.oslo_notifier = None
|
||||
topics = self._get_topics(conf)
|
||||
topics = self._get_topics()
|
||||
if not topics:
|
||||
LOG.info('Graph Notifier is disabled')
|
||||
return
|
||||
self.oslo_notifier = oslo_messaging.Notifier(
|
||||
get_transport(conf),
|
||||
get_transport(),
|
||||
driver='messagingv2',
|
||||
publisher_id='vitrage.graph',
|
||||
topics=topics)
|
||||
@ -45,12 +48,12 @@ class GraphNotifier(object):
|
||||
def enabled(self):
|
||||
return self.oslo_notifier is not None
|
||||
|
||||
def _get_topics(self, conf):
|
||||
def _get_topics(self):
|
||||
topics = []
|
||||
|
||||
try:
|
||||
notifier_topic = conf.entity_graph.notifier_topic
|
||||
notifier_plugins = conf.notifiers
|
||||
notifier_topic = CONF.entity_graph.notifier_topic
|
||||
notifier_plugins = CONF.notifiers
|
||||
if notifier_topic and notifier_plugins:
|
||||
topics.append(notifier_topic)
|
||||
except Exception:
|
||||
@ -58,8 +61,8 @@ class GraphNotifier(object):
|
||||
|
||||
try:
|
||||
machine_learning_topic = \
|
||||
conf.machine_learning.machine_learning_topic
|
||||
machine_learning_plugins = conf.machine_learning.plugins
|
||||
CONF.machine_learning.machine_learning_topic
|
||||
machine_learning_plugins = CONF.machine_learning.plugins
|
||||
if machine_learning_topic and machine_learning_plugins:
|
||||
topics.append(machine_learning_topic)
|
||||
except Exception:
|
||||
@ -117,11 +120,11 @@ class GraphNotifier(object):
|
||||
|
||||
class PersistNotifier(object):
|
||||
"""Allows writing to message bus"""
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
self.oslo_notifier = None
|
||||
topics = [conf.persistency.persistor_topic]
|
||||
topics = [CONF.persistency.persistor_topic]
|
||||
self.oslo_notifier = oslo_messaging.Notifier(
|
||||
get_transport(conf),
|
||||
get_transport(),
|
||||
driver='messagingv2',
|
||||
publisher_id='vitrage.graph',
|
||||
topics=topics)
|
||||
|
@ -31,11 +31,10 @@ LOG = log.getLogger(__name__)
|
||||
|
||||
class Processor(processor.ProcessorBase):
|
||||
|
||||
def __init__(self, conf, e_graph=None):
|
||||
def __init__(self, e_graph=None):
|
||||
super(Processor, self).__init__()
|
||||
self.conf = conf
|
||||
self.transformer_manager = TransformerManager(self.conf)
|
||||
self.info_mapper = DatasourceInfoMapper(self.conf)
|
||||
self.transformer_manager = TransformerManager()
|
||||
self.info_mapper = DatasourceInfoMapper()
|
||||
self._initialize_events_actions()
|
||||
self.entity_graph = e_graph
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import importutils
|
||||
|
||||
@ -26,29 +27,30 @@ from vitrage.evaluator.actions.evaluator_event_transformer \
|
||||
import VITRAGE_DATASOURCE
|
||||
from vitrage.utils import opt_exists
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
ENTITIES = 'entities'
|
||||
|
||||
|
||||
class TransformerManager(object):
|
||||
|
||||
def __init__(self, conf):
|
||||
self.transformers = self.register_transformer_classes(conf)
|
||||
def __init__(self):
|
||||
self.transformers = self.register_transformer_classes()
|
||||
|
||||
@staticmethod
|
||||
def register_transformer_classes(conf):
|
||||
def register_transformer_classes():
|
||||
|
||||
transformers = {}
|
||||
for datasource_type in conf.datasources.types:
|
||||
for datasource_type in CONF.datasources.types:
|
||||
try:
|
||||
transformers[datasource_type] = importutils.import_object(
|
||||
conf[datasource_type].transformer,
|
||||
transformers, conf)
|
||||
if opt_exists(conf[datasource_type], ENTITIES):
|
||||
for entity in conf[datasource_type].entities:
|
||||
CONF[datasource_type].transformer,
|
||||
transformers)
|
||||
if opt_exists(CONF[datasource_type], ENTITIES):
|
||||
for entity in CONF[datasource_type].entities:
|
||||
transformers[entity] = importutils.import_object(
|
||||
conf[datasource_type].transformer,
|
||||
transformers, conf)
|
||||
CONF[datasource_type].transformer,
|
||||
transformers)
|
||||
|
||||
except Exception:
|
||||
LOG.exception('Failed to register transformer %s.',
|
||||
@ -56,11 +58,11 @@ class TransformerManager(object):
|
||||
|
||||
transformers[VITRAGE_DATASOURCE] = importutils.import_object(
|
||||
"%s.%s" % (EvaluatorEventTransformer.__module__,
|
||||
EvaluatorEventTransformer.__name__), transformers, conf)
|
||||
EvaluatorEventTransformer.__name__), transformers)
|
||||
|
||||
transformers[CONSISTENCY_DATASOURCE] = importutils.import_object(
|
||||
"%s.%s" % (ConsistencyTransformer.__module__,
|
||||
ConsistencyTransformer.__name__), transformers, conf)
|
||||
ConsistencyTransformer.__name__), transformers)
|
||||
|
||||
return transformers
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from futurist import periodics
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from vitrage.datasources import utils
|
||||
|
||||
@ -23,22 +24,22 @@ from vitrage.common.utils import spawn
|
||||
from vitrage.entity_graph.consistency.consistency_enforcer import\
|
||||
ConsistencyEnforcer
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class Scheduler(object):
|
||||
|
||||
def __init__(self, conf, graph, driver_exec, persist):
|
||||
def __init__(self, graph, driver_exec, persist):
|
||||
super(Scheduler, self).__init__()
|
||||
self.conf = conf
|
||||
self.graph = graph
|
||||
self.driver_exec = driver_exec
|
||||
self.persist = persist
|
||||
self.consistency = ConsistencyEnforcer(conf, graph)
|
||||
self.consistency = ConsistencyEnforcer(graph)
|
||||
self.periodic = None
|
||||
|
||||
def start_periodic_tasks(self, immediate_get_all):
|
||||
thread_num = len(utils.get_pull_drivers_names(self.conf))
|
||||
thread_num = len(utils.get_pull_drivers_names())
|
||||
thread_num += 2 # for consistency and get_all
|
||||
self.periodic = periodics.PeriodicWorker.create(
|
||||
[], executor_factory=lambda: ThreadPoolExecutor(
|
||||
@ -49,7 +50,7 @@ class Scheduler(object):
|
||||
spawn(self.periodic.start)
|
||||
|
||||
def _add_consistency_timer(self):
|
||||
spacing = self.conf.datasources.snapshots_interval
|
||||
spacing = CONF.datasources.snapshots_interval
|
||||
|
||||
@periodics.periodic(spacing=spacing)
|
||||
def consistency_periodic():
|
||||
@ -62,7 +63,7 @@ class Scheduler(object):
|
||||
LOG.info("added consistency_periodic (spacing=%s)", spacing)
|
||||
|
||||
def _add_datasource_timers(self, run_immediately):
|
||||
spacing = self.conf.datasources.snapshots_interval
|
||||
spacing = CONF.datasources.snapshots_interval
|
||||
|
||||
@periodics.periodic(spacing=spacing, run_immediately=run_immediately)
|
||||
def get_all_periodic():
|
||||
@ -71,9 +72,9 @@ class Scheduler(object):
|
||||
self.periodic.add(get_all_periodic)
|
||||
LOG.info("added get_all_periodic (spacing=%s)", spacing)
|
||||
|
||||
driver_names = utils.get_pull_drivers_names(self.conf)
|
||||
driver_names = utils.get_pull_drivers_names()
|
||||
for d_name in driver_names:
|
||||
spacing = self.conf[d_name].changes_interval
|
||||
spacing = CONF[d_name].changes_interval
|
||||
|
||||
@periodics.periodic(spacing=spacing)
|
||||
def get_changes_periodic(driver_name=d_name):
|
||||
|
@ -18,6 +18,7 @@ import cotyledon
|
||||
import multiprocessing
|
||||
import multiprocessing.queues
|
||||
import os
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
import oslo_messaging
|
||||
from oslo_utils import uuidutils
|
||||
@ -45,6 +46,7 @@ from vitrage import messaging
|
||||
from vitrage import rpc as vitrage_rpc
|
||||
from vitrage import storage
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = None
|
||||
|
||||
# Supported message types
|
||||
@ -67,9 +69,8 @@ class GraphWorkersManager(cotyledon.ServiceManager):
|
||||
- the queues used to communicate with these workers
|
||||
- methods interface to submit tasks to workers
|
||||
"""
|
||||
def __init__(self, conf):
|
||||
def __init__(self):
|
||||
super(GraphWorkersManager, self).__init__()
|
||||
self._conf = conf
|
||||
self._db = None
|
||||
self._evaluator_queues = []
|
||||
self._template_queues = []
|
||||
@ -93,10 +94,10 @@ class GraphWorkersManager(cotyledon.ServiceManager):
|
||||
"""
|
||||
if self._evaluator_queues:
|
||||
raise VitrageError('add_evaluator_workers called more than once')
|
||||
workers = self._conf.evaluator.workers
|
||||
workers = CONF.evaluator.workers
|
||||
queues = [multiprocessing.JoinableQueue() for i in range(workers)]
|
||||
self.add(EvaluatorWorker,
|
||||
args=(self._conf, queues, workers),
|
||||
args=(queues, workers),
|
||||
workers=workers)
|
||||
self._evaluator_queues = queues
|
||||
self._all_queues.extend(queues)
|
||||
@ -111,9 +112,9 @@ class GraphWorkersManager(cotyledon.ServiceManager):
|
||||
"""
|
||||
if self._api_queues:
|
||||
raise VitrageError('add_api_workers called more than once')
|
||||
workers = self._conf.api.workers
|
||||
workers = CONF.api.workers
|
||||
queues = [multiprocessing.Queue() for i in range(workers)]
|
||||
self.add(ApiWorker, args=(self._conf, queues), workers=workers)
|
||||
self.add(ApiWorker, args=(queues,), workers=workers)
|
||||
self._api_queues = queues
|
||||
self._all_queues.extend(queues)
|
||||
|
||||
@ -177,7 +178,7 @@ class GraphWorkersManager(cotyledon.ServiceManager):
|
||||
template_action = event.get(TEMPLATE_ACTION)
|
||||
|
||||
if not self._db:
|
||||
self._db = storage.get_connection_from_config(self._conf)
|
||||
self._db = storage.get_connection_from_config()
|
||||
|
||||
if template_action == ADD:
|
||||
templates = self._db.templates.query(status=TStatus.LOADING)
|
||||
@ -219,10 +220,8 @@ class GraphWorkersManager(cotyledon.ServiceManager):
|
||||
class GraphCloneWorkerBase(coord.Service):
|
||||
def __init__(self,
|
||||
worker_id,
|
||||
conf,
|
||||
task_queues):
|
||||
super(GraphCloneWorkerBase, self).__init__(worker_id, conf)
|
||||
self._conf = conf
|
||||
super(GraphCloneWorkerBase, self).__init__(worker_id)
|
||||
self._task_queue = task_queues[worker_id]
|
||||
self._entity_graph = NXGraph()
|
||||
|
||||
@ -285,7 +284,7 @@ class GraphCloneWorkerBase(coord.Service):
|
||||
self._entity_graph.remove_edge(before)
|
||||
|
||||
def _read_db_graph(self):
|
||||
db = storage.get_connection_from_config(self._conf)
|
||||
db = storage.get_connection_from_config()
|
||||
graph_snapshot = db.graph_snapshots.query()
|
||||
NXGraph.read_gpickle(graph_snapshot.graph_snapshot, self._entity_graph)
|
||||
GraphPersistency.do_replay_events(db, self._entity_graph,
|
||||
@ -296,25 +295,22 @@ class GraphCloneWorkerBase(coord.Service):
|
||||
class EvaluatorWorker(GraphCloneWorkerBase):
|
||||
def __init__(self,
|
||||
worker_id,
|
||||
conf,
|
||||
task_queues,
|
||||
workers_num):
|
||||
super(EvaluatorWorker, self).__init__(
|
||||
worker_id, conf, task_queues)
|
||||
worker_id, task_queues)
|
||||
self._workers_num = workers_num
|
||||
self._evaluator = None
|
||||
|
||||
name = 'EvaluatorWorker'
|
||||
|
||||
def _init_instance(self):
|
||||
scenario_repo = ScenarioRepository(self._conf, self.worker_id,
|
||||
scenario_repo = ScenarioRepository(self.worker_id,
|
||||
self._workers_num)
|
||||
actions_callback = messaging.VitrageNotifier(
|
||||
conf=self._conf,
|
||||
publisher_id='vitrage_evaluator',
|
||||
topics=[EVALUATOR_TOPIC]).notify
|
||||
self._evaluator = ScenarioEvaluator(
|
||||
self._conf,
|
||||
self._entity_graph,
|
||||
scenario_repo,
|
||||
actions_callback,
|
||||
@ -338,7 +334,7 @@ class EvaluatorWorker(GraphCloneWorkerBase):
|
||||
|
||||
def _reload_templates(self):
|
||||
LOG.info("reloading evaluator scenarios")
|
||||
scenario_repo = ScenarioRepository(self._conf, self.worker_id,
|
||||
scenario_repo = ScenarioRepository(self.worker_id,
|
||||
self._workers_num)
|
||||
self._evaluator.scenario_repo = scenario_repo
|
||||
self._evaluator.scenario_repo.log_enabled_scenarios()
|
||||
@ -347,7 +343,7 @@ class EvaluatorWorker(GraphCloneWorkerBase):
|
||||
# Here, we create a temporary ScenarioRepo to execute the needed
|
||||
# templates. Once _reload_templates is called, it will create a
|
||||
# non temporary ScenarioRepo, to replace this one
|
||||
scenario_repo = ScenarioRepository(self._conf)
|
||||
scenario_repo = ScenarioRepository()
|
||||
for s in scenario_repo._all_scenarios:
|
||||
s.enabled = False
|
||||
for template_name in template_names:
|
||||
@ -363,24 +359,23 @@ class ApiWorker(GraphCloneWorkerBase):
|
||||
name = 'ApiWorker'
|
||||
|
||||
def _init_instance(self):
|
||||
conf = self._conf
|
||||
notifier = messaging.VitrageNotifier(conf, "vitrage.api",
|
||||
notifier = messaging.VitrageNotifier("vitrage.api",
|
||||
[EVALUATOR_TOPIC])
|
||||
db = storage.get_connection_from_config(conf)
|
||||
transport = messaging.get_rpc_transport(conf)
|
||||
target = oslo_messaging.Target(topic=conf.rpc_topic,
|
||||
db = storage.get_connection_from_config()
|
||||
transport = messaging.get_rpc_transport()
|
||||
target = oslo_messaging.Target(topic=CONF.rpc_topic,
|
||||
server=uuidutils.generate_uuid())
|
||||
self.api_lock = threading.RLock()
|
||||
|
||||
endpoints = [
|
||||
TopologyApis(self._entity_graph, conf, self.api_lock),
|
||||
AlarmApis(self._entity_graph, conf, self.api_lock, db),
|
||||
RcaApis(self._entity_graph, conf, self.api_lock, db),
|
||||
ResourceApis(self._entity_graph, conf, self.api_lock),
|
||||
TopologyApis(self._entity_graph, self.api_lock),
|
||||
AlarmApis(self._entity_graph, self.api_lock, db),
|
||||
RcaApis(self._entity_graph, self.api_lock, db),
|
||||
ResourceApis(self._entity_graph, self.api_lock),
|
||||
TemplateApis(notifier, db),
|
||||
EventApis(conf),
|
||||
WebhookApis(conf, db),
|
||||
OperationalApis(conf, self._entity_graph),
|
||||
EventApis(),
|
||||
WebhookApis(db),
|
||||
OperationalApis(self._entity_graph),
|
||||
]
|
||||
|
||||
server = vitrage_rpc.get_server(target, endpoints, transport)
|
||||
|
@ -51,10 +51,10 @@ SOURCE = 'source'
|
||||
|
||||
class ActionExecutor(object):
|
||||
|
||||
def __init__(self, conf, actions_callback):
|
||||
def __init__(self, actions_callback):
|
||||
|
||||
self.actions_callback = actions_callback
|
||||
self.notifier = EvaluatorNotifier(conf)
|
||||
self.notifier = EvaluatorNotifier()
|
||||
self.action_recipes = ActionExecutor._register_action_recipes()
|
||||
|
||||
self.action_step_defs = {
|
||||
|
@ -42,8 +42,8 @@ VITRAGE_DATASOURCE = 'vitrage'
|
||||
|
||||
class EvaluatorEventTransformer(transformer_base.TransformerBase):
|
||||
|
||||
def __init__(self, transformers, conf):
|
||||
super(EvaluatorEventTransformer, self).__init__(transformers, conf)
|
||||
def __init__(self, transformers):
|
||||
super(EvaluatorEventTransformer, self).__init__(transformers)
|
||||
self.actions = self._init_actions()
|
||||
|
||||
def _create_snapshot_entity_vertex(self, entity_event):
|
||||
|
@ -11,6 +11,8 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
import oslo_messaging
|
||||
|
||||
@ -18,15 +20,16 @@ from vitrage.common.constants import NotifierEventTypes
|
||||
from vitrage.messaging import get_transport
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class EvaluatorNotifier(object):
|
||||
"""Allows writing to message bus"""
|
||||
def __init__(self, conf):
|
||||
def __init__(self, ):
|
||||
self.oslo_notifiers = {}
|
||||
try:
|
||||
notifier_plugins = conf.notifiers
|
||||
notifier_plugins = CONF.notifiers
|
||||
|
||||
LOG.debug('notifier_plugins: %s', notifier_plugins)
|
||||
|
||||
@ -35,13 +38,13 @@ class EvaluatorNotifier(object):
|
||||
return
|
||||
|
||||
topic_prefix = \
|
||||
conf.evaluator_actions.evaluator_notification_topic_prefix
|
||||
CONF.evaluator_actions.evaluator_notification_topic_prefix
|
||||
|
||||
for notifier in notifier_plugins:
|
||||
LOG.debug('Adding evaluator notifier %s', notifier)
|
||||
|
||||
self.oslo_notifiers[notifier] = oslo_messaging.Notifier(
|
||||
get_transport(conf),
|
||||
get_transport(),
|
||||
driver='messagingv2',
|
||||
publisher_id='vitrage.evaluator',
|
||||
topics=[topic_prefix + '.' + notifier])
|
||||
|
@ -18,6 +18,7 @@ import copy
|
||||
import re
|
||||
import time
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
from vitrage.common.constants import EdgeProperties as EProps
|
||||
@ -42,6 +43,7 @@ from vitrage import storage
|
||||
from vitrage.storage.sqlalchemy import models
|
||||
from vitrage.utils.datetime import utcnow
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
# Entry containing action info.
|
||||
@ -60,16 +62,14 @@ SOURCE = 'source'
|
||||
class ScenarioEvaluator(object):
|
||||
|
||||
def __init__(self,
|
||||
conf,
|
||||
e_graph,
|
||||
scenario_repo,
|
||||
actions_callback,
|
||||
enabled=False):
|
||||
self._conf = conf
|
||||
self._entity_graph = e_graph
|
||||
self._db = storage.get_connection_from_config(self._conf)
|
||||
self._db = storage.get_connection_from_config()
|
||||
self._scenario_repo = scenario_repo
|
||||
self._action_executor = ActionExecutor(self._conf, actions_callback)
|
||||
self._action_executor = ActionExecutor(actions_callback)
|
||||
self._entity_graph.subscribe(self.process_event)
|
||||
self.enabled = enabled
|
||||
self.connected_component_cache = defaultdict(dict)
|
||||
@ -314,7 +314,7 @@ class ScenarioEvaluator(object):
|
||||
if not actions:
|
||||
return []
|
||||
|
||||
active_actions = ActiveActionsTracker(self._conf, self._db, actions)
|
||||
active_actions = ActiveActionsTracker(self._db, actions)
|
||||
for action_info in actions:
|
||||
if action_info.mode == ActionMode.DO:
|
||||
active_actions.calc_do_action(action_info)
|
||||
@ -483,13 +483,13 @@ class ActiveActionsTracker(object):
|
||||
"""
|
||||
action_tools = None
|
||||
|
||||
def __init__(self, conf, db, actions):
|
||||
def __init__(self, db, actions):
|
||||
self.db = db
|
||||
self.data = defaultdict(set)
|
||||
self.actions_to_create = {}
|
||||
self.actions_to_remove = set()
|
||||
self.actions_to_perform = [] # use a list to keep the insertion order
|
||||
self._init_action_tools(conf)
|
||||
self._init_action_tools()
|
||||
|
||||
# Query DB for all actions with same properties
|
||||
actions_keys = set([self._get_key(action) for action in actions])
|
||||
@ -499,10 +499,10 @@ class ActiveActionsTracker(object):
|
||||
db_row.extra_info, db_row.action_type)].add(db_row)
|
||||
|
||||
@classmethod
|
||||
def _init_action_tools(cls, conf):
|
||||
def _init_action_tools(cls):
|
||||
if cls.action_tools:
|
||||
return
|
||||
info_mapper = DatasourceInfoMapper(conf)
|
||||
info_mapper = DatasourceInfoMapper()
|
||||
alarms_score = info_mapper.get_datasource_priorities('vitrage')
|
||||
all_scores = info_mapper.get_datasource_priorities()
|
||||
cls.action_tools = {
|
||||
|
@ -35,7 +35,7 @@ DEF_TEMPLATES_DIR_OPT = 'def_templates_dir'
|
||||
|
||||
|
||||
class ScenarioRepository(object):
|
||||
def __init__(self, conf, worker_index=None, workers_num=None):
|
||||
def __init__(self, worker_index=None, workers_num=None):
|
||||
"""Create an instance of ScenarioRepository
|
||||
|
||||
:param conf:
|
||||
@ -45,7 +45,7 @@ class ScenarioRepository(object):
|
||||
self._templates = {}
|
||||
self._def_templates = {}
|
||||
self._all_scenarios = []
|
||||
self._db = storage.get_connection_from_config(conf)
|
||||
self._db = storage.get_connection_from_config()
|
||||
self.entity_equivalences = EquivalenceRepository().load(self._db)
|
||||
self.relationship_scenarios = defaultdict(list)
|
||||
self.entity_scenarios = defaultdict(list)
|
||||
|
@ -24,22 +24,23 @@ from keystoneclient.v3 import client as ks_client_v3
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
CFG_GROUP = "service_credentials"
|
||||
|
||||
|
||||
def get_session(conf):
|
||||
def get_session():
|
||||
"""Get a vitrage service credentials auth session."""
|
||||
auth_plugin = ka_loading.load_auth_from_conf_options(conf, CFG_GROUP)
|
||||
auth_plugin = ka_loading.load_auth_from_conf_options(CONF, CFG_GROUP)
|
||||
return ka_loading.load_session_from_conf_options(
|
||||
conf, CFG_GROUP, auth=auth_plugin
|
||||
CONF, CFG_GROUP, auth=auth_plugin
|
||||
)
|
||||
|
||||
|
||||
def get_client(conf):
|
||||
def get_client():
|
||||
"""Return a client for keystone v3 endpoint."""
|
||||
sess = get_session(conf)
|
||||
sess = get_session()
|
||||
return ks_client_v3.Client(session=sess)
|
||||
|
||||
|
||||
@ -57,10 +58,10 @@ def get_client_on_behalf_user(auth_plugin):
|
||||
return ks_client_v3.Client(session=sess)
|
||||
|
||||
|
||||
def create_trust_id(conf, trustor_user_id, trustor_project_id, roles,
|
||||
def create_trust_id(trustor_user_id, trustor_project_id, roles,
|
||||
auth_plugin):
|
||||
"""Create a new trust using the vitrage service user."""
|
||||
admin_client = get_client(conf)
|
||||
admin_client = get_client()
|
||||
trustee_user_id = admin_client.session.get_user_id()
|
||||
|
||||
client = get_client_on_behalf_user(auth_plugin)
|
||||
@ -98,10 +99,10 @@ OPTS = [
|
||||
]
|
||||
|
||||
|
||||
def register_keystoneauth_opts(conf):
|
||||
ka_loading.register_auth_conf_options(conf, CFG_GROUP)
|
||||
def register_keystoneauth_opts():
|
||||
ka_loading.register_auth_conf_options(CONF, CFG_GROUP)
|
||||
ka_loading.register_session_conf_options(
|
||||
conf, CFG_GROUP,
|
||||
CONF, CFG_GROUP,
|
||||
deprecated_opts={'cacert': [
|
||||
cfg.DeprecatedOpt('os-cacert', group=CFG_GROUP),
|
||||
cfg.DeprecatedOpt('os-cacert', group="DEFAULT")]
|
||||
|
@ -19,9 +19,6 @@ import six
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class MachineLearningBase(object):
|
||||
|
||||
def __init__(self, conf):
|
||||
self.conf = conf
|
||||
|
||||
@abc.abstractmethod
|
||||
def process_event(self, data, event_type):
|
||||
pass
|
||||
|
@ -14,6 +14,8 @@
|
||||
|
||||
from collections import namedtuple
|
||||
from datetime import datetime
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
from vitrage.common.constants import NotifierEventTypes
|
||||
@ -28,6 +30,8 @@ from vitrage.machine_learning.plugins.jaccard_correlation.\
|
||||
from vitrage.machine_learning.plugins.jaccard_correlation.correlation_manager\
|
||||
import CorrelationManager as CM
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
AlarmID = namedtuple('AlarmID', [VProps.VITRAGE_RESOURCE_ID,
|
||||
@ -41,12 +45,12 @@ class AlarmDataProcessor(MachineLearningBase):
|
||||
def get_plugin_name():
|
||||
return 'jaccard_correlation'
|
||||
|
||||
def __init__(self, conf):
|
||||
super(AlarmDataProcessor, self).__init__(conf)
|
||||
def __init__(self):
|
||||
super(AlarmDataProcessor, self).__init__()
|
||||
self.data_manager = ADAcummulator(APersistor.load_data())
|
||||
self.correlation_manager = CM(conf)
|
||||
self.correlation_manager = CM()
|
||||
self.num_of_events_to_flush = \
|
||||
conf.jaccard_correlation.num_of_events_to_flush
|
||||
CONF.jaccard_correlation.num_of_events_to_flush
|
||||
self.event_counter = 0
|
||||
|
||||
def process_event(self, data, event_type):
|
||||
|
@ -15,6 +15,7 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
from vitrage.machine_learning.plugins.jaccard_correlation.\
|
||||
@ -23,17 +24,18 @@ from vitrage.machine_learning.plugins.jaccard_correlation.\
|
||||
correlation_collection import CorrelationPriorities as CPriorities
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class CorrelationManager(object):
|
||||
|
||||
def __init__(self, conf):
|
||||
self.high_corr_score = conf.jaccard_correlation.high_corr_score
|
||||
self.med_corr_score = conf.jaccard_correlation.med_corr_score
|
||||
def __init__(self):
|
||||
self.high_corr_score = CONF.jaccard_correlation.high_corr_score
|
||||
self.med_corr_score = CONF.jaccard_correlation.med_corr_score
|
||||
self.correlation_threshold = \
|
||||
conf.jaccard_correlation.correlation_threshold
|
||||
self.output_folder = conf.jaccard_correlation.output_folder
|
||||
CONF.jaccard_correlation.correlation_threshold
|
||||
self.output_folder = CONF.jaccard_correlation.output_folder
|
||||
self.last_written_file = ""
|
||||
self.correlation_table = CCollection(self.high_corr_score,
|
||||
self.med_corr_score)
|
||||
|
@ -12,7 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
import oslo_messaging as oslo_m
|
||||
from oslo_utils import importutils
|
||||
@ -21,18 +21,18 @@ from vitrage.coordination import service as coord
|
||||
from vitrage import messaging
|
||||
from vitrage.opts import register_opts
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class MachineLearningService(coord.Service):
|
||||
|
||||
def __init__(self, worker_id, conf):
|
||||
super(MachineLearningService, self).__init__(worker_id, conf)
|
||||
self.conf = conf
|
||||
self.machine_learning_plugins = self.get_machine_learning_plugins(conf)
|
||||
transport = messaging.get_transport(conf)
|
||||
def __init__(self, worker_id):
|
||||
super(MachineLearningService, self).__init__(worker_id)
|
||||
self.machine_learning_plugins = self.get_machine_learning_plugins()
|
||||
transport = messaging.get_transport()
|
||||
target = \
|
||||
oslo_m.Target(topic=conf.machine_learning.machine_learning_topic)
|
||||
oslo_m.Target(topic=CONF.machine_learning.machine_learning_topic)
|
||||
self.listener = messaging.get_notification_listener(
|
||||
transport, [target],
|
||||
[VitrageEventEndpoint(self.machine_learning_plugins)])
|
||||
@ -55,21 +55,21 @@ class MachineLearningService(coord.Service):
|
||||
LOG.info("Vitrage Machine Learning Service - Stopped!")
|
||||
|
||||
@staticmethod
|
||||
def get_machine_learning_plugins(conf):
|
||||
def get_machine_learning_plugins():
|
||||
machine_learning_plugins = []
|
||||
machine_learning_plugins_names = \
|
||||
conf.machine_learning.plugins
|
||||
CONF.machine_learning.plugins
|
||||
if not machine_learning_plugins_names:
|
||||
LOG.info('There are no Machine Learning plugins in configuration')
|
||||
return []
|
||||
for machine_learning_plugin_name in machine_learning_plugins_names:
|
||||
register_opts(conf, machine_learning_plugin_name,
|
||||
conf.machine_learning.plugins_path)
|
||||
register_opts(machine_learning_plugin_name,
|
||||
CONF.machine_learning.plugins_path)
|
||||
LOG.info('Machine Learning plugin %s started',
|
||||
machine_learning_plugin_name)
|
||||
machine_learning_plugins.append(importutils.import_object(
|
||||
conf[machine_learning_plugin_name].plugin_path,
|
||||
conf))
|
||||
CONF[machine_learning_plugin_name].plugin_path,
|
||||
CONF))
|
||||
return machine_learning_plugins
|
||||
|
||||
|
||||
|
@ -11,11 +11,12 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
import oslo_messaging as oslo_msg
|
||||
|
||||
# from oslo_messaging import serializer as oslo_serializer
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
DEFAULT_URL = "__default__"
|
||||
@ -28,11 +29,11 @@ def setup():
|
||||
oslo_msg.set_transport_defaults('vitrage')
|
||||
|
||||
|
||||
def get_rpc_transport(conf, url=None, optional=False, cache=True):
|
||||
return get_transport(conf, url, optional, cache, rpc=True)
|
||||
def get_rpc_transport(url=None, optional=False, cache=True):
|
||||
return get_transport(url, optional, cache, rpc=True)
|
||||
|
||||
|
||||
def get_transport(conf, url=None, optional=False, cache=True, rpc=False):
|
||||
def get_transport(url=None, optional=False, cache=True, rpc=False):
|
||||
"""Initialise the oslo_messaging layer."""
|
||||
global TRANSPORTS, DEFAULT_URL
|
||||
cache_key = url or DEFAULT_URL + '_rpc' if rpc else ''
|
||||
@ -40,9 +41,9 @@ def get_transport(conf, url=None, optional=False, cache=True, rpc=False):
|
||||
if not transport or not cache:
|
||||
try:
|
||||
if rpc:
|
||||
transport = oslo_msg.get_rpc_transport(conf, url)
|
||||
transport = oslo_msg.get_rpc_transport(CONF, url)
|
||||
else:
|
||||
transport = oslo_msg.get_notification_transport(conf, url)
|
||||
transport = oslo_msg.get_notification_transport(CONF, url)
|
||||
except oslo_msg.InvalidTransportURL as e:
|
||||
if not optional or e.url:
|
||||
# NOTE(sileht): oslo_messaging is configured but unloadable
|
||||
@ -65,8 +66,8 @@ def get_notification_listener(transport, targets, endpoints,
|
||||
|
||||
class VitrageNotifier(object):
|
||||
"""Allows writing to message bus"""
|
||||
def __init__(self, conf, publisher_id, topics):
|
||||
transport = get_transport(conf)
|
||||
def __init__(self, publisher_id, topics):
|
||||
transport = get_transport()
|
||||
self.notifier = oslo_msg.Notifier(
|
||||
transport,
|
||||
driver='messagingv2',
|
||||
|
@ -39,9 +39,9 @@ class AodhNotifier(NotifierBase):
|
||||
def get_notifier_name():
|
||||
return AODH_DATASOURCE
|
||||
|
||||
def __init__(self, conf):
|
||||
super(AodhNotifier, self).__init__(conf)
|
||||
self.client = os_clients.aodh_client(conf)
|
||||
def __init__(self):
|
||||
super(AodhNotifier, self).__init__()
|
||||
self.client = os_clients.aodh_client()
|
||||
|
||||
def process_event(self, data, event_type):
|
||||
response = None
|
||||
|
@ -19,9 +19,6 @@ import six
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class NotifierBase(object):
|
||||
|
||||
def __init__(self, conf):
|
||||
self.conf = conf
|
||||
|
||||
@abc.abstractmethod
|
||||
def process_event(self, data, event_type):
|
||||
pass
|
||||
|
@ -25,9 +25,8 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
class MistralNotifier(NotifierBase):
|
||||
|
||||
def __init__(self, conf):
|
||||
super(MistralNotifier, self).__init__(conf)
|
||||
self.conf = conf
|
||||
def __init__(self):
|
||||
super(MistralNotifier, self).__init__()
|
||||
self._client = None
|
||||
|
||||
@staticmethod
|
||||
@ -41,7 +40,7 @@ class MistralNotifier(NotifierBase):
|
||||
@property
|
||||
def client(self):
|
||||
if not self._client:
|
||||
self._client = os_clients.mistral_client(self.conf)
|
||||
self._client = os_clients.mistral_client()
|
||||
return self._client
|
||||
|
||||
def info(self, ctxt, publisher_id, event_type, payload, metadata):
|
||||
|
@ -30,9 +30,9 @@ class NovaNotifier(NotifierBase):
|
||||
def get_notifier_name():
|
||||
return 'nova'
|
||||
|
||||
def __init__(self, conf):
|
||||
super(NovaNotifier, self).__init__(conf)
|
||||
self.client = os_clients.nova_client(conf)
|
||||
def __init__(self):
|
||||
super(NovaNotifier, self).__init__()
|
||||
self.client = os_clients.nova_client()
|
||||
self.actions = {
|
||||
NOVA_HOST_DATASOURCE: self._mark_host_down,
|
||||
NOVA_INSTANCE_DATASOURCE: self._reset_instance_state
|
||||
|
@ -20,9 +20,6 @@ import six
|
||||
class SnmpSenderBase(object):
|
||||
"""Abstract Vitrage snmp trap sender"""
|
||||
|
||||
def __init__(self, conf):
|
||||
self.conf = conf
|
||||
|
||||
@abc.abstractmethod
|
||||
def send_snmp(self, alarm_data):
|
||||
pass
|
||||
|
@ -12,6 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import importutils
|
||||
|
||||
@ -19,6 +20,7 @@ from vitrage.common.constants import NotifierEventTypes
|
||||
from vitrage.common.constants import VertexProperties as VProps
|
||||
from vitrage.notifier.plugins.base import NotifierBase
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -27,10 +29,10 @@ class SnmpNotifier(NotifierBase):
|
||||
def get_notifier_name():
|
||||
return 'snmp'
|
||||
|
||||
def __init__(self, conf):
|
||||
super(SnmpNotifier, self).__init__(conf)
|
||||
def __init__(self):
|
||||
super(SnmpNotifier, self).__init__()
|
||||
self.snmp_sender = \
|
||||
importutils.import_object(conf.snmp.snmp_sender_class, conf)
|
||||
importutils.import_object(CONF.snmp.snmp_sender_class)
|
||||
|
||||
def process_event(self, data, event_type):
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from pysnmp.entity.engine import SnmpEngine
|
||||
from pysnmp.hlapi.asyncore.sync.compat.ntforg import sendNotification
|
||||
@ -27,6 +28,7 @@ from vitrage.common.constants import VertexProperties as VProps
|
||||
from vitrage.notifier.plugins.snmp.base import SnmpSenderBase
|
||||
from vitrage.utils.file import load_yaml_file
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
# TODO(annarez): change NA to N/A
|
||||
@ -43,12 +45,11 @@ PORT_PAT = re.compile('\d+')
|
||||
|
||||
|
||||
class SnmpSender(SnmpSenderBase):
|
||||
def __init__(self, conf):
|
||||
super(SnmpSender, self).__init__(conf)
|
||||
self.hosts = load_yaml_file(self.conf.snmp.consumers, True)
|
||||
self.oid_tree = load_yaml_file(self.conf.snmp.oid_tree, True)
|
||||
def __init__(self):
|
||||
self.hosts = load_yaml_file(CONF.snmp.consumers, True)
|
||||
self.oid_tree = load_yaml_file(CONF.snmp.oid_tree, True)
|
||||
self.alarm_mapping = \
|
||||
load_yaml_file(self.conf.snmp.alarm_oid_mapping, True)
|
||||
load_yaml_file(CONF.snmp.alarm_oid_mapping, True)
|
||||
self.oids, self.var_fields = self._build_oids()
|
||||
|
||||
def send_snmp(self, alarm_data):
|
||||
|
@ -14,6 +14,7 @@
|
||||
import ast
|
||||
import re
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import uuidutils
|
||||
@ -26,6 +27,7 @@ from vitrage.notifier.plugins.base import NotifierBase
|
||||
from vitrage.notifier.plugins.webhook import utils as webhook_utils
|
||||
from vitrage import storage
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
URL = 'url'
|
||||
IS_ADMIN_WEBHOOK = 'is_admin_webhook'
|
||||
@ -65,10 +67,10 @@ class Webhook(NotifierBase):
|
||||
def get_notifier_name():
|
||||
return 'webhook'
|
||||
|
||||
def __init__(self, conf):
|
||||
super(Webhook, self).__init__(conf)
|
||||
self._db = storage.get_connection_from_config(self.conf)
|
||||
self.max_retries = self.conf.webhook.max_retries
|
||||
def __init__(self):
|
||||
super(Webhook, self).__init__()
|
||||
self._db = storage.get_connection_from_config()
|
||||
self.max_retries = CONF.webhook.max_retries
|
||||
self.default_headers = {'content-type': 'application/json'}
|
||||
|
||||
def process_event(self, data, event_type):
|
||||
|
@ -11,22 +11,24 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
|
||||
from vitrage.common.constants import NotifierEventTypes
|
||||
from vitrage.notifier.plugins.base import NotifierBase
|
||||
from vitrage import os_clients
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class ZaqarNotifier(NotifierBase):
|
||||
|
||||
def __init__(self, conf):
|
||||
super(ZaqarNotifier, self).__init__(conf)
|
||||
client = os_clients.zaqar_client(self.conf)
|
||||
self._queue = client.queue(self.conf.zaqar.queue)
|
||||
def __init__(self):
|
||||
super(ZaqarNotifier, self).__init__()
|
||||
client = os_clients.zaqar_client()
|
||||
self._queue = client.queue(CONF.zaqar.queue)
|
||||
|
||||
@staticmethod
|
||||
def get_notifier_name():
|
||||
|
@ -11,6 +11,8 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
import oslo_messaging
|
||||
from oslo_utils import importutils
|
||||
@ -19,16 +21,16 @@ from vitrage.coordination import service as coord
|
||||
from vitrage import messaging
|
||||
from vitrage.opts import register_opts
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
class VitrageNotifierService(coord.Service):
|
||||
|
||||
def __init__(self, worker_id, conf):
|
||||
super(VitrageNotifierService, self).__init__(worker_id, conf)
|
||||
self.conf = conf
|
||||
self.notifiers = self.get_notifier_plugins(conf)
|
||||
self._init_listeners(self.conf)
|
||||
def __init__(self, worker_id):
|
||||
super(VitrageNotifierService, self).__init__(worker_id)
|
||||
self.notifiers = self.get_notifier_plugins()
|
||||
self._init_listeners()
|
||||
|
||||
def run(self):
|
||||
super(VitrageNotifierService, self).run()
|
||||
@ -51,31 +53,30 @@ class VitrageNotifierService(coord.Service):
|
||||
LOG.info("Vitrage Notifier Service - Stopped!")
|
||||
|
||||
@staticmethod
|
||||
def get_notifier_plugins(conf):
|
||||
def get_notifier_plugins():
|
||||
notifiers = []
|
||||
conf_notifier_names = conf.notifiers
|
||||
conf_notifier_names = CONF.notifiers
|
||||
if not conf_notifier_names:
|
||||
LOG.info('There are no notifier plugins in configuration')
|
||||
return []
|
||||
for notifier_name in conf_notifier_names:
|
||||
register_opts(conf, notifier_name, conf.notifiers_path)
|
||||
register_opts(notifier_name, CONF.notifiers_path)
|
||||
LOG.info('Notifier plugin %s started', notifier_name)
|
||||
notifiers.append(importutils.import_object(
|
||||
conf[notifier_name].notifier,
|
||||
conf))
|
||||
CONF[notifier_name].notifier))
|
||||
return notifiers
|
||||
|
||||
def _init_listeners(self, conf):
|
||||
def _init_listeners(self):
|
||||
self.listeners = []
|
||||
transport = messaging.get_transport(conf)
|
||||
transport = messaging.get_transport()
|
||||
|
||||
self._init_notifier(transport=transport,
|
||||
topic=conf.entity_graph.notifier_topic,
|
||||
topic=CONF.entity_graph.notifier_topic,
|
||||
endpoint=VitrageDefaultEventEndpoint(
|
||||
self.notifiers))
|
||||
|
||||
topic_prefix = \
|
||||
conf.evaluator_actions.evaluator_notification_topic_prefix
|
||||
CONF.evaluator_actions.evaluator_notification_topic_prefix
|
||||
|
||||
for notifier in self.notifiers:
|
||||
if notifier.use_private_topic():
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user