45620d9f7827ba2c4f7405bd32f9a73700d27559
1 """Configurations for the Aodh plugin."""
3 from __future__
import unicode_literals
8 from collections
import namedtuple
10 from plugins
.OpenStack
.singleton
import Singleton
15 class BadConfigError(Exception):
16 """Configuration exception."""
21 class CfgParam(namedtuple('CfgParam', ['key', 'default', 'data_type'])):
22 """Configuration parameter definition."""
24 def value(self
, data
):
25 """Convert a string to the parameter type."""
27 return self
.data_type(data
)
28 except (ValueError, TypeError):
30 'Invalid value "%s" for configuration parameter "%s"' % (
36 """Plugin confguration."""
39 CfgParam('OS_AUTH_URL', None, six
.text_type
),
40 CfgParam('OS_IDENTITY_API_VERSION', "3", six
.text_type
),
41 CfgParam('OS_USERNAME', None, six
.text_type
),
42 CfgParam('OS_PASSWORD', "password", six
.text_type
),
43 CfgParam('OS_TENANT_NAME', "service", six
.text_type
),
46 _config_dict
= {cfg
.key
: cfg
for cfg
in _configuration
}
47 _config_keys
= _config_dict
.keys()
50 """Set the default values."""
51 for cfg
in self
._configuration
:
52 setattr(self
, cfg
.key
, cfg
.default
)
54 def read_environ(self
, service
):
55 """Check the appropriate environment variables and update defaults."""
56 for key
in self
._config
_keys
:
57 # Default username for a service is it's name
58 setattr(self
, 'OS_USERNAME', service
)
59 if (key
== "OS_IDENTITY_API_VERSION" or key
== "OS_PASSWORD"):
60 val
= str(os
.environ
[key
])
61 setattr(self
, key
, val
)
62 elif (key
== "OS_AUTH_URL"):
63 val
= str(os
.environ
[key
]) + "/v3"
64 setattr(self
, key
, val
)
66 # TODO(mcgoughh): Log errors and no config updates required
67 log
.warn("Configuration doesn't require updating")