~openstack-charmers/charms/precise/swift-proxy/old-1410

« back to all changes in this revision

Viewing changes to hooks/swift_context.py

  • Committer: Edward Hope-Morley
  • Date: 2014-10-17 18:36:18 UTC
  • mfrom: (61.1.1 swift-proxy)
  • Revision ID: edward.hope-morley@canonical.com-20141017183618-k6q3th2wrtmgumxo
[jjo,r=hopem]

If a hash is not provided when deploying swift-proxy,
each unit will create it's own. This patch builds default
swift_hash from $JUJU_ENV_UUID and service_name (unless
one is provided in config)

Closes-Bug: 1337765

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
    relation_ids,
5
5
    related_units,
6
6
    relation_get,
7
 
    unit_get
 
7
    unit_get,
 
8
    service_name
8
9
)
9
10
 
10
11
from charmhelpers.contrib.openstack.context import (
23
24
)
24
25
 
25
26
from charmhelpers.contrib.openstack.utils import get_host_ip
26
 
import subprocess
27
27
import os
 
28
import uuid
28
29
 
29
30
 
30
31
class HAProxyContext(OSContextGenerator):
171
172
        with open(SWIFT_HASH_FILE, 'w') as hashfile:
172
173
            hashfile.write(swift_hash)
173
174
    else:
174
 
        cmd = ['od', '-t', 'x8', '-N', '8', '-A', 'n']
175
 
        rand = open('/dev/random', 'r')
176
 
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=rand)
177
 
        swift_hash = p.communicate()[0].strip()
 
175
        swift_hash = str(uuid.uuid3(uuid.UUID(os.environ.get("JUJU_ENV_UUID")),
 
176
                                    service_name()))
178
177
        with open(SWIFT_HASH_FILE, 'w') as hashfile:
179
178
            hashfile.write(swift_hash)
180
179
    return swift_hash