aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/bin/README.md9
-rw-r--r--tools/bin/api2rst.py145
-rw-r--r--tools/bin/get_keystone_token.py71
-rw-r--r--tools/moon_kubernetes/start_moon.sh2
4 files changed, 224 insertions, 3 deletions
diff --git a/tools/bin/README.md b/tools/bin/README.md
index 3125c468..71ff4a44 100644
--- a/tools/bin/README.md
+++ b/tools/bin/README.md
@@ -1,5 +1,8 @@
# Automated Tools/Scripts
-## moon_utilities_update
-- update moon_utilities to PIP: `./moon_utilities_update.sh upload`
-- locally update moon_utilities for each moon Python package: `./moon_utilities_update.sh copy` \ No newline at end of file
+## api2pdf
+```bash
+python3 $MOON_HOME/tools/bin/api2rst.py
+pandoc api.rst --toc -o api.pdf
+evince api.pdf
+```
diff --git a/tools/bin/api2rst.py b/tools/bin/api2rst.py
new file mode 100644
index 00000000..6d407bdf
--- /dev/null
+++ b/tools/bin/api2rst.py
@@ -0,0 +1,145 @@
+# 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 sys
+import requests
+import logging
+import time
+import json
+
+os.unsetenv("http_proxy")
+logging.basicConfig(level=logging.INFO)
+logger = logging.getLogger(__name__)
+
+HOST = "172.18.0.11"
+PORT = 38001
+COMPONENT = sys.argv[2] if len(sys.argv) > 1 else "Interface"
+FILENAME = sys.argv[2] if len(sys.argv) > 2 else "api.rst"
+CURRENT_TIME = time.strftime("%Y/%m/%d %H:%M:%S %Z")
+REVISION = time.strftime("%Y%m%d_%H%M%S_%Z")
+AUTHOR = "Thomas Duval <thomas.duval@orange.com>"
+
+logger.info("Writing to {}".format(FILENAME))
+
+toc = (
+ "generic",
+ "models",
+ "policies",
+ "pdp",
+ "meta_rules",
+ "meta_data",
+ "perimeter",
+ "data",
+ "assignments",
+ "rules",
+ "authz",
+)
+
+
+def get_api_list():
+ url = "http://{}:{}/api".format(HOST, PORT)
+ cnx = requests.get(url)
+ try:
+ return cnx.json()
+ except json.decoder.JSONDecodeError:
+ logger.error("Error decoding JSON on {}\n{}".format(url, cnx.content))
+ sys.exit(1)
+
+
+def analyse_description(desc):
+ result = ""
+ if not desc:
+ return "No description"
+ for line in desc.splitlines():
+ if line.strip().startswith(":"):
+ if ":request body:" in line:
+ result += ":request body:\n\n.. code-block:: json\n\n"
+ result += line.replace(":request body: ", "") + "\n\n"
+ elif ":return:" in line:
+ result += ":return:\n\n.. code-block:: json\n\n"
+ result += line.replace(":return: ", "") + "\n"
+ else:
+ result += line.strip() + "\n\n"
+ else:
+ result += line + "\n"
+ return result
+
+
+def filter_and_sort(list_group_api):
+ results = list()
+ keys = list_group_api.keys()
+ for element in toc:
+ if element in keys:
+ results.append(element)
+ for element in keys:
+ if element not in results:
+ results.append(element)
+ return results
+
+
+def main():
+ list_group_api = get_api_list()
+
+ _toc = filter_and_sort(list_group_api)
+
+ file_desc = open(FILENAME, "w")
+ length_of_title = len("Moon {component} API".format(component=COMPONENT))
+ file_desc.write(HEADERS.format(
+ component=COMPONENT,
+ date=CURRENT_TIME,
+ revision=REVISION,
+ title_headers="="*length_of_title,
+ author=AUTHOR
+ ))
+
+ for key in _toc:
+ logger.info(key)
+ file_desc.write("{}\n".format(key))
+ file_desc.write("{}\n\n".format("="*len(key)))
+ if "description" in list_group_api[key]:
+ file_desc.write("{}\n\n".format(list_group_api[key]["description"]))
+ version = "unknown"
+ logger.debug(list_group_api.keys())
+ if "version" in list_group_api[key]:
+ version = list_group_api[key]["version"]
+ file_desc.write("Version: {}\n\n".format(version))
+ for api in list_group_api[key]:
+ logger.info("\t{}".format(api))
+ if api in ("description", "version"):
+ continue
+ file_desc.write("{}\n".format(api))
+ file_desc.write("{}\n\n".format("-" * len(api)))
+
+ file_desc.write("{}\n\n".format(list_group_api[key][api]["description"]))
+
+ file_desc.write("URLs are:\n\n")
+ for _url in list_group_api[key][api]["urls"]:
+ file_desc.write("* {}\n".format(_url))
+
+ file_desc.write("\nMethods are:\n\n")
+ for _method in list_group_api[key][api]["methods"]:
+ file_desc.write("→ {}\n".format(_method))
+ file_desc.write("{}\n\n".format("~"*(len(_method) + 2)))
+ file_desc.write("{}\n\n".format(analyse_description(list_group_api[key][api]["methods"][_method])))
+
+HEADERS = """{title_headers}
+Moon {component} API
+{title_headers}
+
+:Info: See <https://git.opnfv.org/cgit/moon/> for code.
+:Author: {author}
+:Date: {date}
+:Revision: $Revision: {revision} $
+:Description: List of the API served by the Moon {component} component
+
+This document list all of the API connectors served by the Moon {component} component
+Here are Moon API with some examples of posted data and returned data.
+All requests must be prefixed with the host and port, for example: http://localhost:38001/authz/123456789/123456789/servers/list
+
+"""
+
+if __name__ == "__main__":
+ main()
diff --git a/tools/bin/get_keystone_token.py b/tools/bin/get_keystone_token.py
new file mode 100644
index 00000000..1856aab8
--- /dev/null
+++ b/tools/bin/get_keystone_token.py
@@ -0,0 +1,71 @@
+import requests
+from oslo_config import cfg
+from oslo_log import log as logging
+from python_moonutilities import exceptions
+
+CONF = cfg.CONF
+LOG = logging.getLogger(__name__)
+
+
+def login(user=None, password=None, domain=None, project=None, url=None):
+ print("""Configuration:
+ user: {user}
+ domain: {domain}
+ project: {project}
+ url: {url}""".format(
+ user=CONF.keystone.user,
+ domain=CONF.keystone.domain,
+ project=CONF.keystone.project,
+ url=CONF.keystone.url,
+ ))
+ if not user:
+ user = CONF.keystone.user
+ if not password:
+ password = CONF.keystone.password
+ if not domain:
+ domain = CONF.keystone.domain
+ if not project:
+ project = CONF.keystone.project
+ if not url:
+ url = CONF.keystone.url
+ headers = {
+ "Content-Type": "application/json"
+ }
+ data_auth = {
+ "auth": {
+ "identity": {
+ "methods": [
+ "password"
+ ],
+ "password": {
+ "user": {
+ "domain": {
+ "id": domain
+ },
+ "name": user,
+ "password": password
+ }
+ }
+ },
+ "scope": {
+ "project": {
+ "domain": {
+ "id": domain
+ },
+ "name": project
+ }
+ }
+ }
+ }
+
+ req = requests.post("{}/auth/tokens".format(url),
+ json=data_auth, headers=headers,
+ verify=False)
+
+ if req.status_code not in (200, 201):
+ LOG.error(req.text)
+ raise exceptions.KeystoneError
+ headers['X-Auth-Token'] = req.headers['X-Subject-Token']
+ return headers
+
+print(login()['X-Auth-Token'])
diff --git a/tools/moon_kubernetes/start_moon.sh b/tools/moon_kubernetes/start_moon.sh
index 47d6998b..32d9740d 100644
--- a/tools/moon_kubernetes/start_moon.sh
+++ b/tools/moon_kubernetes/start_moon.sh
@@ -33,4 +33,6 @@ kubectl create -n moon -f tools/moon_kubernetes/templates/moon_orchestrator.yaml
kubectl create -n moon -f tools/moon_kubernetes/templates/moon_gui.yaml
+# load moon_wrapper on both master and slaves
+# moon_create_wrapper