~ionutbalutoiu/charms/trusty/neutron-api/next

« back to all changes in this revision

Viewing changes to hooks/neutron_api_utils.py

  • Committer: James Page
  • Date: 2015-09-04 11:03:14 UTC
  • mfrom: (39.7.35 trunk)
  • Revision ID: james.page@ubuntu.com-20150904110314-1iym0vseisumy5d0
[project-calico,r=james-page] Add support for Calico plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
import os
5
5
import shutil
6
6
import subprocess
 
7
import glob
7
8
from base64 import b64encode
8
9
from charmhelpers.contrib.openstack import context, templating
9
10
from charmhelpers.contrib.openstack.neutron import (
38
39
)
39
40
 
40
41
from charmhelpers.core.host import (
 
42
    lsb_release,
41
43
    adduser,
42
44
    add_group,
43
45
    add_user_to_group,
44
46
    mkdir,
45
 
    lsb_release,
 
47
    service_stop,
 
48
    service_start,
46
49
    service_restart,
47
50
    write_file,
48
51
)
160
163
    return API_PORTS[service]
161
164
 
162
165
 
 
166
def additional_install_locations(plugin, source):
 
167
    '''
 
168
    Add any required additional package locations for the charm, based
 
169
    on the Neutron plugin being used. This will also force an immediate
 
170
    package upgrade.
 
171
    '''
 
172
    if plugin == 'Calico':
 
173
        if config('calico-origin'):
 
174
            calico_source = config('calico-origin')
 
175
        else:
 
176
            release = get_os_codename_install_source(source)
 
177
            calico_source = 'ppa:project-calico/%s' % release
 
178
 
 
179
        add_source(calico_source)
 
180
 
 
181
        apt_update()
 
182
        apt_upgrade()
 
183
 
 
184
 
 
185
def force_etcd_restart():
 
186
    '''
 
187
    If etcd has been reconfigured we need to force it to fully restart.
 
188
    This is necessary because etcd has some config flags that it ignores
 
189
    after the first time it starts, so we need to make it forget them.
 
190
    '''
 
191
    service_stop('etcd')
 
192
    for directory in glob.glob('/var/lib/etcd/*'):
 
193
        shutil.rmtree(directory)
 
194
    service_start('etcd')
 
195
 
 
196
 
163
197
def manage_plugin():
164
198
    return config('manage-neutron-plugin-legacy-mode')
165
199