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

« back to all changes in this revision

Viewing changes to hooks/neutron_api_hooks.py

  • Committer: James Page
  • Date: 2015-11-04 18:02:37 UTC
  • mfrom: (39.9.67 neutron-api)
  • Revision ID: james.page@ubuntu.com-20151104180237-d858qfwj7oo0tzth
Add support for Nuage VSP SDN

This takes two forms

1) relation to the nuage-vsp charm

2) configuration options for an existing Nuage VSP installation

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
import sys
4
4
import uuid
 
5
import os
5
6
from subprocess import (
6
7
    check_call,
 
8
    check_output,
7
9
)
8
10
 
9
11
from charmhelpers.core.hookenv import (
30
32
 
31
33
from charmhelpers.fetch import (
32
34
    apt_install,
 
35
    add_source,
33
36
    apt_update,
34
37
    filter_installed_packages,
35
38
)
88
91
    PUBLIC, INTERNAL, ADMIN
89
92
)
90
93
 
 
94
from charmhelpers.contrib.openstack.neutron import (
 
95
    neutron_plugin_attribute,
 
96
)
 
97
 
91
98
from charmhelpers.contrib.network.ip import (
92
99
    get_iface_for_address,
93
100
    get_netmask_for_address,
97
104
)
98
105
 
99
106
from charmhelpers.contrib.openstack.context import ADDRESS_TYPES
 
107
from charmhelpers.fetch.archiveurl import ArchiveUrlFetchHandler
100
108
 
101
109
from charmhelpers.contrib.charmsupport import nrpe
102
110
 
105
113
 
106
114
 
107
115
def conditional_neutron_migration():
108
 
    if os_release('neutron-common') < 'kilo':
109
 
        log('Not running neutron database migration as migrations are handled '
110
 
            'by the neutron-server process or nova-cloud-controller charm.')
111
 
        return
 
116
    if os_release('neutron-server') < 'kilo':
 
117
        if not (os_release('neutron-server') == 'juno' and
 
118
           config('neutron-plugin') == 'vsp'):
 
119
            log('Not running neutron database migration as migrations '
 
120
                'are handled by the neutron-server process or'
 
121
                ' nova-cloud-controller charm.')
 
122
            return
112
123
 
113
124
    if is_elected_leader(CLUSTER_RES):
114
125
        allowed_units = relation_get('allowed_units')
156
167
        config('neutron-plugin'), config('openstack-origin')
157
168
    )
158
169
 
 
170
    add_source(config('extra-source'), config('extra-key'))
159
171
    status_set('maintenance', 'Installing apt packages')
160
172
    apt_update()
161
 
    apt_install(determine_packages(config('openstack-origin')),
162
 
                fatal=True)
 
173
    packages = determine_packages(config('openstack-origin'))
 
174
    apt_install(packages, fatal=True)
 
175
 
 
176
    if config('neutron-plugin') == 'vsp':
 
177
        source = config('nuage-tarball-url')
 
178
        if source is not None:
 
179
            try:
 
180
                handler = ArchiveUrlFetchHandler()
 
181
                packages = ['nuage-neutron']
 
182
                path = handler.install(source)
 
183
                for package in packages:
 
184
                    package_path = os.path.join(path, package)
 
185
                    if os.path.exists(package_path):
 
186
                        log('install {0} from: {1}'.format(package,
 
187
                                                           package_path))
 
188
                        check_output(
 
189
                            [
 
190
                                'bash', '-c',
 
191
                                'cd {}; sudo python setup.py install'.format(
 
192
                                    package_path)
 
193
                            ]
 
194
                        )
 
195
            except Exception as e:
 
196
                log('install failed with error: {}'.format(e.message))
 
197
                raise Exception(e)
163
198
 
164
199
    status_set('maintenance', 'Git install')
165
200
    git_install(config('openstack-origin-git'))
167
202
    [open_port(port) for port in determine_ports()]
168
203
 
169
204
 
 
205
@hooks.hook('vsd-rest-api-relation-changed')
 
206
@restart_on_change(restart_map(), stopstart=True)
 
207
def vsd_changed(relation_id=None, remote_unit=None):
 
208
    if config('neutron-plugin') == 'vsp':
 
209
        vsd_ip_address = relation_get('vsd-ip-address')
 
210
        if not vsd_ip_address:
 
211
            return
 
212
        vsd_address = '{}:8443'.format(vsd_ip_address)
 
213
        nuage_config_file = neutron_plugin_attribute(config('neutron-plugin'),
 
214
                                                     'config', 'neutron')
 
215
        log('vsd-rest-api-relation-changed: ip address:{}'.format(vsd_address))
 
216
        log('vsd-rest-api-relation-changed:{}'.format(nuage_config_file))
 
217
        CONFIGS.write(nuage_config_file)
 
218
 
 
219
 
170
220
@hooks.hook('upgrade-charm')
171
221
@hooks.hook('config-changed')
172
222
@restart_on_change(restart_map(), stopstart=True)