~corey.bryant/charms/trusty/neutron-api/stuff

« back to all changes in this revision

Viewing changes to hooks/neutron_api_utils.py

  • Committer: Subbarayudu Mukkamala
  • Date: 2015-10-27 14:50:30 UTC
  • mfrom: (153 neutron-api-274709)
  • mto: This revision was merged to the branch mainline in revision 155.
  • Revision ID: smukkamala@nuagenetworks.net-20151027145030-3lr5cofupf4tond8
MergeĀ fromĀ lp:~openstack-charmers/charms/trusty/.../next/

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 (
19
20
    git_pip_venv_dir,
20
21
    git_yaml_value,
21
22
    configure_installation_source,
 
23
    set_os_workload_status,
22
24
)
23
25
 
24
26
from charmhelpers.contrib.python.packages import (
28
30
from charmhelpers.core.hookenv import (
29
31
    config,
30
32
    log,
 
33
    relation_ids,
 
34
    status_get,
31
35
)
32
36
 
33
37
from charmhelpers.fetch import (
38
42
)
39
43
 
40
44
from charmhelpers.core.host import (
 
45
    lsb_release,
41
46
    adduser,
42
47
    add_group,
43
48
    add_user_to_group,
44
49
    mkdir,
45
 
    lsb_release,
 
50
    service_stop,
 
51
    service_start,
46
52
    service_restart,
47
53
    write_file,
48
54
)
49
55
 
 
56
from charmhelpers.contrib.hahelpers.cluster import (
 
57
    get_hacluster_config,
 
58
)
 
59
 
 
60
 
50
61
from charmhelpers.core.templating import render
51
62
from charmhelpers.contrib.hahelpers.cluster import is_elected_leader
52
63
 
111
122
NEUTRON_CONF_DIR = "/etc/neutron"
112
123
 
113
124
NEUTRON_CONF = '%s/neutron.conf' % NEUTRON_CONF_DIR
 
125
NEUTRON_LBAAS_CONF = '%s/neutron_lbaas.conf' % NEUTRON_CONF_DIR
 
126
NEUTRON_VPNAAS_CONF = '%s/neutron_vpnaas.conf' % NEUTRON_CONF_DIR
114
127
HAPROXY_CONF = '/etc/haproxy/haproxy.cfg'
115
128
APACHE_CONF = '/etc/apache2/sites-available/openstack_https_frontend'
116
129
APACHE_24_CONF = '/etc/apache2/sites-available/openstack_https_frontend.conf'
155
168
    }),
156
169
])
157
170
 
 
171
# The interface is said to be satisfied if anyone of the interfaces in the
 
172
# list has a complete context.
 
173
REQUIRED_INTERFACES = {
 
174
    'database': ['shared-db', 'pgsql-db'],
 
175
    'messaging': ['amqp', 'zeromq-configuration'],
 
176
    'identity': ['identity-service'],
 
177
}
 
178
 
 
179
LIBERTY_RESOURCE_MAP = OrderedDict([
 
180
    (NEUTRON_LBAAS_CONF, {
 
181
        'services': ['neutron-server'],
 
182
        'contexts': [],
 
183
    }),
 
184
    (NEUTRON_VPNAAS_CONF, {
 
185
        'services': ['neutron-server'],
 
186
        'contexts': [],
 
187
    }),
 
188
])
 
189
 
158
190
 
159
191
def api_port(service):
160
192
    return API_PORTS[service]
161
193
 
162
194
 
 
195
def additional_install_locations(plugin, source):
 
196
    '''
 
197
    Add any required additional package locations for the charm, based
 
198
    on the Neutron plugin being used. This will also force an immediate
 
199
    package upgrade.
 
200
    '''
 
201
    if plugin == 'Calico':
 
202
        if config('calico-origin'):
 
203
            calico_source = config('calico-origin')
 
204
        else:
 
205
            release = get_os_codename_install_source(source)
 
206
            calico_source = 'ppa:project-calico/%s' % release
 
