4dacef9d142392e4dec1ff08f80b35610a273ab3
1 """Configurations for the Aodh plugin."""
3 from __future__
import unicode_literals
5 from plugins
.Openstack
.singleton
import Singleton
7 from collections
import namedtuple
12 class BadConfigError(Exception):
13 """Configuration exception"""
17 class CfgParam(namedtuple('CfgParam', ['key', 'default', 'data_type'])):
18 """Configuration parameter definition"""
20 def value(self
, data
):
21 """Convert a string to the parameter type"""
24 return self
.data_type(data
)
25 except (ValueError, TypeError) as exc
:
27 'Invalid value "%s" for configuration parameter "%s"' % (
33 """Plugin confguration"""
36 CfgParam('OS_AUTH_URL', None, six
.text_type
),
37 CfgParam('OS_IDENTITY_API_VERSION', "3", six
.text_type
),
38 CfgParam('OS_USERNAME', "aodh", six
.text_type
),
39 CfgParam('OS_PASSWORD', "password", six
.text_type
),
40 CfgParam('OS_TENANT_NAME', "service", six
.text_type
),
43 _config_dict
= {cfg
.key
: cfg
for cfg
in _configuration
}
44 _config_keys
= _config_dict
.keys()
47 """Set the default values"""
48 for cfg
in self
._configuration
:
49 setattr(self
, cfg
.key
, cfg
.default
)
51 def read_environ(self
):
52 """Check the appropriate environment variables and update defaults."""
54 for key
in self
._config
_keys
:
55 if (key
== "OS_IDENTITY_API_VERSION" or key
== "OS_PASSWORD"):
56 val
= str(os
.environ
[key
])
57 setattr(self
, key
, val
)
58 elif (key
== "OS_AUTH_URL"):
59 val
= str(os
.environ
[key
]) + "/v3"
60 setattr(self
, key
, val
)
62 # TODO: Log errors and no config updates required