diff options
-rw-r--r-- | README.rst | 24 | ||||
-rw-r--r-- | os_client_config/config.py | 17 |
2 files changed, 41 insertions, 0 deletions
@@ -45,11 +45,13 @@ and without the OS prefix. So, username is set with `username`. Service specific settings, like the nova service type, are set with the default service type as a prefix. For instance, to set a special service_type for trove (because you're using Rackspace) set: + :: database_service_type: 'rax:database' An example config file is probably helpful: + :: clouds: @@ -90,6 +92,28 @@ the setting with the default service type. That might strike you funny when setting `service_type` and it does me too - but that's just the world we live in. +Cache Settings +-------------- + +Accessing a cloud is often expensive, so it's quite common to want to do some +client-side caching of those operations. To facilitate that, os-client-config +understands a simple set of cache control settings. + +:: + + cache: + path: ~/.cache/openstack + max_age: 300 + clouds: + mordred: + cloud: hp + username: mordred@inaugust.com + password: XXXXXXXXX + project_id: mordred@inaugust.com + region_name: region-b.geo-1 + dns_service_type: hpext:dns + + Usage ----- diff --git a/os_client_config/config.py b/os_client_config/config.py index ade9708..f92c790 100644 --- a/os_client_config/config.py +++ b/os_client_config/config.py @@ -28,6 +28,9 @@ CONFIG_HOME = os.path.join(os.path.expanduser( CONFIG_SEARCH_PATH = [os.getcwd(), CONFIG_HOME, '/etc/openstack'] CONFIG_FILES = [ os.path.join(d, 'clouds.yaml') for d in CONFIG_SEARCH_PATH] +CACHE_PATH = os.path.join(os.path.expanduser( + os.environ.get('XDG_CACHE_PATH', os.path.join('~', '.cache'))), + 'openstack') BOOL_KEYS = ('insecure', 'cache') REQUIRED_VALUES = ('auth_url', 'username', 'password', 'project_id') VENDOR_SEARCH_PATH = [os.getcwd(), CONFIG_HOME, '/etc/openstack'] @@ -70,6 +73,14 @@ class OpenStackConfig(object): self.cloud_config = dict( clouds=dict(openstack=dict(self.defaults))) + self._cache_max_age = 300 + self._cache_path = CACHE_PATH + if 'cache' in self.cloud_config: + self._cache_max_age = self.cloud_config['cache'].get( + 'max_age', self._cache_max_age) + self._cache_path = os.path.expanduser( + self.cloud_config['cache'].get('path', self._cache_path)) + def _load_config_file(self): for path in self._config_files: if os.path.exists(path): @@ -80,6 +91,12 @@ class OpenStackConfig(object): if os.path.exists(path): return yaml.load(open(path, 'r')) + def get_cache_max_age(self): + return self._cache_max_age + + def get_cache_path(self): + return self._cache_path + def _get_regions(self, cloud): try: return self.cloud_config['clouds'][cloud]['region_name'] |