X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=plugins%2FOpenStack%2Fsettings.py;h=d177dcf8ca97bde0e3b813425b3e7c95a44c03ee;hb=95b92b3dacfd93fa1649a5f87dafd2fa6553a086;hp=45620d9f7827ba2c4f7405bd32f9a73700d27559;hpb=478c3baf620e7803ff18f9a19a3fd95a31d6cf99;p=osm%2FMON.git diff --git a/plugins/OpenStack/settings.py b/plugins/OpenStack/settings.py index 45620d9..d177dcf 100644 --- a/plugins/OpenStack/settings.py +++ b/plugins/OpenStack/settings.py @@ -1,8 +1,28 @@ -"""Configurations for the Aodh plugin.""" +# Copyright 2017 Intel Research and Development Ireland Limited +# ************************************************************* -from __future__ import unicode_literals +# This file is part of OSM Monitoring module +# All Rights Reserved to Intel Corporation -import logging as log +# 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. + +# For those usages not covered by the Apache License, Version 2.0 please +# contact: helena.mcgough@intel.com or adrian.hoban@intel.com +## +"""Configurations for the OpenStack plugins.""" + +import logging +log = logging.getLogger(__name__) import os from collections import namedtuple @@ -11,6 +31,8 @@ from plugins.OpenStack.singleton import Singleton import six +__author__ = "Helena McGough" + class BadConfigError(Exception): """Configuration exception.""" @@ -54,15 +76,19 @@ class Config(object): def read_environ(self, service): """Check the appropriate environment variables and update defaults.""" for key in self._config_keys: - # Default username for a service is it's name - setattr(self, 'OS_USERNAME', service) - if (key == "OS_IDENTITY_API_VERSION" or key == "OS_PASSWORD"): - val = str(os.environ[key]) - setattr(self, key, val) - elif (key == "OS_AUTH_URL"): - val = str(os.environ[key]) + "/v3" - setattr(self, key, val) - else: - # TODO(mcgoughh): Log errors and no config updates required - log.warn("Configuration doesn't require updating") - return + try: + if (key == "OS_IDENTITY_API_VERSION" or key == "OS_PASSWORD"): + val = str(os.environ[key]) + setattr(self, key, val) + elif (key == "OS_AUTH_URL"): + val = str(os.environ[key]) + "/v3" + setattr(self, key, val) + else: + # Default username for a service is it's name + setattr(self, 'OS_USERNAME', service) + log.info("Configuration complete!") + return + except KeyError as exc: + log.warn("Falied to configure plugin: %s", exc) + log.warn("Try re-authenticating your OpenStack deployment.") + return