~james-page/charms/precise/cinder/pre-test

« back to all changes in this revision

Viewing changes to hooks/cinder_contexts.py

  • Committer: Adam Gandelman
  • Date: 2013-10-17 21:48:08 UTC
  • Revision ID: adamg@canonical.com-20131017214808-k52pya40bowxzg4i
Merging python-redux and havana work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from charmhelpers.core.hookenv import (
 
2
    config,
 
3
    relation_ids,
 
4
    service_name,
 
5
)
 
6
 
 
7
from charmhelpers.contrib.openstack.context import (
 
8
    OSContextGenerator,
 
9
    ApacheSSLContext as SSLContext,
 
10
)
 
11
 
 
12
from charmhelpers.contrib.hahelpers.cluster import (
 
13
    determine_api_port,
 
14
    determine_haproxy_port,
 
15
)
 
16
 
 
17
 
 
18
class ImageServiceContext(OSContextGenerator):
 
19
    interfaces = ['image-service']
 
20
 
 
21
    def __call__(self):
 
22
        if not relation_ids('image-service'):
 
23
            return {}
 
24
        return { 'glance_api_version': config('glance-api-version') }
 
25
 
 
26
 
 
27
class CephContext(OSContextGenerator):
 
28
    interfaces = ['ceph']
 
29
 
 
30
    def __call__(self):
 
31
        """
 
32
        Used to generate template context to be added to cinder.conf in the
 
33
        presence of a ceph relation.
 
34
        """
 
35
        if not relation_ids('ceph'):
 
36
            return {}
 
37
        service = service_name()
 
38
        return {
 
39
            'volume_driver': 'cinder.volume.driver.RBDDriver',
 
40
            # ensure_ceph_pool() creates pool based on service name.
 
41
            'rbd_pool': service,
 
42
            'rbd_user': service,
 
43
            'host': service,
 
44
        }
 
45
 
 
46
 
 
47
class HAProxyContext(OSContextGenerator):
 
48
    interfaces = ['ceph']
 
49
 
 
50
    def __call__(self):
 
51
        '''
 
52
        Extends the main charmhelpers HAProxyContext with a port mapping
 
53
        specific to this charm.
 
54
        Also used to extend cinder.conf context with correct api_listening_port
 
55
        '''
 
56
        haproxy_port = determine_haproxy_port(config('api-listening-port'))
 
57
        api_port = determine_api_port(config('api-listening-port'))
 
58
 
 
59
        ctxt = {
 
60
            'service_ports': {'cinder_api': [haproxy_port, api_port]},
 
61
            'osapi_volume_listen_port': api_port,
 
62
        }
 
63
        return ctxt
 
64
 
 
65
 
 
66
class ApacheSSLContext(SSLContext):
 
67
    interfaces = ['https']
 
68
    external_ports = [8776]
 
69
    service_namespace = 'cinder'
 
70
 
 
71
    def __call__(self):
 
72
        # late import to work around circular dependency
 
73
        from cinder_utils import service_enabled
 
74
        if not service_enabled('cinder-api'):
 
75
            return {}
 
76
        return super(ApacheSSLContext, self).__call__()