From 0581c1ed0320acd612dc38757744e8cc1212014b Mon Sep 17 00:00:00 2001 From: Tommy Carpenter Date: Fri, 11 Aug 2017 15:02:32 -0400 Subject: Intial commit of CBS to ONAP Change-Id: I2082544efc59476ac8de0dc39c899f968c3847bd Signed-off-by: Tommy Carpenter Issue-Id: DCAEGEN2-47 --- config_binding_service/__init__.py | 52 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 config_binding_service/__init__.py (limited to 'config_binding_service/__init__.py') diff --git a/config_binding_service/__init__.py b/config_binding_service/__init__.py new file mode 100644 index 0000000..51d3246 --- /dev/null +++ b/config_binding_service/__init__.py @@ -0,0 +1,52 @@ +# ============LICENSE_START======================================================= +# org.onap.dcae +# ================================================================================ +# Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +import os +import logging + +'''Configures the module root logger''' +root = logging.getLogger() +if root.handlers: + root.handlers.clear() +formatter = logging.Formatter('%(asctime)s | %(name)s | %(module)s | %(funcName)s | %(lineno)d | %(levelname)s | %(message)s') +handler = logging.StreamHandler() +handler.setFormatter(formatter) +root.addHandler(handler) +root.setLevel("DEBUG") + +class BadEnviornmentENVNotFound(Exception): + pass + +def get_logger(module=None): + '''Returns a module-specific logger or global logger if the module is None''' + return root if module is None else root.getChild(module) + +def get_consul_uri(): + """ + This method waterfalls reads an envioronmental variable called CONSUL_HOST + If that doesn't work, it raises an Exception + """ + if "CONSUL_HOST" in os.environ: + # WARNING! TODO! Currently the env file does not include the port. + # But some other people think that the port should be a part of that. + # For now, I'm hardcoding 8500 until this gets resolved. + return "http://{0}:{1}".format(os.environ["CONSUL_HOST"], 8500) + else: + raise BadEnviornmentENVNotFound("CONSUL_HOST") + -- cgit 1.2.3-korg