207
 
 
208
        add_source(calico_source)
 
209
 
 
210
        apt_update()
 
211
        apt_upgrade()
 
212
 
 
213
 
 
214
def force_etcd_restart():
 
215
    '''
 
216
    If etcd has been reconfigured we need to force it to fully restart.
 
217
    This is necessary because etcd has some config flags that it ignores
 
218
    after the first time it starts, so we need to make it forget them.
 
219
    '''
 
220
    service_stop('etcd')
 
221
    for directory in glob.glob('/var/lib/etcd/*'):
 
222
        shutil.rmtree(directory)
 
223
    service_start('etcd')
 
224
 
 
225
 
163
226
def manage_plugin():
164
227
    return config('manage-neutron-plugin-legacy-mode')
165
228
 
210
273
    return list(set(ports))
211
274
 
212
275
 
213
 
def resource_map():
 
276
def resource_map(release=None):
214
277
    '''
215
278
    Dynamically generate a map of resources that will be managed for a single
216
279
    hook execution.
217
280
    '''
 
281
    release = release or os_release('neutron-common')
 
282
 
218
283
    resource_map = deepcopy(BASE_RESOURCE_MAP)
 
284
    if release >= 'liberty':
 
285
        resource_map.update(LIBERTY_RESOURCE_MAP)
219
286
 
220
287
    if os.path.exists('/etc/apache2/conf-available'):
221
288
        resource_map.pop(APACHE_CONF)
251
318
 
252
319
 
253
320
def register_configs(release=None):
254
 
    release = release or os_release('neutron-server')
 
321
    release = release or os_release('neutron-common')
255
322
    configs = templating.OSConfigRenderer(templates_dir=TEMPLATES,
256
323
                                          openstack_release=release)
257
324
    for cfg, rscs in resource_map().iteritems():
289
356
 
290
357
    :param configs: The charms main OSConfigRenderer object.
291
358
    """
292
 
    cur_os_rel = os_release('neutron-server')
 
359
    cur_os_rel = os_release('neutron-common')
293
360
    new_src = config('openstack-origin')
294
361
    new_os_rel = get_os_codename_install_source(new_src)
295
362
 
396
463
        raise Exception("IPv6 is not supported in the charms for Ubuntu "
397
464
                        "versions less than Trusty 14.04")
398
465
 
399
 
    # NOTE(xianghui): Need to install haproxy(1.5.3) from trusty-backports
400
 
    # to support ipv6 address, so check is required to make sure not
401
 
    # breaking other versions, IPv6 only support for >= Trusty
402
 
    if ubuntu_rel == 'trusty':
403
 
        add_source('deb http://archive.ubuntu.com/ubuntu trusty-backports'
404
 
                   ' main')
 
466
    # Need haproxy >= 1.5.3 for ipv6 so for Trusty if we are <= Kilo we need to
 
467
    # use trusty-backports otherwise we can use the UCA.
 
468
    if ubuntu_rel == 'trusty' and os_release('neutron-server') < 'liberty':
 
469
        add_source('deb http://archive.ubuntu.com/ubuntu trusty-backports '
 
470
                   'main')
405
471
        apt_update()
406
472
        apt_install('haproxy/trusty-backports', fatal=True)
407
473
 
540
606
           neutron_api_context, perms=0o644)
541
607
 
542
608
    service_restart('neutron-server')
 
609
 
 
610
 
 
611
def check_optional_relations(configs):
 
612
    required_interfaces = {}
 
613
    if relation_ids('ha'):
 
614
        required_interfaces['ha'] = ['cluster']
 
615
        try:
 
616
            get_hacluster_config()
 
617
        except:
 
618
            return ('blocked',
 
619
                    'hacluster missing configuration: '
 
620
                    'vip, vip_iface, vip_cidr')
 
621
 
 
622
    if required_interfaces:
 
623
        set_os_workload_status(configs, required_interfaces)
 
624
        return status_get()
 
625
    else:
 
626
        return 'unknown', 'No optional relations'