aboutsummaryrefslogtreecommitdiffstats
path: root/moonv4/moon_db/moon_db/backends/memory.py
diff options
context:
space:
mode:
authorWuKong <rebirthmonkey@gmail.com>2017-04-22 13:25:07 +0200
committerWuKong <rebirthmonkey@gmail.com>2017-04-22 13:25:07 +0200
commitd182202fc6001983541504ed323d68479086317e (patch)
tree11d4c10cdd3e995f519c3e0e324968fdaf175114 /moonv4/moon_db/moon_db/backends/memory.py
parent83c1c966baf73329fab8ddcfad19ad7fe0c41c2a (diff)
add moonv4
Change-Id: I247af788d0b0fb961fbc85416486b241eb1d807c Signed-off-by: WuKong <rebirthmonkey@gmail.com>
Diffstat (limited to 'moonv4/moon_db/moon_db/backends/memory.py')
-rw-r--r--moonv4/moon_db/moon_db/backends/memory.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/moonv4/moon_db/moon_db/backends/memory.py b/moonv4/moon_db/moon_db/backends/memory.py
new file mode 100644
index 00000000..06de99eb
--- /dev/null
+++ b/moonv4/moon_db/moon_db/backends/memory.py
@@ -0,0 +1,60 @@
+# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
+# This software is distributed under the terms and conditions of the 'Apache-2.0'
+# license which can be found in the file 'LICENSE' in this package distribution
+# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
+
+import os
+import json
+import logging
+import hashlib
+from glob import glob
+from oslo_config import cfg
+from moon_db.core import ConfigurationDriver
+
+LOG = logging.getLogger(__name__)
+CONF = cfg.CONF
+
+
+class ConfigurationConnector(object):
+
+ def __init__(self, engine):
+ super(ConfigurationConnector, self).__init__()
+ self.policy_directory = CONF.policy_directory
+ self.aggregation_algorithms_dict = dict()
+ self.aggregation_algorithms_dict[hashlib.sha224("all_true".encode("utf-8")).hexdigest()[:32]] = \
+ {'name': 'all_true', 'description': 'all rules must match'}
+ self.aggregation_algorithms_dict[hashlib.sha224("one_true".encode("utf-8")).hexdigest()[:32]] = \
+ {'name': 'one_true', 'description': 'only one rule has to match'}
+ self.sub_meta_rule_algorithms_dict = dict()
+ self.sub_meta_rule_algorithms_dict[hashlib.sha224("inclusion".encode("utf-8")).hexdigest()[:32]] = \
+ {'name': 'inclusion', 'description': 'inclusion'}
+ self.sub_meta_rule_algorithms_dict[hashlib.sha224("comparison".encode("utf-8")).hexdigest()[:32]] = \
+ {'name': 'comparison', 'description': 'comparison'}
+
+ def get_policy_templates_dict(self):
+ """
+ :return: {
+ template_id1: {name: template_name, description: template_description},
+ template_id2: {name: template_name, description: template_description},
+ ...
+ }
+ """
+ nodes = glob(os.path.join(self.policy_directory, "*"))
+ LOG.info("get_policy_templates_dict {} {}".format(self.policy_directory, nodes))
+ templates = dict()
+ for node in nodes:
+ try:
+ metadata = json.load(open(os.path.join(node, "metadata.json")))
+ except IOError:
+ # Note (asteroide): it's not a true policy directory, so we forgive it
+ continue
+ templates[os.path.basename(node)] = dict()
+ templates[os.path.basename(node)]["name"] = metadata["name"]
+ templates[os.path.basename(node)]["description"] = metadata["description"]
+ return templates
+
+ def get_aggregation_algorithms_dict(self):
+ return self.aggregation_algorithms_dict
+
+ def get_sub_meta_rule_algorithms_dict(self):
+ return self.sub_meta_rule_algorithms_dict