blob: 42b9894c49ae66290822667789797fe8f8e3fda1 [file] [log] [blame]
Daryl Walleck1465d612011-11-02 02:22:15 -05001import ConfigParser
Jay Pipes7f757632011-12-02 15:53:32 -05002import logging
3import os
4
5LOG = logging.getLogger(__name__)
Daryl Walleck1465d612011-11-02 02:22:15 -05006
7
8class NovaConfig(object):
9 """Provides configuration information for connecting to Nova."""
10
11 def __init__(self, conf):
Daryl Wallecke5b83d42011-11-10 14:39:02 -060012 """Initialize a Nova-specific configuration object"""
Daryl Walleck1465d612011-11-02 02:22:15 -050013 self.conf = conf
14
15 def get(self, item_name, default_value):
16 try:
17 return self.conf.get("nova", item_name)
18 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
19 return default_value
20
21 @property
Rohit Karajgie1b050d2011-12-02 16:13:18 -080022 def host(self):
23 """Host IP for making Nova API requests. Defaults to '127.0.0.1'."""
24 return self.get("host", "127.0.1")
25
26 @property
27 def port(self):
28 """Listen port of the Nova service."""
29 return self.get("port", "8773")
30
31 @property
32 def apiVer(self):
33 """Version of the API"""
34 return self.get("apiVer", "v1.1")
35
36 @property
37 def path(self):
38 """Path of API request"""
39 return self.get("path", "/")
40
41 def params(self):
42 """Parameters to be passed with the API request"""
43 return self.get("params", "")
Daryl Walleck1465d612011-11-02 02:22:15 -050044
45 @property
46 def username(self):
47 """Username to use for Nova API requests. Defaults to 'admin'."""
48 return self.get("user", "admin")
49
50 @property
51 def tenant_name(self):
52 """Tenant name to use for Nova API requests. Defaults to 'admin'."""
53 return self.get("tenant_name", "admin")
54
55 @property
56 def api_key(self):
57 """API key to use when authenticating. Defaults to 'admin_key'."""
58 return self.get("api_key", "admin_key")
59
60 @property
61 def build_interval(self):
62 """Time in seconds between build status checks."""
63 return float(self.get("build_interval", 10))
64
65 @property
66 def ssh_timeout(self):
67 """Timeout in seconds to use when connecting via ssh."""
68 return float(self.get("ssh_timeout", 300))
69
70 @property
71 def build_timeout(self):
72 """Timeout in seconds to wait for an entity to build."""
73 return float(self.get("build_timeout", 300))
74
75
76class EnvironmentConfig(object):
77 def __init__(self, conf):
78 """Initialize a Environment-specific configuration object."""
79 self.conf = conf
80
81 def get(self, item_name, default_value):
82 try:
83 return self.conf.get("environment", item_name)
84 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
85 return default_value
86
87 @property
88 def image_ref(self):
89 """Valid imageRef to use """
90 return self.get("image_ref", 3)
91
92 @property
93 def image_ref_alt(self):
94 """Valid imageRef to rebuild images with"""
95 return self.get("image_ref_alt", 3)
96
97 @property
98 def flavor_ref(self):
99 """Valid flavorRef to use"""
Daryl Walleckadea1fa2011-11-15 18:36:39 -0600100 return self.get("flavor_ref", 1)
Daryl Walleck1465d612011-11-02 02:22:15 -0500101
102 @property
103 def flavor_ref_alt(self):
104 """Valid flavorRef to resize images with"""
105 return self.get("flavor_ref_alt", 2)
106
107 @property
108 def resize_available(self):
109 """ Does the test environment support resizing """
110 return self.get("resize_available", 'false') != 'false'
111
112 @property
113 def create_image_enabled(self):
114 """ Does the test environment support resizing """
115 return self.get("create_image_enabled", 'false') != 'false'
116
117 @property
118 def authentication(self):
119 """ What auth method does the environment use (basic|keystone) """
120 return self.get("authentication", 'keystone')
121
122
123class StormConfig(object):
124 """Provides OpenStack configuration information."""
125
Jay Pipes7f757632011-12-02 15:53:32 -0500126 def __init__(self, conf_dir, conf_file):
127 """
128 Initialize a configuration from a conf directory and conf file.
Daryl Walleck1465d612011-11-02 02:22:15 -0500129
Jay Pipes7f757632011-12-02 15:53:32 -0500130 :param conf_dir: Directory to look for config files
131 :param conf_file: Name of config file to use
132 """
133 path = os.path.join(conf_dir, conf_file)
134
135 if not os.path.exists(path):
136 msg = "Config file %(path)s not found" % locals()
137 raise RuntimeError(msg)
138
139 self._conf = self.load_config(path)
Daryl Walleck1465d612011-11-02 02:22:15 -0500140 self.nova = NovaConfig(self._conf)
141 self.env = EnvironmentConfig(self._conf)
142
Jay Pipes7f757632011-12-02 15:53:32 -0500143 def load_config(self, path):
Daryl Walleck1465d612011-11-02 02:22:15 -0500144 """Read configuration from given path and return a config object."""
145 config = ConfigParser.SafeConfigParser()
146 config.read(path)
147 return config