1
from collections import OrderedDict
2
from copy import deepcopy
5
from base64 import b64encode
6
from charmhelpers.contrib.openstack import context, templating
7
from charmhelpers.contrib.openstack.neutron import (
8
network_manager, neutron_plugin_attribute)
10
from charmhelpers.contrib.openstack.utils import (
14
from charmhelpers.core.hookenv import (
18
import neutron_api_context
20
TEMPLATES = 'templates/'
22
CLUSTER_RES = 'res_nova_vip'
24
# removed from original: charm-helper-sh
26
'python-keystoneclient',
36
'neutron-server': 9696,
39
NEUTRON_CONF_DIR = "/etc/neutron"
41
NEUTRON_CONF = '%s/neutron.conf' % NEUTRON_CONF_DIR
42
HAPROXY_CONF = '/etc/haproxy/haproxy.cfg'
43
APACHE_CONF = '/etc/apache2/sites-available/openstack_https_frontend'
44
APACHE_24_CONF = '/etc/apache2/sites-available/openstack_https_frontend.conf'
45
NEUTRON_DEFAULT = '/etc/default/neutron-server'
46
CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt'
48
BASE_RESOURCE_MAP = OrderedDict([
50
'services': ['neutron-server'],
51
'contexts': [context.AMQPContext(ssl_dir=NEUTRON_CONF_DIR),
52
context.SharedDBContext(
53
user=config('neutron-database-user'),
54
database=config('neutron-database'),
55
relation_prefix='neutron',
56
ssl_dir=NEUTRON_CONF_DIR),
57
neutron_api_context.NeutronPostgresqlDBContext(),
58
neutron_api_context.IdentityServiceContext(),
59
neutron_api_context.NeutronCCContext(),
60
context.SyslogContext()],
63
'services': ['neutron-server'],
64
'contexts': [neutron_api_context.NeutronCCContext()],
67
def api_port(service):
68
return API_PORTS[service]
70
def determine_endpoints(url):
71
'''Generates a dictionary containing all relevant endpoints to be
72
passed to keystone as relation settings.'''
73
region = config('region')
75
neutron_url = '%s:%s' % (url, api_port('neutron-server'))
78
'quantum_service': 'quantum',
79
'quantum_region': region,
80
'quantum_public_url': neutron_url,
81
'quantum_admin_url': neutron_url,
82
'quantum_internal_url': neutron_url,
89
def determine_packages():
90
# currently all packages match service names
91
packages = [] + BASE_PACKAGES
92
for v in resource_map().values():
93
packages.extend(v['services'])
94
pkgs = neutron_plugin_attribute(config('neutron-plugin'), 'server_packages',
97
return list(set(packages))
99
def determine_ports():
100
'''Assemble a list of API ports for services we are managing'''
102
for services in restart_map().values():
103
for service in services:
105
ports.append(API_PORTS[service])
108
return list(set(ports))
113
Dynamically generate a map of resources that will be managed for a single
116
resource_map = deepcopy(BASE_RESOURCE_MAP)
118
net_manager = network_manager()
120
# add neutron plugin requirements. nova-c-c only needs the neutron-server
121
# associated with configs, not the plugin agent.
122
plugin = config('neutron-plugin')
123
conf = neutron_plugin_attribute(plugin, 'config', net_manager)
124
ctxts = (neutron_plugin_attribute(plugin, 'contexts', net_manager)
126
services = neutron_plugin_attribute(plugin, 'server_services',
128
resource_map[conf] = {}
129
resource_map[conf]['services'] = services
130
resource_map[conf]['contexts'] = ctxts
131
resource_map[conf]['contexts'].append(
132
neutron_api_context.NeutronCCContext())
134
# update for postgres
135
resource_map[conf]['contexts'].append(
136
neutron_api_context.NeutronPostgresqlDBContext())
141
def register_configs(release=None):
142
release = release or os_release('nova-common')
143
configs = templating.OSConfigRenderer(templates_dir=TEMPLATES,
144
openstack_release=release)
145
for cfg, rscs in resource_map().iteritems():
146
configs.register(cfg, rscs['contexts'])
151
return OrderedDict([(cfg, v['services'])
152
for cfg, v in resource_map().iteritems()
155
def auth_token_config(setting):
157
Returns currently configured value for setting in api-paste.ini's
158
authtoken section, or None.
160
config = ConfigParser.RawConfigParser()
161
config.read('/etc/neutron/api-paste.ini')
163
value = config.get('filter:authtoken', setting)
166
if value.startswith('%'):
170
def keystone_ca_cert_b64():
171
'''Returns the local Keystone-provided CA cert if it exists, or None.'''
172
if not os.path.isfile(CA_CERT_PATH):
174
with open(CA_CERT_PATH) as _in:
175
return b64encode(_in.read())