From c233dc215cab776d3e7faf10cf1870fa84d24db5 Mon Sep 17 00:00:00 2001 From: termie Date: Thu, 12 Jan 2012 16:02:37 -0800 Subject: re-indent --- keystone/backends/sql/util.py | 14 ++--- keystone/backends/templated.py | 117 +++++++++++++++++++++-------------------- 2 files changed, 67 insertions(+), 64 deletions(-) diff --git a/keystone/backends/sql/util.py b/keystone/backends/sql/util.py index 498ee6c2..e96ac6c6 100644 --- a/keystone/backends/sql/util.py +++ b/keystone/backends/sql/util.py @@ -1,3 +1,5 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + import os from keystone import config @@ -8,9 +10,9 @@ CONF = config.CONF def setup_test_database(): - # TODO(termie): be smart about this - try: - os.unlink('bla.db') - except Exception: - pass - migration.db_sync() + # TODO(termie): be smart about this + try: + os.unlink('bla.db') + except Exception: + pass + migration.db_sync() diff --git a/keystone/backends/templated.py b/keystone/backends/templated.py index 989ee0f6..475f13da 100644 --- a/keystone/backends/templated.py +++ b/keystone/backends/templated.py @@ -1,3 +1,5 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + from keystone import config from keystone import logging from keystone.backends import kvs @@ -8,80 +10,79 @@ config.register_str('template_file', group='catalog') class TemplatedCatalog(kvs.KvsCatalog): - """A backend that generates endpoints for the Catalog based on templates. - - It is usually configured via config entries that look like: + """A backend that generates endpoints for the Catalog based on templates. - catalog.$REGION.$SERVICE.$key = $value + It is usually configured via config entries that look like: - and is stored in a similar looking hierarchy. Where a value can contain - values to be interpolated by standard python string interpolation that look - like (the % is replaced by a $ due to paste attmepting to interpolate on its - own: + catalog.$REGION.$SERVICE.$key = $value - http://localhost:$(public_port)s/ + and is stored in a similar looking hierarchy. Where a value can contain + values to be interpolated by standard python string interpolation that look + like (the % is replaced by a $ due to paste attmepting to interpolate on + its own: - When expanding the template it will pass in a dict made up of the conf - instance plus a few additional key-values, notably tenant_id and user_id. + http://localhost:$(public_port)s/ - It does not care what the keys and values are but it is worth noting that - keystone_compat will expect certain keys to be there so that it can munge - them into the output format keystone expects. These keys are: + When expanding the template it will pass in a dict made up of the conf + instance plus a few additional key-values, notably tenant_id and user_id. - name - the name of the service, most likely repeated for all services of - the same type, across regions. - adminURL - the url of the admin endpoint - publicURL - the url of the public endpoint - internalURL - the url of the internal endpoint + It does not care what the keys and values are but it is worth noting that + keystone_compat will expect certain keys to be there so that it can munge + them into the output format keystone expects. These keys are: - """ + name - the name of the service, most likely repeated for all services of + the same type, across regions. + adminURL - the url of the admin endpoint + publicURL - the url of the public endpoint + internalURL - the url of the internal endpoint - def __init__(self, templates=None): - if templates: - self.templates = templates - else: - self._load_templates(CONF.catalog.template_file) + """ - super(TemplatedCatalog, self).__init__() + def __init__(self, templates=None): + if templates: + self.templates = templates + else: + self._load_templates(CONF.catalog.template_file) + super(TemplatedCatalog, self).__init__() - def _load_templates(self, template_file): - o = {} - for line in open(template_file): - if ' = ' not in line: - continue + def _load_templates(self, template_file): + o = {} + for line in open(template_file): + if ' = ' not in line: + continue - k, v = line.strip().split(' = ') - if not k.startswith('catalog.'): - continue + k, v = line.strip().split(' = ') + if not k.startswith('catalog.'): + continue - parts = k.split('.') + parts = k.split('.') - region = parts[1] - # NOTE(termie): object-store insists on having a dash - service = parts[2].replace('_', '-') - key = parts[3] + region = parts[1] + # NOTE(termie): object-store insists on having a dash + service = parts[2].replace('_', '-') + key = parts[3] - region_ref = o.get(region, {}) - service_ref = region_ref.get(service, {}) - service_ref[key] = v + region_ref = o.get(region, {}) + service_ref = region_ref.get(service, {}) + service_ref[key] = v - region_ref[service] = service_ref - o[region] = region_ref + region_ref[service] = service_ref + o[region] = region_ref - self.templates = o + self.templates = o - def get_catalog(self, user_id, tenant_id, metadata=None): - d = dict(CONF.iteritems()) - d.update({'tenant_id': tenant_id, - 'user_id': user_id}) + def get_catalog(self, user_id, tenant_id, metadata=None): + d = dict(CONF.iteritems()) + d.update({'tenant_id': tenant_id, + 'user_id': user_id}) - o = {} - for region, region_ref in self.templates.iteritems(): - o[region] = {} - for service, service_ref in region_ref.iteritems(): - o[region][service] = {} - for k, v in service_ref.iteritems(): - v = v.replace('$(', '%(') - o[region][service][k] = v % d + o = {} + for region, region_ref in self.templates.iteritems(): + o[region] = {} + for service, service_ref in region_ref.iteritems(): + o[region][service] = {} + for k, v in service_ref.iteritems(): + v = v.replace('$(', '%(') + o[region][service][k] = v % d - return o + return o -- cgit