summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2014-09-28 11:18:31 -0700
committerMonty Taylor <mordred@inaugust.com>2014-10-10 15:25:53 -0700
commitb1bb75a69b491b26048fd18c40a7ac87043ea93c (patch)
tree783260de0b77b0e7bc41559f1434c53f06249975
parent215425f421cb4b831f1a294d73a25a14f301c1f4 (diff)
downloados-client-config-b1bb75a69b491b26048fd18c40a7ac87043ea93c.tar.gz
Add cache control settings
Things need to do local caching, which means they need to control some settings about that. Add simple cache settings support. Change-Id: I7b56cc25ebe7a803816d95b79d0329f8e42025ba
-rw-r--r--README.rst24
-rw-r--r--os_client_config/config.py17
2 files changed, 41 insertions, 0 deletions
diff --git a/README.rst b/README.rst
index 33327e2..30819f3 100644
--- a/README.rst
+++ b/README.rst
@@ -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']