blob: 5c3771f98edb7c1e65a560a690d98939b7e2dcc2 [file] [log] [blame]
Soren Hansenbc1d3a02011-09-08 13:33:17 +02001import ConfigParser
2
3
4class NovaConfig(object):
5 """Provides configuration information for connecting to Nova."""
6
7 def __init__(self, conf):
8 """Initialize a Nova-specific configuration object."""
9 self.conf = conf
10
11 def get(self, item_name, default_value):
12 try:
13 return self.conf.get("nova", item_name)
14 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
15 return default_value
16
17 @property
18 def host(self):
19 """Host for the Nova HTTP API. Defaults to 127.0.0.1."""
20 return self.get("host", "127.0.0.1")
21
22 @property
23 def port(self):
24 """Port for the Nova HTTP API. Defaults to 8774."""
25 return int(self.get("port", 8774))
26
27 @property
28 def username(self):
29 """Username to use for Nova API requests. Defaults to 'admin'."""
30 return self.get("user", "admin")
31
32 @property
33 def base_url(self):
34 """Base of the HTTP API URL. Defaults to '/v1.1'."""
35 return self.get("base_url", "/v1.1")
36
37 @property
38 def project_id(self):
39 """Base of the HTTP API URL. Defaults to '/v1.1'."""
40 return self.get("project_id", "admin")
41
42 @property
43 def api_key(self):
44 """API key to use when authenticating. Defaults to 'admin_key'."""
45 return self.get("api_key", "admin_key")
46
47 @property
48 def ssh_timeout(self):
49 """Timeout in seconds to use when connecting via ssh."""
50 return float(self.get("ssh_timeout", 300))
51
52 @property
53 def build_timeout(self):
54 """Timeout in seconds to use when connecting via ssh."""
55 return float(self.get("build_timeout", 300))
56
57
58
59class EnvironmentConfig(object):
60 def __init__(self, conf):
61 """Initialize a Environment-specific configuration object."""
62 self.conf = conf
63
64 def get(self, item_name, default_value):
65 try:
66 return self.conf.get("environment", item_name)
67 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
68 return default_value
69
70 @property
71 def image_ref(self):
72 """Valid imageRef to use """
73 return self.get("image_ref", 3);
74
75 @property
76 def image_ref_alt(self):
77 """Valid imageRef to rebuild images with"""
78 return self.get("image_ref_alt", 3);
79
80 @property
81 def flavor_ref(self):
82 """Valid flavorRef to use"""
83 return self.get("flavor_ref", 1);
84
85 @property
86 def flavor_ref_alt(self):
87 """Valid flavorRef to resize images with"""
88 return self.get("flavor_ref_alt", 2);
89
90 @property
91 def multi_node(self):
92 """ Does the test environment have more than one compute node """
93 return self.get("multi_node", 'false') != 'false'
94
95
96class StackConfig(object):
97 """Provides `kong` configuration information."""
98
99 _path = None
100
101 def __init__(self, path=None):
102 """Initialize a configuration from a path."""
103 self._path = path or self._path
104 self._conf = self.load_config(self._path)
105 self.nova = NovaConfig(self._conf)
106 self.env = EnvironmentConfig(self._conf)
107
108 def load_config(self, path=None):
109 """Read configuration from given path and return a config object."""
110 config = ConfigParser.SafeConfigParser()
111 config.read(path)
112 return config