~hopem/charms/trusty/swift-proxy/pki-token-support

« back to all changes in this revision

Viewing changes to hooks/swift_context.py

  • Committer: james.page at ubuntu
  • Date: 2014-10-01 21:24:05 UTC
  • mfrom: (56.2.26 ipv6)
  • Revision ID: james.page@ubuntu.com-20141001212405-sn3e62qfrxyvfn57
[xianghui,dosaboy,r=james-page,t=gema] Add IPv6 support using prefer-ipv6 flag

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
    determine_apache_port,
20
20
)
21
21
 
 
22
from charmhelpers.contrib.network.ip import (
 
23
    get_ipv6_addr
 
24
)
 
25
 
22
26
from charmhelpers.contrib.openstack.utils import get_host_ip
23
27
import subprocess
24
28
import os
116
120
        for relid in relation_ids('swift-storage'):
117
121
            for unit in related_units(relid):
118
122
                host = relation_get('private-address', unit, relid)
119
 
                allowed_hosts.append(get_host_ip(host))
 
123
                if config('prefer-ipv6'):
 
124
                    host_ip = get_ipv6_addr(exc_list=[config('vip')])[0]
 
125
                else:
 
126
                    host_ip = get_host_ip(host)
 
127
                allowed_hosts.append(host_ip)
120
128
 
121
129
        ctxt = {
122
130
            'www_dir': WWW_DIR,
134
142
        if workers == '0':
135
143
            import multiprocessing
136
144
            workers = multiprocessing.cpu_count()
 
145
        if config('prefer-ipv6'):
 
146
            proxy_ip = '[%s]' % get_ipv6_addr(exc_list=[config('vip')])[0]
 
147
            memcached_ip = 'ip6-localhost'
 
148
        else:
 
149
            proxy_ip = get_host_ip(unit_get('private-address'))
 
150
            memcached_ip = get_host_ip(unit_get('private-address'))
137
151
        ctxt = {
138
 
            'proxy_ip': get_host_ip(unit_get('private-address')),
 
152
            'proxy_ip': proxy_ip,
 
153
            'memcached_ip': memcached_ip,
139
154
            'bind_port': determine_api_port(bind_port),
140
155
            'workers': workers,
141
156
            'operator_roles': config('operator-roles'),
196
211
class MemcachedContext(OSContextGenerator):
197
212
 
198
213
    def __call__(self):
199
 
        ctxt = {
200
 
            'proxy_ip': get_host_ip(unit_get('private-address'))
201
 
        }
 
214
        ctxt = {}
 
215
        if config('prefer-ipv6'):
 
216
            ctxt['memcached_ip'] = 'ip6-localhost'
 
217
        else:
 
218
            ctxt['memcached_ip'] = get_host_ip(unit_get('private-address'))
202
219
        return ctxt
203
220
 
204
221
SWIFT_HASH_FILE = '/var/lib/juju/swift-hash-path.conf'