3
from charmhelpers.contrib.openstack import context
4
4
from charmhelpers.core.hookenv import config
5
from charmhelpers.contrib.openstack import context
5
from charmhelpers.core.host import pwgen
7
8
HEAT_PATH = '/var/lib/heat/'
10
class IdentityServiceContext(context.IdentityServiceContext):
11
def generate_ec2_tokens(host, port):
12
ec2_tokens = 'http://%s:%s/v2.0/ec2tokens' % (host, port)
16
class HeatIdentityServiceContext(context.IdentityServiceContext):
11
17
def __call__(self):
12
ctxt = super(IdentityServiceContext, self).__call__()
18
ctxt = super(HeatIdentityServiceContext, self).__call__()
16
22
# the ec2 api needs to know the location of the keystone ec2
17
23
# tokens endpoint, set in nova.conf
18
ec2_tokens = 'http://%s:%s/v2.0/ec2tokens' % (ctxt['service_host'],
24
ec2_tokens = generate_ec2_tokens(ctxt['service_host'],
20
26
ctxt['keystone_ec2_url'] = ec2_tokens
30
def get_encryption_key():
31
encryption_path = os.path.join(HEAT_PATH, 'encryption-key')
32
if os.path.isfile(encryption_path):
33
with open(encryption_path, 'r') as enc:
34
encryption = enc.read()
36
# create encryption key and store it
37
if not os.path.isdir(HEAT_PATH):
38
os.makedirs(HEAT_PATH)
39
encryption = config("encryption-key")
42
encryption = pwgen(16)
43
with open(encryption_path, 'w') as enc:
24
47
class EncryptionContext(context.OSContextGenerator):
25
49
def __call__(self):
28
52
# check if we have stored encryption key
29
encryption_path = os.path.join(HEAT_PATH, 'encryption-key')
30
if os.path.isfile(encryption_path):
31
with open(encryption_path, 'r') as enc:
32
encryption = enc.read()
34
# create encryption key and store it
35
if not os.path.isdir(HEAT_PATH):
36
os.makedirs(HEAT_PATH)
37
encryption = config("encryption-key")
40
cmd = 'hexdump -n 16 -v -e \'/1 "%02x"\' /dev/random'
41
encryption = subprocess.check_output(cmd, shell=True).strip()
42
with open(encryption_path, 'w') as enc:
53
encryption = get_encryption_key()
45
54
ctxt['encryption_key'] = encryption