aboutsummaryrefslogtreecommitdiffstats
path: root/moonv4
diff options
context:
space:
mode:
authorasteroide <thomas.duval@orange.com>2017-07-25 17:48:35 +0200
committerasteroide <thomas.duval@orange.com>2017-07-25 17:48:35 +0200
commit8c643f53acb79153ab93b2e6fee8bad301af869f (patch)
treea4bfdedcbf420825ef12264d1d560b3ae58515bb /moonv4
parent62579d1acbef875159c953222a275033e51ec0cd (diff)
Update to get configuration from the consul
Change-Id: Ie9a2ac33807fe9f07b6d2d0d504a968b678401a2
Diffstat (limited to 'moonv4')
-rw-r--r--moonv4/moon_router/moon_router/api/route.py41
-rw-r--r--moonv4/moon_router/moon_router/messenger.py16
-rw-r--r--moonv4/moon_router/moon_router/server.py22
-rw-r--r--moonv4/moon_router/requirements.txt3
4 files changed, 50 insertions, 32 deletions
diff --git a/moonv4/moon_router/moon_router/api/route.py b/moonv4/moon_router/moon_router/api/route.py
index 1a102abf..c9cfb82a 100644
--- a/moonv4/moon_router/moon_router/api/route.py
+++ b/moonv4/moon_router/moon_router/api/route.py
@@ -9,11 +9,10 @@ import itertools
from uuid import uuid4
from oslo_log import log as logging
from moon_utilities.security_functions import call, notify
-from oslo_config import cfg
from moon_router.api.generic import Status, Logs
+from moon_utilities import configuration
-LOG = logging.getLogger(__name__)
-CONF = cfg.CONF
+LOG = logging.getLogger("moon.router.api.route")
API = {
"orchestrator": (
@@ -308,50 +307,55 @@ class Router(object):
__version__ = "0.1.0"
cache_requests = {}
+ slave_name = ""
def __init__(self, add_master_cnx):
- if CONF.slave.slave_name and add_master_cnx:
+ self.slave = configuration.get_configuration(configuration.SLAVE)["slave"]
+ try:
+ self.slave_name = self.slave['name']
+ except KeyError:
+ pass
+ if self.slave_name and add_master_cnx:
result = call('security_router', method="route",
ctx={
- "name": CONF.slave.slave_name,
- "description": CONF.slave.slave_name,
+ "name": self.slave_name,
+ "description": self.slave_name,
"call_master": True,
"method": "add_slave"}, args={})
if "result" in result and not result["result"]:
LOG.error("An error occurred when sending slave name {} {}".format(
- CONF.slave.slave_name, result
+ self.slave_name, result
))
self.slave_id = list(result['slaves'].keys())[0]
result = call('security_router', method="route",
ctx={
- "name": CONF.slave.slave_name,
- "description": CONF.slave.slave_name,
+ "name": self.slave_name,
+ "description": self.slave_name,
"call_master": True,
"method": "get_slaves"}, args={})
if "result" in result and not result["result"]:
LOG.error("An error occurred when receiving slave names {} {}".format(
- CONF.slave.slave_name, result
+ self.slave_name, result
))
LOG.info("SLAVES: {}".format(result))
def delete(self):
- if CONF.slave.slave_name and self.slave_id:
+ if self.slave_name and self.slave_id:
result = call('security_router', method="route",
ctx={
- "name": CONF.slave.slave_name,
- "description": CONF.slave.slave_name,
+ "name": self.slave_name,
+ "description": self.slave_name,
"call_master": True,
"method": "delete_slave",
"id": self.slave_id}, args={})
if "result" in result and not result["result"]:
LOG.error("An error occurred when sending slave name {} {}".format(
- CONF.slave.slave_name, result
+ self.slave_name, result
))
LOG.info("SLAVE CONNECTION ENDED!")
LOG.info(result)
- @staticmethod
- def check_pdp(ctx):
+ def check_pdp(self, ctx):
_ctx = copy.deepcopy(ctx)
keystone_id = _ctx.pop('id')
# LOG.info("_ctx {}".format(_ctx))
@@ -361,7 +365,7 @@ class Router(object):
return False
keystone_id_list = map(lambda x: x["keystone_project_id"], ext['pdps'].values())
if not ext['pdps'] or keystone_id not in keystone_id_list:
- if CONF.slave.slave_name:
+ if self.slave_name:
_ctx['call_master'] = True
# update from master if exist and test again
LOG.info("Need to update from master {}".format(keystone_id))
@@ -393,7 +397,7 @@ class Router(object):
def send_update(self, api, ctx={}, args={}):
# TODO (asteroide): add threads here
- if not CONF.slave.slave_name:
+ if not self.slave_name:
# Note (asteroide):
# if adding or setting an element: do nothing
# if updating or deleting an element: force deletion in the slave
@@ -416,6 +420,7 @@ class Router(object):
:param args: dictionary depending of the real destination
:return: dictionary depending of the real destination
"""
+ LOG.info("Get Route {} {}".format(ctx, args))
if ctx["method"] == "get_status":
return Status().get_status(ctx=ctx, args=args)
if ctx["method"] == "get_logs":
diff --git a/moonv4/moon_router/moon_router/messenger.py b/moonv4/moon_router/moon_router/messenger.py
index 46565c62..0a377678 100644
--- a/moonv4/moon_router/moon_router/messenger.py
+++ b/moonv4/moon_router/moon_router/messenger.py
@@ -10,8 +10,9 @@ from oslo_log import log as logging
from moon_router.api.generic import Status, Logs
from moon_router.api.route import Router
from moon_utilities.api import APIList
+from moon_utilities import configuration
-LOG = logging.getLogger(__name__)
+LOG = logging.getLogger("moon.router.messenger")
class Server:
@@ -19,9 +20,11 @@ class Server:
TOPIC = "security_router"
def __init__(self, add_master_cnx=False):
- if add_master_cnx and cfg.CONF.slave.master_url:
- self.transport = oslo_messaging.get_transport(cfg.CONF, cfg.CONF.slave.master_url)
- self.TOPIC = self.TOPIC + "_" + cfg.CONF.slave.slave_name
+ slave = configuration.get_configuration(configuration.SLAVE)["slave"]
+ cfg.CONF.transport_url = self.__get_transport_url()
+ if add_master_cnx and slave["master"]["url"]:
+ self.transport = oslo_messaging.get_transport(cfg.CONF, slave["master"]["url"])
+ self.TOPIC = self.TOPIC + "_" + slave["name"]
else:
self.transport = oslo_messaging.get_transport(cfg.CONF)
self.target = oslo_messaging.Target(topic=self.TOPIC, server='server1')
@@ -37,6 +40,11 @@ class Server:
access_policy=oslo_messaging.DefaultRPCAccessPolicy)
self.__is_alive = False
+ @staticmethod
+ def __get_transport_url():
+ messenger = configuration.get_configuration(configuration.MESSENGER)["messenger"]
+ return messenger['url']
+
def stop(self):
self.__is_alive = False
self.endpoints[-1].delete()
diff --git a/moonv4/moon_router/moon_router/server.py b/moonv4/moon_router/moon_router/server.py
index 40e2b945..1b2bddee 100644
--- a/moonv4/moon_router/moon_router/server.py
+++ b/moonv4/moon_router/moon_router/server.py
@@ -6,9 +6,8 @@
import os
import threading
import signal
-from oslo_config import cfg
from oslo_log import log as logging
-from moon_utilities import options # noqa
+from moon_utilities import configuration, exceptions
from moon_router.messenger import Server
@@ -21,9 +20,7 @@ class AsyncServer(threading.Thread):
def run(self):
self.server.run()
-LOG = logging.getLogger(__name__)
-CONF = cfg.CONF
-DOMAIN = "moon_router"
+LOG = logging.getLogger("moon.router")
__CWD__ = os.path.dirname(os.path.abspath(__file__))
@@ -37,20 +34,27 @@ def stop_thread():
def main():
global background_threads
- LOG.info("Starting server with IP {}".format(CONF.security_router.host))
+ configuration.init_logging()
+ try:
+ conf = configuration.get_configuration("components/router")
+ except exceptions.ConsulComponentNotFound:
+ conf = configuration.add_component("router", "router")
signal.signal(signal.SIGALRM, stop_thread)
signal.signal(signal.SIGTERM, stop_thread)
signal.signal(signal.SIGABRT, stop_thread)
background_master = None
- if CONF.slave.slave_name:
+ slave = configuration.get_configuration(configuration.SLAVE)["slave"]
+ if slave['name']:
background_master = AsyncServer(add_master_cnx=True)
background_threads.append(background_master)
background_slave = AsyncServer(add_master_cnx=False)
background_threads.append(background_slave)
- if CONF.slave.slave_name:
+ if slave['name']:
background_master.start()
+ LOG.info("Connecting to master...")
background_slave.start()
- if CONF.slave.slave_name:
+ LOG.info("Starting main server {}".format(conf["components/router"]["hostname"]))
+ if slave['name']:
background_master.join()
background_slave.join()
diff --git a/moonv4/moon_router/requirements.txt b/moonv4/moon_router/requirements.txt
index a919c625..9eb4e201 100644
--- a/moonv4/moon_router/requirements.txt
+++ b/moonv4/moon_router/requirements.txt
@@ -3,4 +3,5 @@ oslo.messaging
oslo.config
vine
oslo.log
-babel \ No newline at end of file
+babel
+moon_utilities \ No newline at end of file