~hopem/charms/trusty/swift-storage/lp1518975

« back to all changes in this revision

Viewing changes to lib/swift_storage_context.py

[hopem,r=james-page,gnuoy] Add support for settting swift-storage unit rsyncd acls.
Partially-Closes-Bug: 1427361

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
                out.write(_m.sub('RSYNC_ENABLE=true', default))
55
55
 
56
56
    def __call__(self):
 
57
        ctxt = {}
57
58
        if config('prefer-ipv6'):
58
 
            local_ip = '%s' % get_ipv6_addr()[0]
 
59
            ctxt['local_ip'] = '%s' % get_ipv6_addr()[0]
59
60
        else:
60
 
            local_ip = unit_private_ip()
 
61
            ctxt['local_ip'] = unit_private_ip()
 
62
 
 
63
        timestamps = []
 
64
        for rid in relation_ids('swift-storage'):
 
65
            for unit in related_units(rid):
 
66
                settings = relation_get(unit=unit, rid=rid)
 
67
                ts = settings.get('timestamp')
 
68
                allowed_hosts = settings.get('rsync_allowed_hosts')
 
69
                if allowed_hosts and ts:
 
70
                    if not timestamps or ts > max(timestamps):
 
71
                        ctxt['allowed_hosts'] = allowed_hosts
 
72
 
 
73
                    timestamps.append(ts)
61
74
 
62
75
        self.enable_rsyncd()
63
 
        return {
64
 
            'local_ip': local_ip
65
 
        }
 
76
        return ctxt
66
77
 
67
78
 
68
79
class SwiftStorageServerContext(OSContextGenerator):