aboutsummaryrefslogtreecommitdiffstats
path: root/moonv4/moon_manager/moon_manager
diff options
context:
space:
mode:
Diffstat (limited to 'moonv4/moon_manager/moon_manager')
-rw-r--r--moonv4/moon_manager/moon_manager/__init__.py6
-rw-r--r--moonv4/moon_manager/moon_manager/__main__.py3
-rw-r--r--moonv4/moon_manager/moon_manager/api/__init__.py0
-rw-r--r--moonv4/moon_manager/moon_manager/api/generic.py28
-rw-r--r--moonv4/moon_manager/moon_manager/api/models.py199
-rw-r--r--moonv4/moon_manager/moon_manager/api/pdp.py68
-rw-r--r--moonv4/moon_manager/moon_manager/api/policies.py414
-rw-r--r--moonv4/moon_manager/moon_manager/messenger.py73
-rw-r--r--moonv4/moon_manager/moon_manager/server.py25
9 files changed, 816 insertions, 0 deletions
diff --git a/moonv4/moon_manager/moon_manager/__init__.py b/moonv4/moon_manager/moon_manager/__init__.py
new file mode 100644
index 00000000..903c6518
--- /dev/null
+++ b/moonv4/moon_manager/moon_manager/__init__.py
@@ -0,0 +1,6 @@
+# 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'.
+
+__version__ = "0.1.0"
diff --git a/moonv4/moon_manager/moon_manager/__main__.py b/moonv4/moon_manager/moon_manager/__main__.py
new file mode 100644
index 00000000..0b264ce6
--- /dev/null
+++ b/moonv4/moon_manager/moon_manager/__main__.py
@@ -0,0 +1,3 @@
+from moon_manager.server import main
+
+main()
diff --git a/moonv4/moon_manager/moon_manager/api/__init__.py b/moonv4/moon_manager/moon_manager/api/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/moonv4/moon_manager/moon_manager/api/__init__.py
diff --git a/moonv4/moon_manager/moon_manager/api/generic.py b/moonv4/moon_manager/moon_manager/api/generic.py
new file mode 100644
index 00000000..db61188b
--- /dev/null
+++ b/moonv4/moon_manager/moon_manager/api/generic.py
@@ -0,0 +1,28 @@
+# 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'.
+
+
+class Status(object):
+ """
+ Retrieve the current status of all components.
+ """
+
+ __version__ = "0.1.0"
+
+ def get_status(self, ctx, args):
+ return {"status": "Running"}
+
+
+class Logs(object):
+ """
+ Retrieve the current status of all components.
+ """
+
+ __version__ = "0.1.0"
+
+ def get_logs(self, ctx, args):
+ return {"error": "NotImplemented"}
+
+
diff --git a/moonv4/moon_manager/moon_manager/api/models.py b/moonv4/moon_manager/moon_manager/api/models.py
new file mode 100644
index 00000000..6cb81439
--- /dev/null
+++ b/moonv4/moon_manager/moon_manager/api/models.py
@@ -0,0 +1,199 @@
+# 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'.
+
+from oslo_log import log as logging
+from oslo_config import cfg
+from moon_db.core import ModelManager
+
+LOG = logging.getLogger(__name__)
+CONF = cfg.CONF
+
+
+class Models(object):
+
+ def __init__(self):
+ self.manager = ModelManager
+
+ def get_models(self, ctx, args):
+ try:
+ data = self.manager.get_models(user_id=ctx["user_id"], model_id=ctx["id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"models": data}
+
+ def add_model(self, ctx, args):
+ try:
+ data = self.manager.add_model(user_id=ctx["user_id"], model_id=ctx["id"], value=args)
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"models": data}
+
+ def delete_model(self, ctx, args):
+ try:
+ data = self.manager.delete_model(user_id=ctx["user_id"], model_id=ctx["id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"result": True}
+
+ def update_model(self, ctx, args):
+ try:
+ data = self.manager.update_model(user_id=ctx["user_id"], model_id=ctx["id"], value=args)
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"models": data}
+
+
+class MetaRules(object):
+
+ def __init__(self):
+ self.manager = ModelManager
+
+ def add_meta_rules(self, ctx, args):
+ try:
+ data = self.manager.add_meta_rule(user_id=ctx["user_id"], meta_rule_id=None, value=args)
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"meta_rules": data}
+
+ def delete_meta_rules(self, ctx, args):
+ try:
+ data = self.manager.delete_meta_rule(user_id=ctx["user_id"], meta_rule_id=ctx["meta_rule_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"result": True}
+
+ def get_meta_rules(self, ctx, args):
+ try:
+ data = self.manager.get_meta_rules(user_id=ctx["user_id"], meta_rule_id=ctx["meta_rule_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"meta_rules": data}
+
+ def set_meta_rules(self, ctx, args):
+ try:
+ data = self.manager.set_meta_rule(user_id=ctx["user_id"], meta_rule_id=ctx["meta_rule_id"], value=args)
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"meta_rules": data}
+
+
+class MetaData(object):
+
+ def __init__(self):
+ self.manager = ModelManager
+
+ def get_subject_categories(self, ctx, args):
+ try:
+ data = self.manager.get_subject_categories(user_id=ctx["user_id"], category_id=args["category_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"subject_categories": data}
+
+ def set_subject_category(self, ctx, args):
+ try:
+ data = self.manager.add_subject_category(user_id=ctx["user_id"], value=args)
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"subject_categories": data}
+
+ def delete_subject_category(self, ctx, args):
+ try:
+ data = self.manager.delete_subject_category(user_id=ctx["user_id"], category_id=args["category_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"result": True}
+
+ def get_object_categories(self, ctx, args):
+ try:
+ data = self.manager.get_object_categories(user_id=ctx["user_id"], category_id=args["category_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"object_categories": data}
+
+ def set_object_category(self, ctx, args):
+ try:
+ data = self.manager.add_object_category(user_id=ctx["user_id"], value=args)
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"object_categories": data}
+
+ def delete_object_category(self, ctx, args):
+ try:
+ data = self.manager.delete_object_category(user_id=ctx["user_id"], category_id=args["category_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"result": True}
+
+ def get_action_categories(self, ctx, args):
+ try:
+ data = self.manager.get_action_categories(user_id=ctx["user_id"], category_id=args["category_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"action_categories": data}
+
+ def set_action_category(self, ctx, args):
+ try:
+ data = self.manager.add_action_category(user_id=ctx["user_id"], value=args)
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"action_categories": data}
+
+ def delete_action_category(self, ctx, args):
+ try:
+ data = self.manager.delete_action_category(user_id=ctx["user_id"], category_id=args["category_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"result": True}
diff --git a/moonv4/moon_manager/moon_manager/api/pdp.py b/moonv4/moon_manager/moon_manager/api/pdp.py
new file mode 100644
index 00000000..22504628
--- /dev/null
+++ b/moonv4/moon_manager/moon_manager/api/pdp.py
@@ -0,0 +1,68 @@
+# 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 copy
+from uuid import uuid4
+from oslo_log import log as logging
+from oslo_config import cfg
+from moon_utilities import exceptions
+from moon_db.core import PDPManager
+from moon_utilities.misc import get_uuid_from_name
+from moon_utilities.security_functions import call
+
+LOG = logging.getLogger(__name__)
+CONF = cfg.CONF
+
+
+class PDP(object):
+
+ def __init__(self):
+ self.manager = PDPManager
+
+ def get_pdp(self, ctx, args=None):
+ try:
+ data = self.manager.get_pdp(user_id=ctx["user_id"], pdp_id=ctx.get("id"))
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"pdps": data}
+
+ def add_pdp(self, ctx, args):
+ try:
+ data = self.manager.add_pdp(user_id=ctx["user_id"], pdp_id=None, value=args)
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"pdps": data}
+
+ def delete_pdp(self, ctx, args):
+ try:
+ data = self.manager.delete_pdp(user_id=ctx["user_id"], pdp_id=ctx.get("id"))
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"result": True}
+
+ def update_pdp(self, ctx, args):
+ try:
+ data = self.manager.update_pdp(user_id=ctx["user_id"], pdp_id=ctx.get("id"), value=args)
+ call("orchestrator", method="add_container",
+ ctx={"id": ctx.get("id"), "pipeline": data[ctx.get("id")]['security_pipeline']})
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"pdps": data}
+
+
diff --git a/moonv4/moon_manager/moon_manager/api/policies.py b/moonv4/moon_manager/moon_manager/api/policies.py
new file mode 100644
index 00000000..e2f332e2
--- /dev/null
+++ b/moonv4/moon_manager/moon_manager/api/policies.py
@@ -0,0 +1,414 @@
+# 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'.
+
+from oslo_log import log as logging
+from oslo_config import cfg
+from moon_db.core import PolicyManager
+
+LOG = logging.getLogger(__name__)
+CONF = cfg.CONF
+
+
+class Policies(object):
+
+ def __init__(self):
+ self.manager = PolicyManager
+
+ def get_policies(self, ctx, args):
+ try:
+ data = self.manager.get_policies(user_id=ctx["user_id"], policy_id=ctx["id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"policies": data}
+
+ def add_policy(self, ctx, args):
+ try:
+ data = self.manager.add_policy(user_id=ctx["user_id"], policy_id=ctx["id"], value=args)
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"policies": data}
+
+ def delete_policy(self, ctx, args):
+ try:
+ data = self.manager.delete_policy(user_id=ctx["user_id"], policy_id=ctx["id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"result": True}
+
+ def update_policy(self, ctx, args):
+ try:
+ data = self.manager.update_policy(user_id=ctx["user_id"], policy_id=ctx["id"], value=args)
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"policies": data}
+
+
+class Perimeter(object):
+
+ def __init__(self):
+ self.manager = PolicyManager
+
+ def get_subjects(self, ctx, args):
+ try:
+ data = self.manager.get_subjects(user_id=ctx["user_id"], policy_id=ctx["id"], perimeter_id=args['perimeter_id'])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"subjects": data}
+
+ def set_subject(self, ctx, args):
+ try:
+ data = self.manager.add_subject(user_id=ctx["user_id"], policy_id=ctx["id"],
+ perimeter_id=ctx["perimeter_id"], value=args)
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"subjects": data}
+
+ def delete_subject(self, ctx, args):
+ try:
+ data = self.manager.delete_subject(user_id=ctx["user_id"], policy_id=ctx["id"], perimeter_id=args["perimeter_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"result": True}
+
+ def get_objects(self, ctx, args):
+ try:
+ data = self.manager.get_objects(user_id=ctx["user_id"], policy_id=ctx["id"], perimeter_id=args['perimeter_id'])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"objects": data}
+
+ def set_object(self, ctx, args):
+ try:
+ data = self.manager.add_object(user_id=ctx["user_id"], policy_id=ctx["id"],
+ perimeter_id=ctx["perimeter_id"], value=args)
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"objects": data}
+
+ def delete_object(self, ctx, args):
+ try:
+ data = self.manager.delete_object(user_id=ctx["user_id"], policy_id=ctx["id"], perimeter_id=args["perimeter_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"result": True}
+
+ def get_actions(self, ctx, args):
+ try:
+ data = self.manager.get_actions(user_id=ctx["user_id"], policy_id=ctx["id"], perimeter_id=args['perimeter_id'])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"actions": data}
+
+ def set_action(self, ctx, args):
+ try:
+ data = self.manager.add_action(user_id=ctx["user_id"], policy_id=ctx["id"],
+ perimeter_id=ctx["perimeter_id"], value=args)
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"actions": data}
+
+ def delete_action(self, ctx, args):
+ try:
+ data = self.manager.delete_action(user_id=ctx["user_id"], policy_id=ctx["id"], perimeter_id=args["perimeter_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"result": True}
+
+
+class Data(object):
+
+ def __init__(self):
+ self.manager = PolicyManager
+
+ def get_subject_data(self, ctx, args):
+ try:
+ data = self.manager.get_subject_data(user_id=ctx["user_id"], policy_id=ctx["id"],
+ category_id=ctx["category_id"], data_id=args["data_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"subject_data": data}
+
+ def add_subject_data(self, ctx, args):
+ try:
+ data = self.manager.set_subject_data(user_id=ctx["user_id"], policy_id=ctx["id"],
+ category_id=ctx["category_id"], value=args)
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"subject_data": data}
+
+ def delete_subject_data(self, ctx, args):
+ try:
+ data = self.manager.delete_subject_data(user_id=ctx["user_id"], policy_id=ctx["id"],
+ data_id=["data_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"result": True}
+
+ def get_object_data(self, ctx, args):
+ try:
+ data = self.manager.get_object_data(user_id=ctx["user_id"], policy_id=ctx["id"],
+ category_id=ctx["category_id"], data_id=args["data_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"object_data": data}
+
+ def add_object_data(self, ctx, args):
+ try:
+ data = self.manager.add_object_data(user_id=ctx["user_id"], policy_id=ctx["id"],
+ category_id=ctx["category_id"], value=args)
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"object_data": data}
+
+ def delete_object_data(self, ctx, args):
+ try:
+ data = self.manager.delete_object_data(user_id=ctx["user_id"], policy_id=ctx["id"],
+ data_id=["data_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"result": True}
+
+ def get_action_data(self, ctx, args):
+ try:
+ data = self.manager.get_action_data(user_id=ctx["user_id"], policy_id=ctx["id"],
+ category_id=ctx["category_id"], data_id=args["data_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"action_data": data}
+
+ def add_action_data(self, ctx, args):
+ try:
+ data = self.manager.add_action_data(user_id=ctx["user_id"], policy_id=ctx["id"],
+ category_id=ctx["category_id"], value=args)
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"action_data": data}
+
+ def delete_action_data(self, ctx, args):
+ try:
+ data = self.manager.delete_action_data(user_id=ctx["user_id"], policy_id=ctx["id"],
+ data_id=["data_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"result": True}
+
+
+class Assignments(object):
+
+ def __init__(self):
+ self.manager = PolicyManager
+
+ def get_subject_assignments(self, ctx, args):
+ try:
+ data = self.manager.get_subject_assignments(user_id=ctx["user_id"], policy_id=ctx["id"],
+ subject_id=ctx["perimeter_id"], category_id=ctx["category_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"subject_assignments": data}
+
+ def update_subject_assignment(self, ctx, args):
+ try:
+ data = self.manager.add_subject_assignment(user_id=ctx["user_id"], policy_id=ctx["id"],
+ subject_id=args["id"], category_id=args["category_id"],
+ data_id=args["data_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"subject_assignments": data}
+
+ def delete_subject_assignment(self, ctx, args):
+ try:
+ data = self.manager.delete_subject_assignment(user_id=ctx["user_id"], policy_id=ctx["id"],
+ subject_id=ctx["perimeter_id"], category_id=ctx["category_id"],
+ data_id=args["data_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"result": True}
+
+ def get_object_assignments(self, ctx, args):
+ try:
+ data = self.manager.get_object_assignments(user_id=ctx["user_id"], policy_id=ctx["id"],
+ object_id=ctx["perimeter_id"], category_id=ctx["category_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"object_assignments": data}
+
+ def update_object_assignment(self, ctx, args):
+ try:
+ data = self.manager.add_object_assignment(user_id=ctx["user_id"], policy_id=ctx["id"],
+ object_id=args["id"], category_id=args["category_id"],
+ data_id=args["data_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"object_assignments": data}
+
+ def delete_object_assignment(self, ctx, args):
+ try:
+ data = self.manager.delete_object_assignment(user_id=ctx["user_id"], policy_id=ctx["id"],
+ object_id=ctx["perimeter_id"], category_id=ctx["category_id"],
+ data_id=args["data_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"result": True}
+
+ def get_action_assignments(self, ctx, args):
+ try:
+ data = self.manager.get_action_assignments(user_id=ctx["user_id"], policy_id=ctx["id"],
+ action_id=ctx["perimeter_id"], category_id=ctx["category_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"action_assignments": data}
+
+ def update_action_assignment(self, ctx, args):
+ try:
+ data = self.manager.add_action_assignment(user_id=ctx["user_id"], policy_id=ctx["id"],
+ action_id=args["id"], category_id=args["category_id"],
+ data_id=args["data_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"action_assignments": data}
+
+ def delete_action_assignment(self, ctx, args):
+ try:
+ data = self.manager.delete_action_assignment(user_id=ctx["user_id"], policy_id=ctx["id"],
+ action_id=ctx["perimeter_id"], category_id=ctx["category_id"],
+ data_id=args["data_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"result": True}
+
+
+class Rules(object):
+
+ def __init__(self):
+ self.manager = PolicyManager
+
+ def get_rules(self, ctx, args):
+ try:
+ data = self.manager.get_rules(user_id=ctx["user_id"],
+ policy_id=ctx["id"],
+ # meta_rule_id=ctx["meta_rule_id"],
+ rule_id=ctx["rule_id"])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"rules": data}
+
+ def add_rule(self, ctx, args):
+ try:
+ data = self.manager.add_rule(user_id=ctx["user_id"],
+ policy_id=ctx["id"],
+ meta_rule_id=args["meta_rule_id"],
+ value=args)
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"rules": data}
+
+ def delete_rule(self, ctx, args):
+ try:
+ data = self.manager.delete_rule(user_id=ctx["user_id"], policy_id=ctx["id"], rule_id=ctx['rule_id'])
+ except Exception as e:
+ LOG.error(e, exc_info=True)
+ return {"result": False,
+ "error": str(e),
+ "ctx": ctx, "args": args}
+ return {"result": True}
diff --git a/moonv4/moon_manager/moon_manager/messenger.py b/moonv4/moon_manager/moon_manager/messenger.py
new file mode 100644
index 00000000..784b9eab
--- /dev/null
+++ b/moonv4/moon_manager/moon_manager/messenger.py
@@ -0,0 +1,73 @@
+# 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 time
+from oslo_config import cfg
+import oslo_messaging
+from oslo_log import log as logging
+from moon_manager.api.generic import Status, Logs
+from moon_utilities.api import APIList
+from moon_manager.api.models import Models, MetaRules, MetaData
+from moon_manager.api.policies import Policies, Perimeter, Data, Assignments, Rules
+from moon_manager.api.pdp import PDP
+from moon_utilities.security_functions import call
+from moon_utilities.exceptions import IntraExtensionUnknown
+
+LOG = logging.getLogger(__name__)
+CONF = cfg.CONF
+
+
+class Server:
+
+ def __init__(self):
+ self.TOPIC = "moon_manager"
+ self.transport = oslo_messaging.get_transport(cfg.CONF)
+ self.target = oslo_messaging.Target(topic=self.TOPIC, server='moon_manager_server1')
+ # ctx = {'user_id': 'admin', 'id': intra_extension_id, 'method': 'get_intra_extensions'}
+ # if CONF.slave.slave_name:
+ # ctx['call_master'] = True
+ # intra_extension = call(
+ # endpoint="security_router",
+ # ctx=ctx,
+ # method='route',
+ # args={}
+ # )
+ LOG.info("Starting MQ server with topic: {}".format(self.TOPIC))
+ # if "intra_extensions" not in intra_extension:
+ # LOG.error("Error reading intra_extension from router")
+ # LOG.error("intra_extension: {}".format(intra_extension))
+ # raise IntraExtensionUnknown
+ # intra_extension_id = list(intra_extension["intra_extensions"].keys())[0]
+ self.endpoints = [
+ APIList((Status, Logs)),
+ Status(),
+ Logs(),
+ Models(),
+ MetaRules(),
+ MetaData(),
+ Policies(),
+ Perimeter(),
+ Data(),
+ Assignments(),
+ Rules(),
+ PDP()
+ ]
+ self.server = oslo_messaging.get_rpc_server(self.transport, self.target, self.endpoints,
+ executor='threading',
+ access_policy=oslo_messaging.DefaultRPCAccessPolicy)
+
+ def run(self):
+ try:
+ self.server.start()
+ while True:
+ time.sleep(1)
+ except KeyboardInterrupt:
+ print("Stopping server by crtl+c")
+ except SystemExit:
+ print("Stopping server")
+
+ self.server.stop()
+ self.server.wait()
+
diff --git a/moonv4/moon_manager/moon_manager/server.py b/moonv4/moon_manager/moon_manager/server.py
new file mode 100644
index 00000000..715a74c3
--- /dev/null
+++ b/moonv4/moon_manager/moon_manager/server.py
@@ -0,0 +1,25 @@
+# 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
+from oslo_config import cfg
+from oslo_log import log as logging
+from moon_utilities import options # noqa
+from moon_manager.messenger import Server
+
+LOG = logging.getLogger(__name__)
+CONF = cfg.CONF
+DOMAIN = "moon_manager"
+
+__CWD__ = os.path.dirname(os.path.abspath(__file__))
+
+
+def main():
+ server = Server()
+ server.run()
+
+
+if __name__ == '__main__':
+ main()