~niedbalski/charms/trusty/nova-compute/template-cleanup

« back to all changes in this revision

Viewing changes to hooks/nova_compute_utils.py

  • Committer: James Page
  • Date: 2014-04-16 08:26:38 UTC
  • mfrom: (51.3.32 nova-compute)
  • Revision ID: james.page@canonical.com-20140416082638-e2cld0wqyfqpamy0
[yolanda.robla,james-page,hazmat,ivoks,coreycb,r=james-page,t=*]

Support for Icehouse on 12.04 and 14.04
Support for Active/Active and SSL RabbitMQ
Support for SSL MySQL
Support for SSL endpoints
Support for PostgreSQL

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
from copy import deepcopy
6
6
from subprocess import check_call, check_output
7
7
 
8
 
from charmhelpers.fetch import apt_update, apt_install
9
 
from charmhelpers.core.host import mkdir
 
8
from charmhelpers.fetch import apt_update, apt_upgrade, apt_install
 
9
from charmhelpers.core.host import mkdir, service_restart
10
10
from charmhelpers.core.hookenv import (
11
11
    config,
12
12
    log,
43
43
    'genisoimage',  # was missing as a package dependency until raring.
44
44
]
45
45
 
 
46
NOVA_CONF_DIR = "/etc/nova"
46
47
QEMU_CONF = '/etc/libvirt/qemu.conf'
47
48
LIBVIRTD_CONF = '/etc/libvirt/libvirtd.conf'
48
49
LIBVIRT_BIN = '/etc/default/libvirt-bin'
49
 
NOVA_CONF = '/etc/nova/nova.conf'
 
50
NOVA_CONF = '%s/nova.conf' % NOVA_CONF_DIR
50
51
 
51
52
BASE_RESOURCE_MAP = {
52
53
    QEMU_CONF: {
63
64
    },
64
65
    NOVA_CONF: {
65
66
        'services': ['nova-compute'],
66
 
        'contexts': [context.AMQPContext(),
67
 
                     context.SharedDBContext(relation_prefix='nova'),
 
67
        'contexts': [context.AMQPContext(ssl_dir=NOVA_CONF_DIR),
 
68
                     context.SharedDBContext(
 
69
                         relation_prefix='nova', ssl_dir=NOVA_CONF_DIR),
 
70
                     context.PostgresqlDBContext(),
68
71
                     context.ImageServiceContext(),
69
72
                     context.OSConfigFlagContext(),
70
73
                     CloudComputeContext(),
90
93
    }
91
94
}
92
95
 
93
 
QUANTUM_CONF = '/etc/quantum/quantum.conf'
 
96
QUANTUM_CONF_DIR = "/etc/quantum"
 
97
QUANTUM_CONF = '%s/quantum.conf' % QUANTUM_CONF_DIR
94
98
 
95
99
QUANTUM_RESOURCES = {
96
100
    QUANTUM_CONF: {
97
101
        'services': [],
98
 
        'contexts': [context.AMQPContext(),
99
 
                     NeutronComputeContext(),
 
102
        'contexts': [NeutronComputeContext(),
 
103
                     context.AMQPContext(ssl_dir=QUANTUM_CONF_DIR),
100
104
                     context.SyslogContext()],
101
105
    }
102
106
}
103
107
 
104
 
NEUTRON_CONF = '/etc/neutron/neutron.conf'
 
108
NEUTRON_CONF_DIR = "/etc/neutron"
 
109
NEUTRON_CONF = '%s/neutron.conf' % NEUTRON_CONF_DIR
105
110
 
106
111
NEUTRON_RESOURCES = {
107
112
    NEUTRON_CONF: {
108
113
        'services': [],
109
 
        'contexts': [context.AMQPContext(),
110
 
                     NeutronComputeContext(),
 
114
        'contexts': [NeutronComputeContext(),
 
115
                     context.AMQPContext(ssl_dir=NEUTRON_CONF_DIR),
111
116
                     context.SyslogContext()],
112
117
    }
113
118
}
200
205
    return {k: v['services'] for k, v in resource_map().iteritems()}
201
206
 
202
207
 
 
208
def services():
 
209
    ''' Returns a list of services associate with this charm '''
 
210
    _services = []
 
211
    for v in restart_map().values():
 
212
        _services = _services + v
 
213
    return list(set(_services))
 
214
 
 
215
 
203
216
def register_configs():
204
217
    '''
205
218
    Returns an OSTemplateRenderer object with all required configs registered.
220
233
    if (net_manager in ['flatmanager', 'flatdhcpmanager'] and
221
234
            config('multi-host').lower() == 'yes'):
222
235
        packages.extend(['nova-api', 'nova-network'])
223
 
    elif net_manager == 'quantum':
 
236
    elif net_manager in ['quantum', 'neutron']:
224
237
        plugin = neutron_plugin()
225
 
        packages.extend(
226
 
            neutron_plugin_attribute(plugin, 'packages', net_manager))
 
238
        pkg_lists = neutron_plugin_attribute(plugin, 'packages', net_manager)
 
239
        for pkg_list in pkg_lists:
 
240
            packages.extend(pkg_list)
227
241
 
228
242
    if relation_ids('ceph'):
229
243
        packages.append('ceph-common')
346
360
        _hosts.write(b64decode(hosts))
347
361
 
348
362
 
349
 
def do_openstack_upgrade(configs):
 
363
def do_openstack_upgrade():
 
364
    # NOTE(jamespage) horrible hack to make utils forget a cached value
 
365
    import charmhelpers.contrib.openstack.utils as utils
 
366
    utils.os_rel = None
350
367
    new_src = config('openstack-origin')
351
368
    new_os_rel = get_os_codename_install_source(new_src)
352
369
    log('Performing OpenStack upgrade to %s.' % (new_os_rel))
353
370
 
354
371
    configure_installation_source(new_src)
355
 
    apt_update()
 
372
    apt_update(fatal=True)
356
373
 
357
374
    dpkg_opts = [
358
375
        '--option', 'Dpkg::Options::=--force-confnew',
359
376
        '--option', 'Dpkg::Options::=--force-confdef',
360
377
    ]
361
378
 
362
 
    apt_install(packages=determine_packages(), options=dpkg_opts, fatal=True)
 
379
    apt_upgrade(options=dpkg_opts, fatal=True, dist=True)
 
380
    apt_install(determine_packages(), fatal=True)
363
381
 
364
 
    # set CONFIGS to load templates from new release and regenerate config
365
 
    configs.set_release(openstack_release=new_os_rel)
 
382
    # Regenerate configs in full for new release
 
383
    configs = register_configs()
366
384
    configs.write_all()
 
385
    [service_restart(s) for s in services()]
 
386
    return configs
367
387
 
368
388
 
369
389
def import_keystone_ca_cert():