1 # Copyright 2017 Intel Research and Development Ireland Limited
2 # *************************************************************
4 # This file is part of OSM Monitoring module
5 # All Rights Reserved to Intel Corporation
7 # Licensed under the Apache License, Version 2.0 (the "License"); you may
8 # not use this file except in compliance with the License. You may obtain
9 # a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 # License for the specific language governing permissions and limitations
19 # For those usages not covered by the Apache License, Version 2.0 please
20 # contact: helena.mcgough@intel.com or adrian.hoban@intel.com
22 """Configurations for the OpenStack plugins."""
27 from collections
import namedtuple
29 from osm_mon
.plugins
.OpenStack
.singleton
import Singleton
33 __author__
= "Helena McGough"
35 log
= logging
.getLogger(__name__
)
38 class BadConfigError(Exception):
39 """Configuration exception."""
44 class CfgParam(namedtuple('CfgParam', ['key', 'default', 'data_type'])):
45 """Configuration parameter definition."""
47 def value(self
, data
):
48 """Convert a string to the parameter type."""
50 return self
.data_type(data
)
51 except (ValueError, TypeError):
53 'Invalid value "%s" for configuration parameter "%s"' % (
59 """Plugin confguration."""
62 CfgParam('OS_NOTIFIER_URI', "http://localhost:8662", six
.text_type
),
65 _config_dict
= {cfg
.key
: cfg
for cfg
in _configuration
}
66 _config_keys
= _config_dict
.keys()
69 """Set the default values."""
70 for cfg
in self
._configuration
:
71 setattr(self
, cfg
.key
, cfg
.default
)
73 def read_environ(self
):
74 """Check the appropriate environment variables and update defaults."""
75 for key
in self
._config
_keys
:
77 val
= str(os
.environ
[key
])
78 setattr(self
, key
, val
)
79 except KeyError as exc
:
80 log
.warn("Failed to configure plugin: %s", exc
)