Coverage for watcher/conf/plugins.py: 82%
28 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-17 12:22 +0000
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-17 12:22 +0000
1# -*- encoding: utf-8 -*-
2# Copyright (c) 2016 b<>com
3#
4# Authors: Vincent FRANCOISE <vincent.francoise@b-com.com>
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15# implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
19import prettytable as ptable
21from watcher.applier.loading import default as applier_loader
22from watcher.common import utils
23from watcher.decision_engine.loading import default as decision_engine_loader
25PLUGIN_LOADERS = (
26 applier_loader.DefaultActionLoader,
27 decision_engine_loader.DefaultPlannerLoader,
28 decision_engine_loader.DefaultScoringLoader,
29 decision_engine_loader.DefaultScoringContainerLoader,
30 decision_engine_loader.DefaultStrategyLoader,
31 decision_engine_loader.ClusterDataModelCollectorLoader,
32 applier_loader.DefaultWorkFlowEngineLoader,
33)
36def list_opts():
37 """Load config options for all Watcher plugins"""
38 plugins_opts = []
39 for plugin_loader_cls in PLUGIN_LOADERS:
40 plugin_loader = plugin_loader_cls()
41 plugins_map = plugin_loader.list_available()
43 for plugin_name, plugin_cls in plugins_map.items():
44 plugin_opts = plugin_cls.get_config_opts()
45 if plugin_opts:
46 plugins_opts.append(
47 (plugin_loader.get_entry_name(plugin_name), plugin_opts))
49 return plugins_opts
52def _show_plugins_ascii_table(rows):
53 headers = ["Namespace", "Plugin name", "Import path"]
54 table = ptable.PrettyTable(field_names=headers)
55 for row in rows:
56 table.add_row(row)
57 return table.get_string()
60def show_plugins():
61 rows = []
62 for plugin_loader_cls in PLUGIN_LOADERS:
63 plugin_loader = plugin_loader_cls()
64 plugins_map = plugin_loader.list_available()
66 rows += [
67 (plugin_loader.get_entry_name(plugin_name),
68 plugin_name,
69 utils.get_cls_import_path(plugin_cls))
70 for plugin_name, plugin_cls in plugins_map.items()]
72 return _show_plugins_ascii_table(rows)