~billy-olsen/charms/trusty/cinder/rich-endpoint-overrides

« back to all changes in this revision

Viewing changes to hooks/cinder_hooks.py

  • Committer: billy.olsen at canonical
  • Date: 2015-11-16 23:41:04 UTC
  • Revision ID: billy.olsen@canonical.com-20151116234104-nithn0qur45spkte
Allow the os-public-hostname to specify a URL in addition to a
hostname in order to allow advanced mapping of the public endpoints
for gateway type services.

This allows multiple variables to be inserted into the hostname/url
in order to allow such reverse mapping to be done. The following
variables are replaced within the hostname/url:

  port - the service port
  address - the public hostname/address
  service_name - the name of the service
  path - the path of the service-defined endpoint path
  scheme - the uri scheme/protocol (e.g. http, https)

Allowing for advanced hostname specifications such as:

  https://${service_name}.example.net:${port}/${path}

In this form, 2 endpoints will be registered:

  https://cinder.example.net:8776/v1/$(tenant_id)s
  https://cinder.example.net:8776/v2/$(tenant_id)s

Show diffs side-by-side

added added

removed removed

Lines of Context:
92
92
)
93
93
from charmhelpers.contrib.openstack.ip import (
94
94
    canonical_url,
 
95
    Endpoints,
95
96
    PUBLIC, INTERNAL, ADMIN
96
97
)
97
98
from charmhelpers.contrib.openstack.context import ADDRESS_TYPES
270
271
 
271
272
@hooks.hook('identity-service-relation-joined')
272
273
def identity_joined(rid=None):
273
 
    public_url = '{}:{}/v1/$(tenant_id)s'.format(
274
 
        canonical_url(CONFIGS, PUBLIC),
275
 
        config('api-listening-port')
276
 
    )
277
 
    internal_url = '{}:{}/v1/$(tenant_id)s'.format(
278
 
        canonical_url(CONFIGS, INTERNAL),
279
 
        config('api-listening-port')
280
 
    )
281
 
    admin_url = '{}:{}/v1/$(tenant_id)s'.format(
282
 
        canonical_url(CONFIGS, ADMIN),
283
 
        config('api-listening-port')
284
 
    )
 
274
    v1_template = '${scheme}://${address}:${port}/v1/$(tenant_id)s'
 
275
    v1_endpoints = Endpoints(v1_template, configs=CONFIGS)
285
276
    settings = {
286
277
        'region': None,
287
278
        'service': None,
290
281
        'admin_url': None,
291
282
        'cinder_region': config('region'),
292
283
        'cinder_service': 'cinder',
293
 
        'cinder_public_url': public_url,
294
 
        'cinder_internal_url': internal_url,
295
 
        'cinder_admin_url': admin_url,
 
284
        'cinder_public_url': v1_endpoints.public(),
 
285
        'cinder_internal_url': v1_endpoints.internal(),
 
286
        'cinder_admin_url': v1_endpoints.admin(),
296
287
    }
297
288
    if os_release('cinder-common') >= 'icehouse':
298
289
        # NOTE(jamespage) register v2 endpoint as well
299
 
        public_url = '{}:{}/v2/$(tenant_id)s'.format(
300
 
            canonical_url(CONFIGS, PUBLIC),
301
 
            config('api-listening-port')
302
 
        )
303
 
        internal_url = '{}:{}/v2/$(tenant_id)s'.format(
304
 
            canonical_url(CONFIGS, INTERNAL),
305
 
            config('api-listening-port')
306
 
        )
307
 
        admin_url = '{}:{}/v2/$(tenant_id)s'.format(
308
 
            canonical_url(CONFIGS, ADMIN),
309
 
            config('api-listening-port')
310
 
        )
 
290
        v2_template = '${scheme}://${address}:${port}/v2/$(tenant_id)s'
 
291
        v2_endpoints = Endpoints(v2_template, configs=CONFIGS)
311
292
        settings.update({
312
293
            'cinderv2_region': config('region'),
313
294
            'cinderv2_service': 'cinderv2',
314
 
            'cinderv2_public_url': public_url,
315
 
            'cinderv2_internal_url': internal_url,
316
 
            'cinderv2_admin_url': admin_url,
 
295
            'cinderv2_public_url': v2_endpoints.public(),
 
296
            'cinderv2_internal_url': v2_endpoints.internal(),
 
297
            'cinderv2_admin_url': v2_endpoints.admin(),
317
298
        })
318
299
    relation_set(relation_id=rid, **settings)
319
300