blob: 454f6849440fa3b55db65be643e59777ec411a24 [file] [log] [blame]
Daryl Walleck1465d612011-11-02 02:22:15 -05001import ConfigParser
2
3
4class NovaConfig(object):
5 """Provides configuration information for connecting to Nova."""
6
7 def __init__(self, conf):
Daryl Wallecke5b83d42011-11-10 14:39:02 -06008 """Initialize a Nova-specific configuration object"""
Daryl Walleck1465d612011-11-02 02:22:15 -05009 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
Rohit Karajgie1b050d2011-12-02 16:13:18 -080018 def host(self):
19 """Host IP for making Nova API requests. Defaults to '127.0.0.1'."""
20 return self.get("host", "127.0.1")
21
22 @property
23 def port(self):
24 """Listen port of the Nova service."""
25 return self.get("port", "8773")
26
27 @property
28 def apiVer(self):
29 """Version of the API"""
30 return self.get("apiVer", "v1.1")
31
32 @property
33 def path(self):
34 """Path of API request"""
35 return self.get("path", "/")
36
37 def params(self):
38 """Parameters to be passed with the API request"""
39 return self.get("params", "")
Daryl Walleck1465d612011-11-02 02:22:15 -050040
41 @property
42 def username(self):
43 """Username to use for Nova API requests. Defaults to 'admin'."""
44 return self.get("user", "admin")
45
46 @property
47 def tenant_name(self):
48 """Tenant name to use for Nova API requests. Defaults to 'admin'."""
49 return self.get("tenant_name", "admin")
50
51 @property
52 def api_key(self):
53 """API key to use when authenticating. Defaults to 'admin_key'."""
54 return self.get("api_key", "admin_key")
55
56 @property
57 def build_interval(self):
58 """Time in seconds between build status checks."""
59 return float(self.get("build_interval", 10))
60
61 @property
62 def ssh_timeout(self):
63 """Timeout in seconds to use when connecting via ssh."""
64 return float(self.get("ssh_timeout", 300))
65
66 @property
67 def build_timeout(self):
68 """Timeout in seconds to wait for an entity to build."""
69 return float(self.get("build_timeout", 300))
70
71
72class EnvironmentConfig(object):
73 def __init__(self, conf):
74 """Initialize a Environment-specific configuration object."""
75 self.conf = conf
76
77 def get(self, item_name, default_value):
78 try:
79 return self.conf.get("environment", item_name)
80 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
81 return default_value
82
83 @property
84 def image_ref(self):
85 """Valid imageRef to use """
86 return self.get("image_ref", 3)
87
88 @property
89 def image_ref_alt(self):
90 """Valid imageRef to rebuild images with"""
91 return self.get("image_ref_alt", 3)
92
93 @property
94 def flavor_ref(self):
95 """Valid flavorRef to use"""
Daryl Walleckadea1fa2011-11-15 18:36:39 -060096 return self.get("flavor_ref", 1)
Daryl Walleck1465d612011-11-02 02:22:15 -050097
98 @property
99 def flavor_ref_alt(self):
100 """Valid flavorRef to resize images with"""
101 return self.get("flavor_ref_alt", 2)
102
103 @property
104 def resize_available(self):
105 """ Does the test environment support resizing """
106 return self.get("resize_available", 'false') != 'false'
107
108 @property
109 def create_image_enabled(self):
110 """ Does the test environment support resizing """
111 return self.get("create_image_enabled", 'false') != 'false'
112
113 @property
114 def authentication(self):
115 """ What auth method does the environment use (basic|keystone) """
116 return self.get("authentication", 'keystone')
117
118
119class StormConfig(object):
120 """Provides OpenStack configuration information."""
121
122 _path = "etc/storm.conf"
123
124 def __init__(self, path=None):
125 """Initialize a configuration from a path."""
126 self._conf = self.load_config(self._path)
127 self.nova = NovaConfig(self._conf)
128 self.env = EnvironmentConfig(self._conf)
129
130 def load_config(self, path=None):
131 """Read configuration from given path and return a config object."""
132 config = ConfigParser.SafeConfigParser()
133 config.read(path)
134 return config