1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
import os
from base64 import b64decode
from charmhelpers.core.hookenv import (
config,
local_unit,
log,
relation_get,
relation_ids,
related_units,
unit_get,
unit_private_ip,
ERROR,
)
class ComputeService(object):
def __init__(self):
self.config_dir = '/home/ubuntu/configs'
if not os.path.exists(self.config_dir):
os.mkdir(self.config_dir)
def neutron_context(self):
ctxt = {}
for rid in relation_ids('cloud-compute'):
for unit in related_units(rid):
rel = {'rid': rid, 'unit': unit}
ctxt = {
'auth_protocol': relation_get('auth_protocol', **rel) or 'http',
'service_protocol': relation_get('service_protocol', **rel) or 'http',
'neutron_auth_strategy': 'keystone',
'keystone_host': relation_get('auth_host', **rel),
'auth_port': relation_get('auth_port', **rel),
'neutron_admin_tenant_name': relation_get('service_tenant_name', **rel),
'neutron_admin_username': relation_get('service_username', **rel),
'neutron_admin_password': relation_get('service_password', **rel),
'neutron_plugin': 'neutron',
'neutron_url': relation_get('neutron_url', **rel),
}
ctxt['neutron_security_groups'] = _neutron_security_groups()
ks_url = '%s://%s:%s/v2.0' % (ctxt['auth_protocol'],
ctxt['keystone_host'],
ctxt['auth_port'])
ctxt['neutron_admin_auth_url'] = ks_url
return ctxt
def _neutron_security_groups():
for rid in relation_ids('cloud-compute'):
for unit in related_units(rid):
groups = [
relation_get('neutron_security_groups',
rid=rid, unit=unit),
relation_get('quantum_security_groups',
rid=rid, unit=unit),
]
if ('yes' in groups or 'Yes' in groups):
return True
return False
def get_context(self):
ctxt = {}
if config('instances_path') is not None:
ctxt['instances_path'] = config('instances_path')
ctxt['network_manager'] = self.neutron_context()
ctxt['network_manager_config'] = 'neutron'
ctxt['volume_service'] = 'cinder'
return ctxt
|