~xianghui/charms/trusty/hacluster/support-ipv6

« back to all changes in this revision

Viewing changes to hooks/hooks.py

  • Committer: Hui Xiang
  • Date: 2014-08-19 07:06:29 UTC
  • Revision ID: hui.xiang@canonical.com-20140819070629-pheqt6jch26p84l5
Support hacluster for IPv6.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
import maas as MAAS
17
17
import pcmk
18
18
import hacluster
 
19
import random
19
20
 
20
21
from charmhelpers.core.hookenv import (
21
22
    log,
61
62
 
62
63
def get_corosync_conf():
63
64
    conf = {}
 
65
    if config('prefer-ipv6'):
 
66
        ip_version = 'ipv6'
 
67
        bindnetaddr = hacluster.get_ipv6_addr
 
68
    else:
 
69
        ip_version = 'ipv4'
 
70
        bindnetaddr = hacluster.get_network_address
 
71
 
64
72
    for relid in relation_ids('ha'):
65
73
        for unit in related_units(relid):
 
74
            bindiface = relation_get('corosync_bindiface',
 
75
                                     unit, relid)
 
76
            if bindiface is None:
 
77
                log('No corosync_bindiface is set yet.')
 
78
                continue
 
79
 
66
80
            conf = {
67
81
                'corosync_bindnetaddr':
68
 
                hacluster.get_network_address(
69
 
                    relation_get('corosync_bindiface',
70
 
                                 unit, relid)
71
 
                ),
 
82
                bindnetaddr(bindiface),
72
83
                'corosync_mcastport': relation_get('corosync_mcastport',
73
84
                                                   unit, relid),
74
85
                'corosync_mcastaddr': config('corosync_mcastaddr'),
 
86
                'ip_version': ip_version,
75
87
            }
 
88
 
 
89
            # nodeid = uuid.uuid4().int & (1<<64)-1
 
90
            # Note(xianghui): Need to find better way to avoid conflicts.
 
91
            if config('prefer-ipv6'):
 
92
                conf['nodeid'] = random.randint(1, 100)
 
93
 
76
94
            if None not in conf.itervalues():
77
95
                return conf
78
96
    missing = [k for k, v in conf.iteritems() if v is None]