~hopem/charms/trusty/nova-cloud-controller/next.lp1273022

« back to all changes in this revision

Viewing changes to hooks/nova_cc_context.py

  • Committer: james.page at ubuntu
  • Date: 2014-06-24 11:43:28 UTC
  • mfrom: (78.2.7 nova-cloud-controller)
  • Revision ID: james.page@ubuntu.com-20140624114328-6wgs55qr9qn0oldq
[gnuoy,r=james-page] Refactoring to support split-out of Neutron functionality.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
from charmhelpers.core.hookenv import (
3
3
    config, relation_ids, relation_set, log, ERROR,
4
 
    unit_get)
 
4
    unit_get, related_units, relation_get)
5
5
 
6
6
from charmhelpers.fetch import apt_install, filter_installed_packages
7
7
from charmhelpers.contrib.openstack import context, neutron, utils
14
14
)
15
15
 
16
16
 
 
17
def context_complete(ctxt):
 
18
    _missing = []
 
19
    for k, v in ctxt.iteritems():
 
20
        if v is None or v == '':
 
21
            _missing.append(k)
 
22
    if _missing:
 
23
        log('Missing required data: %s' % ' '.join(_missing), level='INFO')
 
24
        return False
 
25
    return True
 
26
 
 
27
 
17
28
class ApacheSSLContext(context.ApacheSSLContext):
18
29
 
19
30
    interfaces = ['https']
27
38
        return super(ApacheSSLContext, self).__call__()
28
39
 
29
40
 
 
41
class NeutronAPIContext(context.OSContextGenerator):
 
42
    def __call__(self):
 
43
        log('Generating template context from neutron api relation')
 
44
        ctxt = {}
 
45
        for rid in relation_ids('neutron-api'):
 
46
            for unit in related_units(rid):
 
47
                rdata = relation_get(rid=rid, unit=unit)
 
48
                ctxt = {
 
49
                    'neutron_url': rdata.get('neutron-url'),
 
50
                    'neutron_plugin': rdata.get('neutron-plugin'),
 
51
                    'neutron_security_groups':
 
52
                    rdata.get('neutron-security-groups'),
 
53
                    'network_manager': 'neutron',
 
54
                }
 
55
                if context_complete(ctxt):
 
56
                    return ctxt
 
57
        return {}
 
58
 
 
59
 
30
60
class VolumeServiceContext(context.OSContextGenerator):
31
61
    interfaces = []
32
62