aboutsummaryrefslogtreecommitdiffstats
path: root/app/utils
diff options
context:
space:
mode:
Diffstat (limited to 'app/utils')
-rw-r--r--app/utils/cli_dist_translator.py59
-rw-r--r--app/utils/inventory_mgr.py19
-rw-r--r--app/utils/logging/mongo_logging_handler.py3
-rw-r--r--app/utils/mongo_access.py2
-rw-r--r--app/utils/util.py4
5 files changed, 76 insertions, 11 deletions
diff --git a/app/utils/cli_dist_translator.py b/app/utils/cli_dist_translator.py
new file mode 100644
index 0000000..4073bb2
--- /dev/null
+++ b/app/utils/cli_dist_translator.py
@@ -0,0 +1,59 @@
+###############################################################################
+# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
+# and others #
+# #
+# All rights reserved. This program and the accompanying materials #
+# are made available under the terms of the Apache License, Version 2.0 #
+# which accompanies this distribution, and is available at #
+# http://www.apache.org/licenses/LICENSE-2.0 #
+###############################################################################
+
+class CliDistTranslator:
+
+ DOCKER_CALL = 'docker exec --user root'
+
+ TRANSLATIONS = {
+ # special handling of cli commands in Mercury environments
+ 'Mercury': {
+ 'ip netns list':
+ '{docker_call} neutron_l3_agent_{version} {cmd};;;'
+ '{docker_call} neutron_dhcp_agent_{version} {cmd}',
+ 'ip netns exec qdhcp': \
+ '{docker_call} neutron_dhcp_agent_{version} {cmd}',
+ 'ip netns exec qrouter': \
+ '{docker_call} neutron_l3_agent_{version} {cmd}',
+ 'virsh': '{docker_call} novalibvirt_{version} {cmd}',
+ 'ip link': '{docker_call} ovs_vswitch_{version} {cmd}',
+ 'ip -d link': '{docker_call} ovs_vswitch_{version} {cmd}',
+ 'bridge fdb show': '{docker_call} ovs_vswitch_{version} {cmd}',
+ 'brctl': '{docker_call} ovs_vswitch_{version} {cmd}',
+ 'ovs-vsctl': '{docker_call} ovs_vswitch_{version} {cmd}',
+ 'ovs-dpctl': '{docker_call} ovs_vswitch_{version} {cmd}'
+ }
+ }
+
+ def __init__(self, dist: str, dist_version: str=''):
+ self.translation = self.TRANSLATIONS.get(dist, {})
+ self.dist_version = dist_version
+
+ def translate(self, command_to_translate: str) -> str:
+ for command in self.translation.keys():
+ if command in command_to_translate:
+ return self.command_translation(command_to_translate,
+ command)
+ return command_to_translate
+
+ def command_translation(self, command_to_translate: str,
+ translation_key: str) -> str:
+ cmd_translation = self.translation.get(translation_key)
+ if not cmd_translation:
+ return command_to_translate
+ translation_dict = {
+ 'docker_call': self.DOCKER_CALL,
+ 'version': self.dist_version,
+ 'cmd': translation_key
+ }
+ cmd_translation = cmd_translation.format(**translation_dict)
+ cmd_translation = command_to_translate.replace(translation_key,
+ cmd_translation)
+ return cmd_translation
diff --git a/app/utils/inventory_mgr.py b/app/utils/inventory_mgr.py
index 257b0e3..77c1165 100644
--- a/app/utils/inventory_mgr.py
+++ b/app/utils/inventory_mgr.py
@@ -77,13 +77,16 @@ class InventoryMgr(MongoAccess, metaclass=Singleton):
self.set_collection("clique_constraints")
self.set_collection("cliques")
self.set_collection("monitoring_config")
- self.set_collection("constants", use_default_name=True)
self.set_collection("scans")
self.set_collection("messages")
- self.set_collection("monitoring_config_templates",
- use_default_name=True)
self.set_collection("environments_config")
self.set_collection("supported_environments")
+ self.set_collection("constants",
+ use_default_name=True)
+ self.set_collection("monitoring_config_templates",
+ use_default_name=True)
+ self.set_collection("api_tokens",
+ use_default_name=True)
def clear(self, scan_plan):
if scan_plan.inventory_only:
@@ -348,9 +351,13 @@ class InventoryMgr(MongoAccess, metaclass=Singleton):
if isinstance(env_config['mechanism_drivers'], list) \
else env_config['mechanism_drivers']
- full_env = {'environment.distribution': env_config['distribution'],
- 'environment.type_drivers': env_config['type_drivers'],
- 'environment.mechanism_drivers': mechanism_driver}
+ full_env = {
+ 'environment.distribution': env_config['distribution'],
+ 'environment.distribution_version':
+ {"$in": [env_config['distribution_version']]},
+ 'environment.type_drivers': env_config['type_drivers'],
+ 'environment.mechanism_drivers': mechanism_driver
+ }
return self.is_feature_supported_in_env(full_env, feature)
def is_feature_supported_in_env(self, env_def: dict,
diff --git a/app/utils/logging/mongo_logging_handler.py b/app/utils/logging/mongo_logging_handler.py
index b69270e..ffb6f85 100644
--- a/app/utils/logging/mongo_logging_handler.py
+++ b/app/utils/logging/mongo_logging_handler.py
@@ -44,10 +44,9 @@ class MongoLoggingHandler(logging.Handler):
# make ID from current timestamp
now = datetime.datetime.utcnow()
d = now - datetime.datetime(1970, 1, 1)
- ts = stringify_datetime(now)
timestamp_id = '{}.{}.{}'.format(d.days, d.seconds, d.microseconds)
source = self.SOURCE_SYSTEM
message = Message(msg_id=timestamp_id, env=self.env, source=source,
- msg=Logger.formatter.format(record), ts=ts,
+ msg=Logger.formatter.format(record), ts=now,
level=record.levelname)
self.inv.collections['messages'].insert_one(message.get()) \ No newline at end of file
diff --git a/app/utils/mongo_access.py b/app/utils/mongo_access.py
index d39794f..d4599f1 100644
--- a/app/utils/mongo_access.py
+++ b/app/utils/mongo_access.py
@@ -86,7 +86,7 @@ class MongoAccess(DictNamingConverter):
self.prepare_connect_uri()
MongoAccess.client = MongoClient(
self.connect_params["server"],
- self.connect_params["port"]
+ int(self.connect_params["port"])
)
MongoAccess.db = getattr(MongoAccess.client,
config_params.get('auth_db', self.DB_NAME))
diff --git a/app/utils/util.py b/app/utils/util.py
index 385dea7..ae7b518 100644
--- a/app/utils/util.py
+++ b/app/utils/util.py
@@ -147,8 +147,8 @@ def setup_args(args: dict,
return dict(defaults, **args)
-def encode_router_id(host_id: str, uuid: str):
- return '-'.join([host_id, 'qrouter', uuid])
+def encode_router_id(uuid: str):
+ return '-'.join(['qrouter', uuid])
def decode_router_id(router_id: str):