~james-page/charms/precise/ceph-osd/dir-support

« back to all changes in this revision

Viewing changes to hooks/hooks.py

  • Committer: James Page
  • Date: 2012-12-17 10:31:03 UTC
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: james.page@canonical.com-20121217103103-2hbmznsgm3syxckt
Resync with ceph charm, updates for raring

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
 
20
20
def install_upstart_scripts():
21
 
    for x in glob.glob('files/upstart/*.conf'):
22
 
        shutil.copy(x, '/etc/init/')
 
21
    # Only install upstart configurations for older versions
 
22
    if ceph.version_compare(ceph.get_ceph_version(),
 
23
                            "0.55.1") < 0:
 
24
        for x in glob.glob('files/upstart/*.conf'):
 
25
            shutil.copy(x, '/etc/init/')
23
26
 
24
27
 
25
28
def install():
37
40
    cephcontext = {
38
41
        'auth_supported': get_auth(),
39
42
        'mon_hosts': ' '.join(mon_hosts),
40
 
        'fsid': get_fsid()
 
43
        'fsid': get_fsid(),
 
44
        'version': ceph.get_ceph_version()
41
45
        }
42
46
 
43
47
    with open('/etc/ceph/ceph.conf', 'w') as cephconf:
48
52
    utils.juju_log('INFO', 'Begin config-changed hook.')
49
53
 
50
54
    e_mountpoint = utils.config_get('ephemeral-unmount')
51
 
    if (e_mountpoint != "" and
 
55
    if (e_mountpoint and
52
56
        filesystem_mounted(e_mountpoint)):
53
57
        subprocess.call(['umount', e_mountpoint])
54
58
 
89
93
        for unit in utils.relation_list(relid):
90
94
            conf = utils.relation_get(name,
91
95
                                      unit, relid)
92
 
            if conf != "":
 
96
            if conf:
93
97
                return conf
94
98
    return None
95
99
 
96
100
 
97
101
def reformat_osd():
98
 
    if utils.config_get('osd-reformat') != "":
 
102
    if utils.config_get('osd-reformat'):
99
103
        return True
100
104
    else:
101
105
        return False
119
123
                       'Looks like {} is in use, skipping.'.format(dev))
120
124
        return
121
125
 
122
 
    subprocess.call(['ceph-disk-prepare', dev])
 
126
    cmd = ['ceph-disk-prepare']
 
127
    # Later versions of ceph support more options
 
128
    if ceph.version_compare(ceph.get_ceph_version(),
 
129
                            "0.55") >= 0:
 
130
        osd_format = utils.config_get('osd-format')
 
131
        if osd_format:
 
132
            cmd.append('--fs-type')
 
133
            cmd.append(osd_format)
 
134
        cmd.append(dev)
 
135
        osd_journal = utils.config_get('osd-journal')
 
136
        if (osd_journal and
 
137
            os.path.exists(osd_journal)):
 
138
            cmd.append(osd_journal)
 
139
    else:
 
140
        # Just provide the device - no other options
 
141
        # for older versions of ceph
 
142
        cmd.append(dev)
 
143
    subprocess.call(cmd)
123
144
 
124
145
 
125
146
def device_mounted(dev):
136
157
    bootstrap_key = utils.relation_get('osd_bootstrap_key')
137
158
    if (get_fsid() and
138
159
        get_auth() and
139
 
        bootstrap_key != ""):
 
160
        bootstrap_key):
140
161
        utils.juju_log('INFO', 'mon has provided conf- scanning disks')
141
162
        emit_cephconf()
142
163
        ceph.import_osd_bootstrap_key(bootstrap_key)
159
180
    utils.juju_log('INFO', 'End upgrade-charm hook.')
160
181
 
161
182
 
162
 
def start():
163
 
    # In case we're being redeployed to the same machines, try
164
 
    # to make sure everything is running as soon as possible.
165
 
    ceph.rescan_osd_devices()
166
 
 
167
 
 
168
183
utils.do_hooks({
169
184
        'config-changed': config_changed,
170
185
        'install': install,
171
186
        'mon-relation-departed': mon_relation,
172
187
        'mon-relation-changed': mon_relation,
173
 
        'start': start,
174
188
        'upgrade-charm': upgrade_charm,
175
189
        })
176
190