summaryrefslogtreecommitdiffstats
path: root/hooks/lxd_hooks.py
blob: b65d58c29fd8e094d5205ba88c11701c58118d0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env python
#
# Copyright 2016 Canonical Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from socket import gethostname
import sys
import uuid

from charmhelpers.core.hookenv import (
    Hooks,
    UnregisteredHookError,
    config,
    log,
    unit_get,
    relation_set,
    relation_get,
    relation_ids,
    related_units,
    status_set,
)

from charmhelpers.core.host import (
    umount,
    add_user_to_group,
)

from lxd_utils import (
    filesystem_mounted,
    determine_packages,
    install_lxd_source,
    configure_lxd_source,
    configure_lxd_block,
    lxd_trust_password,
    configure_lxd_remote,
    configure_lxd_host,
    assess_status,
    has_storage,
    LXD_POOL,
)

from charmhelpers.fetch import (
    apt_update,
    apt_install,
    add_source,
)

from charmhelpers.contrib.openstack.utils import (
    clear_unit_paused,
    clear_unit_upgrading,
    set_unit_paused,
    set_unit_upgrading,
)

hooks = Hooks()


@hooks.hook('install.real')
def install():
    status_set('maintenance', 'Installing LXD packages')
    if config('source'):
        add_source(config('source'))
    apt_update(fatal=True)
    apt_install(determine_packages(), fatal=True)
    if config('use-source'):
        install_lxd_source()
        configure_lxd_source()


@hooks.hook()
def config_changed():
    e_mountpoint = config('ephemeral-unmount')
    if e_mountpoint and filesystem_mounted(e_mountpoint):
        umount(e_mountpoint)
    configure_lxd_block()
    configure_lxd_host()


@hooks.hook('lxd-migration-relation-joined')
def lxd_relation_joined(rid=None):
    settings = {}
    settings['password'] = lxd_trust_password()
    settings['hostname'] = gethostname()
    settings['address'] = unit_get('private-address')
    if has_storage():
        settings['pool'] = LXD_POOL
    relation_set(relation_id=rid,
                 relation_settings=settings)


@hooks.hook('lxd-relation-changed')
def lxd_relation_changed():
    user = relation_get('user')
    if user:
        add_user_to_group(user, 'lxd')
        for rid in relation_ids('lxd'):
            relation_set(relation_id=rid,
                         nonce=uuid.uuid4())
        # Re-fire lxd-migration relation to ensure that
        # remotes have been setup for the user
        for rid in relation_ids('lxd-migration'):
            for unit in related_units(rid):
                lxd_migration_relation_changed(rid, unit)


@hooks.hook('lxd-migration-relation-changed')
def lxd_migration_relation_changed(rid=None, unit=None):
    settings = {
        'password': relation_get('password',
                                 rid=rid,
                                 unit=unit),
        'hostname': relation_get('hostname',
                                 rid=rid,
                                 unit=unit),
        'address': relation_get('address',
                                rid=rid,
                                unit=unit),
    }
    if all(settings.values()):
        users = ['root']
        for rid in relation_ids('lxd'):
            for unit in related_units(rid):
                user = relation_get(attribute='user',
                                    rid=rid,
                                    unit=unit)
                if user:
                    users.append(user)
        users = list(set(users))
        [configure_lxd_remote(settings, u) for u in users]


@hooks.hook('pre-series-upgrade')
def pre_series_upgrade():
    log("Running prepare series upgrade hook", "INFO")
    # NOTE: The Ceph packages handle the series upgrade gracefully.
    # In order to indicate the step of the series upgrade process for
    # administrators and automated scripts, the charm sets the paused and
    # upgrading states.
    set_unit_paused()
    set_unit_upgrading()


@hooks.hook('post-series-upgrade')
def post_series_upgrade():
    log("Running complete series upgrade hook", "INFO")
    # In order to indicate the step of the series upgrade process for
    # administrators and automated scripts, the charm clears the paused and
    # upgrading states.
    clear_unit_paused()
    clear_unit_upgrading()


def main():
    try:
        hooks.execute(sys.argv)
    except UnregisteredHookError as e:
        log("Unknown hook {} - skipping.".format(e))
    assess_status()


if __name__ == "__main__":
    main()

This mirror site include all the OpenStack related repositories under: openstack, openstack-dev and openstack-infra.

NOTE: All repositories are updated every one hour.

Usage

For Git Clone
 git clone http://git.trystack.cn/openstack/nova.git 
For DevStack

Add GIT_BASE, NOVNC_REPO and SPICE_REPO variables to local.conf file.

[[local|localrc]]

# use TryStack git mirror
GIT_BASE=http://git.trystack.cn
NOVNC_REPO=http://git.trystack.cn/kanaka/noVNC.git
SPICE_REPO=http://git.trystack.cn/git/spice/spice-html5.git