Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 1 | import ConfigParser |
| 2 | |
| 3 | |
| 4 | class NovaConfig(object): |
| 5 | """Provides configuration information for connecting to Nova.""" |
| 6 | |
| 7 | def __init__(self, conf): |
Daryl Walleck | e5b83d4 | 2011-11-10 14:39:02 -0600 | [diff] [blame] | 8 | """Initialize a Nova-specific configuration object""" |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 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 |
Rohit Karajgi | e1b050d | 2011-12-02 16:13:18 -0800 | [diff] [blame^] | 18 | 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 Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 40 | |
| 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 | |
| 72 | class 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 Walleck | adea1fa | 2011-11-15 18:36:39 -0600 | [diff] [blame] | 96 | return self.get("flavor_ref", 1) |
Daryl Walleck | 1465d61 | 2011-11-02 02:22:15 -0500 | [diff] [blame] | 97 | |
| 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 | |
| 119 | class 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 |