diff options
Diffstat (limited to 'old/moon_forming')
-rw-r--r-- | old/moon_forming/.gitignore | 105 | ||||
-rw-r--r-- | old/moon_forming/Changelog | 11 | ||||
-rw-r--r-- | old/moon_forming/Dockerfile | 17 | ||||
-rw-r--r-- | old/moon_forming/README.md | 47 | ||||
-rw-r--r-- | old/moon_forming/conf2consul.py | 104 | ||||
-rw-r--r-- | old/moon_forming/config_moon.sh | 39 |
6 files changed, 323 insertions, 0 deletions
diff --git a/old/moon_forming/.gitignore b/old/moon_forming/.gitignore new file mode 100644 index 00000000..7bff7318 --- /dev/null +++ b/old/moon_forming/.gitignore @@ -0,0 +1,105 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + diff --git a/old/moon_forming/Changelog b/old/moon_forming/Changelog new file mode 100644 index 00000000..a107efd9 --- /dev/null +++ b/old/moon_forming/Changelog @@ -0,0 +1,11 @@ +CHANGES +======= + +1.4.0 +----- +- Update the python_moondb version to 1.2.10 + +1.4.1 +----- +- Update the python_moondb version to 1.2.16 + diff --git a/old/moon_forming/Dockerfile b/old/moon_forming/Dockerfile new file mode 100644 index 00000000..3a39880b --- /dev/null +++ b/old/moon_forming/Dockerfile @@ -0,0 +1,17 @@ +FROM python:3 + + +LABEL Name=Forming +LABEL Description="Configuration job for the Moon platform" +LABEL Maintainer="Thomas Duval" +LABEL Url="https://wiki.opnfv.org/display/moon/Moon+Project+Proposal" + +USER root + +WORKDIR /usr/src/app +RUN pip install --no-cache-dir --upgrade requests pytest pyyaml python_moonutilities python_moondb python_moonclient + +ADD . /root +WORKDIR /root + +CMD /bin/bash /root/config_moon.sh diff --git a/old/moon_forming/README.md b/old/moon_forming/README.md new file mode 100644 index 00000000..9b755d96 --- /dev/null +++ b/old/moon_forming/README.md @@ -0,0 +1,47 @@ +# Moon Forming +moon_forming is a container to automatize the configuration of the Moon platform + +## Run +```bash +docker run wukongsun/moon_forming:latest +``` + +## Consul +The Moon platform is already configured after the installation. +If you want to see or modify the configuration, go with a web browser +to the following page: `http://localhost:30006`. + +With the consul server, you can update the configuration in the `KEY/VALUE` tab. +There are some configuration items, lots of them are only read when a new K8S pod is started +and not during its life cycle. + +**WARNING: some confidential information are put here in clear text. +This is a known security issue.** + +### Keystone +If you have your own Keystone server, you can point Moon to your Keystone in the +`openstack/keystone` element: `http://localhost:30005/ui/#/dc1/kv/openstack/keystone/edit`. +This configuration element is read every time Moon need it, specially when adding users. + +### Database +The database can also be modified through: `http://localhost:30005/ui/#/dc1/kv/database/edit`. + +**WARNING: the password is in clear text, this is a known security issue.** + +If you want to use your own database server, change the configuration: + + {"url": "mysql+pymysql://my_user:my_secret_password@my_server/moon", "driver": "sql"} + +Then you have to rebuild the database before using it. +This can be done with the following commands: +```bash +kubectl delete -f $MOON_HOME/tools/moon_kubernetes/templates/moon_forming.yaml +kubectl create -f $MOON_HOME/tools/moon_kubernetes/templates/moon_forming.yaml +``` + +## Functional tests + +```bash +cd $MOON_HOME/moon_manager +bash ../tests/functional/run_tests_for_component.sh +``` diff --git a/old/moon_forming/conf2consul.py b/old/moon_forming/conf2consul.py new file mode 100644 index 00000000..df7a6b18 --- /dev/null +++ b/old/moon_forming/conf2consul.py @@ -0,0 +1,104 @@ +import os +import sys +import requests +import yaml +import logging +import json +import base64 + +__version__ = "1.4.1" + +logging.basicConfig(level=logging.INFO) +log = logging.getLogger("moon.conf2consul") +requests_log = logging.getLogger("requests.packages.urllib3") +requests_log.setLevel(logging.WARNING) +requests_log.propagate = True + +if len(sys.argv) == 2: + if os.path.isfile(sys.argv[1]): + CONF_FILENAME = sys.argv[1] + CONSUL_HOST = "consul" + else: + CONF_FILENAME = "moon.conf" + CONSUL_HOST = sys.argv[1] + CONSUL_PORT = 8500 +else: + CONSUL_HOST = sys.argv[1] if len(sys.argv) > 1 else "consul" + CONSUL_PORT = sys.argv[2] if len(sys.argv) > 2 else 8500 + CONF_FILENAME = sys.argv[3] if len(sys.argv) > 3 else "moon.conf" +HEADERS = {"content-type": "application/json"} + + +def search_config_file(): + data_config = None + for _file in ( + CONF_FILENAME, + "conf/moon.conf", + "../moon.conf", + "../conf/moon.conf", + "/etc/moon/moon.conf", + ): + try: + data_config = yaml.safe_load(open(_file)) + except FileNotFoundError: + data_config = None + continue + else: + break + if not data_config: + raise Exception("Configuration file not found...") + return data_config + + +def put(key, value): + url = "http://{host}:{port}/v1/kv/{key}".format(host=CONSUL_HOST, port=CONSUL_PORT, key=key) + log.info(url) + req = requests.put( + url, + headers=HEADERS, + json=value + ) + if req.status_code != 200: + raise Exception("Error connecting to Consul ({}, {})".format(req.status_code, req.text)) + + +def get(key): + url = "http://{host}:{port}/v1/kv/{key}".format(host=CONSUL_HOST, port=CONSUL_PORT, key=key) + req = requests.get(url) + data = req.json() + for item in data: + log.info("{} {} -> {}".format( + req.status_code, + item["Key"], + json.loads(base64.b64decode(item["Value"]).decode("utf-8")) + )) + yield json.loads(base64.b64decode(item["Value"]).decode("utf-8")) + + +def main(): + data_config = search_config_file() + req = requests.head("http://{}:{}/ui/".format(CONSUL_HOST, CONSUL_PORT)) + if req.status_code != 200: + log.critical("Consul is down...") + log.critical("request info: {}/{}".format(req, req.text)) + sys.exit(1) + + put("database", data_config["database"]) + # put("messenger", data_config["messenger"]) + # put("slave", data_config["slave"]) + # put("docker", data_config["docker"]) + put("logging", data_config["logging"]) + # put("components_port_start", data_config["components"]["port_start"]) + + for _key, _value in data_config["components"].items(): + put("components/{}".format(_key), data_config["components"][_key]) + + # for _key, _value in data_config["plugins"].items(): + # put("plugins/{}".format(_key), data_config["plugins"][_key]) + + for _key, _value in data_config["openstack"].items(): + put("openstack/{}".format(_key), data_config["openstack"][_key]) + + +main() + diff --git a/old/moon_forming/config_moon.sh b/old/moon_forming/config_moon.sh new file mode 100644 index 00000000..0a55898f --- /dev/null +++ b/old/moon_forming/config_moon.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +populate_args=$* + +echo "Waiting for Consul (http://consul:8500)" +while ! python -c "import requests; req = requests.get('http://consul:8500')" 2>/dev/null ; do + sleep 5 ; + echo -n "." +done +echo "." +echo "Consul (http://consul:8500) is up." + +python3 /root/conf2consul.py /etc/moon/moon.conf + +echo "Waiting for DB (tcp://db:3306)" +while ! python -c "import socket, sys; s = socket.socket(socket.AF_INET, socket.SOCK_STREAM); s.connect(('db', 3306)); sys.exit(0)" 2>/dev/null ; do + sleep 5 ; + echo -n "." +done +echo "." +echo "Database (http://db:3306) is up." + +moon_db_manager upgrade + +echo "Waiting for Keystone (http://keystone:5000)" +while ! python -c "import requests; req = requests.get('http://keystone:5000')" 2>/dev/null ; do + sleep 5 ; + echo -n "." +done +echo "." +echo "Keystone (http://keystone:5000) is up." + +echo "Waiting for Manager (http://manager:8082)" +while ! python -c "import requests; req = requests.get('http://manager:8082')" 2>/dev/null ; do + sleep 5 ; + echo -n "." +done +echo "." +echo "Manager (http://manager:8082) is up." |