X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=plugins%2FOpenStack%2Fsettings.py;h=e7b06e2e9713348aa95e3423b73a478302f2a20f;hb=1d3567053b868400b801c9758ab8d3bc69740d1a;hp=4dacef9d142392e4dec1ff08f80b35610a273ab3;hpb=f358b4fdd006b427e5b653d467c29ae37a47406e;p=osm%2FMON.git diff --git a/plugins/OpenStack/settings.py b/plugins/OpenStack/settings.py index 4dacef9..e7b06e2 100644 --- a/plugins/OpenStack/settings.py +++ b/plugins/OpenStack/settings.py @@ -1,28 +1,54 @@ -"""Configurations for the Aodh plugin.""" +# Copyright 2017 Intel Research and Development Ireland Limited +# ************************************************************* + +# This file is part of OSM Monitoring module +# All Rights Reserved to Intel Corporation + +# 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.""" from __future__ import unicode_literals -from plugins.Openstack.singleton import Singleton +import logging as log +import os from collections import namedtuple + +from plugins.OpenStack.singleton import Singleton + import six -import os + +__author__ = "Helena McGough" class BadConfigError(Exception): - """Configuration exception""" + """Configuration exception.""" + pass class CfgParam(namedtuple('CfgParam', ['key', 'default', 'data_type'])): - """Configuration parameter definition""" + """Configuration parameter definition.""" def value(self, data): - """Convert a string to the parameter type""" - + """Convert a string to the parameter type.""" try: return self.data_type(data) - except (ValueError, TypeError) as exc: + except (ValueError, TypeError): raise BadConfigError( 'Invalid value "%s" for configuration parameter "%s"' % ( data, self.key)) @@ -30,12 +56,12 @@ class CfgParam(namedtuple('CfgParam', ['key', 'default', 'data_type'])): @Singleton class Config(object): - """Plugin confguration""" + """Plugin confguration.""" _configuration = [ CfgParam('OS_AUTH_URL', None, six.text_type), CfgParam('OS_IDENTITY_API_VERSION', "3", six.text_type), - CfgParam('OS_USERNAME', "aodh", six.text_type), + CfgParam('OS_USERNAME', None, six.text_type), CfgParam('OS_PASSWORD', "password", six.text_type), CfgParam('OS_TENANT_NAME', "service", six.text_type), ] @@ -44,13 +70,12 @@ class Config(object): _config_keys = _config_dict.keys() def __init__(self): - """Set the default values""" + """Set the default values.""" for cfg in self._configuration: setattr(self, cfg.key, cfg.default) - def read_environ(self): + def read_environ(self, service): """Check the appropriate environment variables and update defaults.""" - for key in self._config_keys: if (key == "OS_IDENTITY_API_VERSION" or key == "OS_PASSWORD"): val = str(os.environ[key]) @@ -59,5 +84,7 @@ class Config(object): val = str(os.environ[key]) + "/v3" setattr(self, key, val) else: - # TODO: Log errors and no config updates required + # Default username for a service is it's name + setattr(self, 'OS_USERNAME', service) + log.info("Configuration complete!") return