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
This commit is contained in:
24
README.rst
24
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
|
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
|
default service type as a prefix. For instance, to set a special service_type
|
||||||
for trove (because you're using Rackspace) set:
|
for trove (because you're using Rackspace) set:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
database_service_type: 'rax:database'
|
database_service_type: 'rax:database'
|
||||||
|
|
||||||
An example config file is probably helpful:
|
An example config file is probably helpful:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
clouds:
|
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
|
setting `service_type` and it does me too - but that's just the world we live
|
||||||
in.
|
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
|
Usage
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ CONFIG_HOME = os.path.join(os.path.expanduser(
|
|||||||
CONFIG_SEARCH_PATH = [os.getcwd(), CONFIG_HOME, '/etc/openstack']
|
CONFIG_SEARCH_PATH = [os.getcwd(), CONFIG_HOME, '/etc/openstack']
|
||||||
CONFIG_FILES = [
|
CONFIG_FILES = [
|
||||||
os.path.join(d, 'clouds.yaml') for d in CONFIG_SEARCH_PATH]
|
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')
|
BOOL_KEYS = ('insecure', 'cache')
|
||||||
REQUIRED_VALUES = ('auth_url', 'username', 'password', 'project_id')
|
REQUIRED_VALUES = ('auth_url', 'username', 'password', 'project_id')
|
||||||
VENDOR_SEARCH_PATH = [os.getcwd(), CONFIG_HOME, '/etc/openstack']
|
VENDOR_SEARCH_PATH = [os.getcwd(), CONFIG_HOME, '/etc/openstack']
|
||||||
@@ -70,6 +73,14 @@ class OpenStackConfig(object):
|
|||||||
self.cloud_config = dict(
|
self.cloud_config = dict(
|
||||||
clouds=dict(openstack=dict(self.defaults)))
|
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):
|
def _load_config_file(self):
|
||||||
for path in self._config_files:
|
for path in self._config_files:
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
@@ -80,6 +91,12 @@ class OpenStackConfig(object):
|
|||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
return yaml.load(open(path, 'r'))
|
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):
|
def _get_regions(self, cloud):
|
||||||
try:
|
try:
|
||||||
return self.cloud_config['clouds'][cloud]['region_name']
|
return self.cloud_config['clouds'][cloud]['region_name']
|
||||||
|
|||||||
Reference in New Issue
Block a user