~junaidali/charms/trusty/plumgrid-director/pg-restart

« back to all changes in this revision

Viewing changes to hooks/pg_dir_context.py

  • Committer: bbaqar at plumgrid
  • Date: 2015-07-29 18:07:31 UTC
  • Revision ID: bbaqar@plumgrid.com-20150729180731-ioynar8x3u5pxytc
Addressed reviews by Charmers

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2015, PLUMgrid Inc, http://plumgrid.com
 
2
 
 
3
# This file contains the class that generates context for PLUMgrid template files.
 
4
 
1
5
from charmhelpers.core.hookenv import (
2
6
    config,
3
7
    unit_get,
9
13
import re
10
14
from socket import gethostname as get_unit_hostname
11
15
 
12
 
'''
13
 
def _neutron_api_settings():
14
 
    neutron_settings = {
15
 
        'neutron_security_groups': False,
16
 
        'l2_population': True,
17
 
        'overlay_network_type': 'gre',
18
 
    }
19
 
    for rid in relation_ids('neutron-plugin-api'):
20
 
        for unit in related_units(rid):
21
 
            rdata = relation_get(rid=rid, unit=unit)
22
 
            if 'l2-population' not in rdata:
23
 
                continue
24
 
            neutron_settings = {
25
 
                'l2_population': rdata['l2-population'],
26
 
                'neutron_security_groups': rdata['neutron-security-groups'],
27
 
                'overlay_network_type': rdata['overlay-network-type'],
28
 
            }
29
 
            # Override with configuration if set to true
30
 
            if config('disable-security-groups'):
31
 
                neutron_settings['neutron_security_groups'] = False
32
 
            return neutron_settings
33
 
    return neutron_settings
34
 
'''
35
 
 
36
16
 
37
17
class PGDirContext(context.NeutronContext):
38
 
    interfaces = []
39
18
 
40
19
    @property
41
20
    def plugin(self):
 
21
        '''
 
22
        Over-riding function in NeutronContext Class to return 'plumgrid'
 
23
        as the neutron plugin.
 
24
        '''
42
25
        return 'plumgrid'
43
26
 
44
27
    @property
45
28
    def network_manager(self):
 
29
        '''
 
30
        Over-riding function in NeutronContext Class to return 'neutron'
 
31
        as the network manager.
 
32
        '''
46
33
        return 'neutron'
47
34
 
48
35
    def _save_flag_file(self):
 
36
        '''
 
37
        Over-riding function in NeutronContext Class.
 
38
        Function only needed for OVS.
 
39
        '''
49
40
        pass
50
41
 
51
 
    #@property
52
 
    #def neutron_security_groups(self):
53
 
    #    neutron_api_settings = _neutron_api_settings()
54
 
    #    return neutron_api_settings['neutron_security_groups']
55
 
 
56
42
    def pg_ctxt(self):
57
 
        #Generated Config for all Plumgrid templates inside
58
 
        #the templates folder
 
43
        '''
 
44
        Generated Config for all PLUMgrid templates inside the templates folder.
 
45
        '''
59
46
        pg_ctxt = super(PGDirContext, self).pg_ctxt()
60
47
        if not pg_ctxt:
61
48
            return {}
64
51
        pg_ctxt['local_ip'] = \
65
52
            get_address_in_network(network=None,
66
53
                                   fallback=get_host_ip(unit_get('private-address')))
67
 
        #neutron_api_settings = _neutron_api_settings()
68
 
 
69
 
        #TODO: Get this value from the neutron-api charm
70
54
        pg_ctxt['virtual_ip'] = conf['plumgrid-virtual-ip']
71
55
        pg_ctxt['pg_hostname'] = "pg-director"
72
56
        pg_ctxt['interface'] = "juju-br0"