[jjo] build default swift_hash from $JUJU_ENV_UUID and service_name

This commit is contained in:
JuanJo Ciarlante
2014-10-06 11:12:52 -03:00
parent 741379b087
commit 0bd79cabc4

View File

@@ -4,7 +4,8 @@ from charmhelpers.core.hookenv import (
relation_ids, relation_ids,
related_units, related_units,
relation_get, relation_get,
unit_get unit_get,
service_name
) )
from charmhelpers.contrib.openstack.context import ( from charmhelpers.contrib.openstack.context import (
@@ -26,6 +27,7 @@ from charmhelpers.contrib.network.ip import (
from charmhelpers.contrib.openstack.utils import get_host_ip from charmhelpers.contrib.openstack.utils import get_host_ip
import subprocess import subprocess
import os import os
import uuid
from charmhelpers.contrib.hahelpers.apache import ( from charmhelpers.contrib.hahelpers.apache import (
@@ -230,10 +232,8 @@ def get_swift_hash():
with open(SWIFT_HASH_FILE, 'w') as hashfile: with open(SWIFT_HASH_FILE, 'w') as hashfile:
hashfile.write(swift_hash) hashfile.write(swift_hash)
else: else:
cmd = ['od', '-t', 'x8', '-N', '8', '-A', 'n'] swift_hash = str(uuid.uuid3(uuid.UUID(os.environ.get("JUJU_ENV_UUID")),
rand = open('/dev/random', 'r') service_name()))
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=rand)
swift_hash = p.communicate()[0].strip()
with open(SWIFT_HASH_FILE, 'w') as hashfile: with open(SWIFT_HASH_FILE, 'w') as hashfile:
hashfile.write(swift_hash) hashfile.write(swift_hash)
return swift_hash return swift_hash