~bbaqar/charms/trusty/plumgrid-edge/charmstore

« back to all changes in this revision

Viewing changes to hooks/pg_edge_context.py

  • Committer: bbaqar at plumgrid
  • Date: 2015-05-19 21:06:18 UTC
  • Revision ID: bbaqar@plumgrid.com-20150519210618-lfe60xds38e9fyy8
PLUMgrid edge initial charm

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from charmhelpers.core.hookenv import (
 
2
    relation_ids,
 
3
    related_units,
 
4
    relation_get,
 
5
)
 
6
from charmhelpers.contrib.openstack import context
 
7
 
 
8
from socket import gethostname as get_unit_hostname
 
9
 
 
10
'''
 
11
#This function will be used to get information from neutron-api
 
12
def _neutron_api_settings():
 
13
    neutron_settings = {
 
14
        'neutron_security_groups': False,
 
15
        'l2_population': True,
 
16
        'overlay_network_type': 'gre',
 
17
    }
 
18
    for rid in relation_ids('neutron-plugin-api'):
 
19
        for unit in related_units(rid):
 
20
            rdata = relation_get(rid=rid, unit=unit)
 
21
            if 'l2-population' not in rdata:
 
22
                continue
 
23
            neutron_settings = {
 
24
                'l2_population': rdata['l2-population'],
 
25
                'neutron_security_groups': rdata['neutron-security-groups'],
 
26
                'overlay_network_type': rdata['overlay-network-type'],
 
27
            }
 
28
            # Override with configuration if set to true
 
29
            if config('disable-security-groups'):
 
30
                neutron_settings['neutron_security_groups'] = False
 
31
            return neutron_settings
 
32
    return neutron_settings
 
33
'''
 
34
 
 
35
 
 
36
#Use this function to get information from the director
 
37
def _pg_dir_settings():
 
38
    '''
 
39
    Inspects current plumgrid relation
 
40
    '''
 
41
    pg_settings = {
 
42
        'pg_dir_ip': '192.168.100.201',
 
43
    }
 
44
    for rid in relation_ids('plumgrid'):
 
45
        for unit in related_units(rid):
 
46
            rdata = relation_get(rid=rid, unit=unit)
 
47
            pg_settings = {
 
48
                'pg_dir_ip': rdata['private-address'],
 
49
            }
 
50
    return pg_settings
 
51
 
 
52
 
 
53
class PGEdgeContext(context.NeutronContext):
 
54
    interfaces = []
 
55
 
 
56
    @property
 
57
    def plugin(self):
 
58
        return 'plumgrid'
 
59
 
 
60
    @property
 
61
    def network_manager(self):
 
62
        return 'neutron'
 
63
 
 
64
    def _save_flag_file(self):
 
65
        pass
 
66
 
 
67
    #@property
 
68
    #def neutron_security_groups(self):
 
69
    #    neutron_api_settings = _neutron_api_settings()
 
70
    #    return neutron_api_settings['neutron_security_groups']
 
71
 
 
72
    def pg_ctxt(self):
 
73
        #Generated Config for all Plumgrid templates inside
 
74
        #the templates folder
 
75
        pg_ctxt = super(PGEdgeContext, self).pg_ctxt()
 
76
        if not pg_ctxt:
 
77
            return {}
 
78
 
 
79
        #conf = config()
 
80
        pg_dir_settings = _pg_dir_settings()
 
81
        pg_ctxt['local_ip'] = pg_dir_settings['pg_dir_ip']
 
82
        #neutron_api_settings = _neutron_api_settings()
 
83
        pg_ctxt['pg_hostname'] = "pg-edge"
 
84
        pg_ctxt['interface'] = "juju-br0"
 
85
        pg_ctxt['label'] = get_unit_hostname()
 
86
        pg_ctxt['fabric_mode'] = 'host'
 
87
 
 
88
        return pg_ctxt