1
from charmhelpers.contrib.openstack.neutron import neutron_plugin_attribute
2
from copy import deepcopy
3
from charmhelpers.core.hookenv import log
4
from charmhelpers.contrib.openstack import templating
5
from collections import OrderedDict
6
from charmhelpers.contrib.openstack.utils import (
13
#Dont need these right now
14
NOVA_CONF_DIR = "/etc/nova"
15
NEUTRON_CONF_DIR = "/etc/neutron"
16
NEUTRON_CONF = '%s/neutron.conf' % NEUTRON_CONF_DIR
17
NEUTRON_DEFAULT = '/etc/default/neutron-server'
20
P_PGKA_CONF = '/opt/pg/etc/puppet/modules/sal/templates/keepalived.conf.erb'
21
P_PG_CONF = '/opt/pg/etc/puppet/modules/plumgrid/templates/plumgrid.conf.erb'
22
P_PGDEF_CONF = '/opt/pg/etc/puppet/modules/sal/templates/default.conf.erb'
25
PGKA_CONF = '/var/lib/libvirt/filesystems/plumgrid/etc/keepalived/keepalived.conf'
26
PG_CONF = '/var/lib/libvirt/filesystems/plumgrid/opt/pg/etc/plumgrid.conf'
27
PGDEF_CONF = '/var/lib/libvirt/filesystems/plumgrid/opt/pg/sal/nginx/conf.d/default.conf'
28
PGHN_CONF = '/var/lib/libvirt/filesystems/plumgrid-data/conf/etc/hostname'
29
PGHS_CONF = '/var/lib/libvirt/filesystems/plumgrid-data/conf/etc/hosts'
30
PGIFCS_CONF = '/var/lib/libvirt/filesystems/plumgrid-data/conf/pg/ifcs.conf'
31
IFCTL_CONF = '/var/run/plumgrid/lxc/ifc_list_gateway'
32
IFCTL_P_CONF = '/var/lib/libvirt/filesystems/plumgrid/var/run/plumgrid/lxc/ifc_list_gateway'
34
BASE_RESOURCE_MAP = OrderedDict([
36
'services': ['plumgrid'],
37
'contexts': [pg_dir_context.PGDirContext()],
40
'services': ['plumgrid'],
41
'contexts': [pg_dir_context.PGDirContext()],
44
'services': ['plumgrid'],
45
'contexts': [pg_dir_context.PGDirContext()],
48
'services': ['plumgrid'],
49
'contexts': [pg_dir_context.PGDirContext()],
52
'services': ['plumgrid'],
53
'contexts': [pg_dir_context.PGDirContext()],
57
'contexts': [pg_dir_context.PGDirContext()],
60
TEMPLATES = 'templates/'
63
def determine_packages():
64
return neutron_plugin_attribute('plumgrid', 'packages', 'neutron')
67
def register_configs(release=None):
68
release = release or os_release('neutron-common', base='icehouse')
69
configs = templating.OSConfigRenderer(templates_dir=TEMPLATES,
70
openstack_release=release)
71
for cfg, rscs in resource_map().iteritems():
72
configs.register(cfg, rscs['contexts'])
78
Dynamically generate a map of resources that will be managed for a single
81
resource_map = deepcopy(BASE_RESOURCE_MAP)
87
Constructs a restart map based on charm config settings and relation
90
return {k: v['services'] for k, v in resource_map().iteritems()}
94
_exec_cmd(cmd=['cp', '--remove-destination', '-f', P_PGKA_CONF, PGKA_CONF])
95
_exec_cmd(cmd=['cp', '--remove-destination', '-f', P_PG_CONF, PG_CONF])
96
_exec_cmd(cmd=['cp', '--remove-destination', '-f', P_PGDEF_CONF, PGDEF_CONF])
97
_exec_cmd(cmd=['touch', PGIFCS_CONF])
98
_exec_cmd(cmd=['mkdir', '/etc/nova'])
99
_exec_cmd(cmd=['touch', 'neutron_plugin.conf'])
103
_exec_cmd(cmd=['virsh', '-c', 'lxc:', 'destroy', 'plumgrid'], error_msg='ERROR Destroying PLUMgrid')
104
_exec_cmd(cmd=['rm', IFCTL_CONF, IFCTL_P_CONF], error_msg='ERROR Removing ifc_ctl_gateway file')
105
_exec_cmd(cmd=['iptables', '-F'])
106
_exec_cmd(cmd=['virsh', '-c', 'lxc:', 'start', 'plumgrid'], error_msg='ERROR Starting PLUMgrid')
108
_exec_cmd(cmd=['service', 'plumgrid', 'start'], error_msg='ERROR starting PLUMgrid service')
113
_exec_cmd(cmd=['virsh', '-c', 'lxc:', 'destroy', 'plumgrid'], error_msg='ERROR Destroying PLUMgrid')
115
_exec_cmd(cmd=['rm', IFCTL_CONF, IFCTL_P_CONF], error_msg='ERROR Removing ifc_ctl_gateway file')
118
def _exec_cmd(cmd=None, error_msg='Command exited with ERRORs'):
123
subprocess.check_call(cmd)
124
except subprocess.CalledProcessError, e: