~heut2008/charms/trusty/ceph-radosgw/auth_protocol

« back to all changes in this revision

Viewing changes to hooks/ceph.py

  • Committer: Marco Ceppi
  • Date: 2014-01-29 09:32:33 UTC
  • mfrom: (14.1.5 ceph-radosgw)
  • Revision ID: marco@ceppi.net-20140129093233-o7eva2xwuyp140p9
[james-page] Fixes for compatibility with apache 2.4
[james-page] General refresh to use charm-helpers inline with other ceph charms

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
import json
11
11
import subprocess
12
12
import time
13
 
import utils
14
13
import os
15
14
import apt_pkg as apt
16
15
 
 
16
from socket import gethostname as get_unit_hostname
 
17
 
17
18
LEADER = 'leader'
18
19
PEON = 'peon'
19
20
QUORUM = [LEADER, PEON]
20
21
 
21
22
 
22
23
def is_quorum():
23
 
    asok = "/var/run/ceph/ceph-mon.{}.asok".format(utils.get_unit_hostname())
 
24
    asok = "/var/run/ceph/ceph-mon.{}.asok".format(get_unit_hostname())
24
25
    cmd = [
25
26
        "ceph",
26
27
        "--admin-daemon",
27
28
        asok,
28
29
        "mon_status"
29
 
        ]
 
30
    ]
30
31
    if os.path.exists(asok):
31
32
        try:
32
33
            result = json.loads(subprocess.check_output(cmd))
44
45
 
45
46
 
46
47
def is_leader():
47
 
    asok = "/var/run/ceph/ceph-mon.{}.asok".format(utils.get_unit_hostname())
 
48
    asok = "/var/run/ceph/ceph-mon.{}.asok".format(get_unit_hostname())
48
49
    cmd = [
49
50
        "ceph",
50
51
        "--admin-daemon",
51
52
        asok,
52
53
        "mon_status"
53
 
        ]
 
54
    ]
54
55
    if os.path.exists(asok):
55
56
        try:
56
57
            result = json.loads(subprocess.check_output(cmd))
73
74
 
74
75
 
75
76
def add_bootstrap_hint(peer):
76
 
    asok = "/var/run/ceph/ceph-mon.{}.asok".format(utils.get_unit_hostname())
 
77
    asok = "/var/run/ceph/ceph-mon.{}.asok".format(get_unit_hostname())
77
78
    cmd = [
78
79
        "ceph",
79
80
        "--admin-daemon",
80
81
        asok,
81
82
        "add_bootstrap_peer_hint",
82
83
        peer
83
 
        ]
 
84
    ]
84
85
    if os.path.exists(asok):
85
86
        # Ignore any errors for this call
86
87
        subprocess.call(cmd)
89
90
    'xfs',
90
91
    'ext4',
91
92
    'btrfs'
92
 
    ]
 
93
]
93
94
 
94
95
 
95
96
def is_osd_disk(dev):
99
100
        for line in info:
100
101
            if line.startswith(
101
102
                'Partition GUID code: 4FBD7E29-9D25-41B8-AFD0-062C0CEFF05D'
102
 
                ):
 
103
            ):
103
104
                return True
104
105
    except subprocess.CalledProcessError:
105
106
        pass
110
111
    cmd = [
111
112
        'udevadm', 'trigger',
112
113
        '--subsystem-match=block', '--action=add'
113
 
        ]
 
114
    ]
114
115
 
115
116
    subprocess.call(cmd)
116
117
 
140
141
            '--create-keyring',
141
142
            '--name=client.bootstrap-osd',
142
143
            '--add-key={}'.format(key)
143
 
            ]
 
144
        ]
144
145
        subprocess.check_call(cmd)
145
146
 
146
147
# OSD caps taken from ceph-create-keys
148
149
    'mon': [
149
150
        'allow command osd create ...',
150
151
        'allow command osd crush set ...',
151
 
       r'allow command auth add * osd allow\ * mon allow\ rwx',
 
152
        r'allow command auth add * osd allow\ * mon allow\ rwx',
152
153
        'allow command mon getmap'
153
 
        ]
154
 
    }
 
154
    ]
 
155
}
155
156
 
156
157
 
157
158
def get_osd_bootstrap_key():
169
170
            '--create-keyring',
170
171
            '--name=client.radosgw.gateway',
171
172
            '--add-key={}'.format(key)
172
 
            ]
 
173
        ]
173
174
        subprocess.check_call(cmd)
174
175
 
175
176
# OSD caps taken from ceph-create-keys
176
177
_radosgw_caps = {
177
178
    'mon': ['allow r'],
178
179
    'osd': ['allow rwx']
179
 
    }
 
180
}
180
181
 
181
182
 
182
183
def get_radosgw_key():
186
187
_default_caps = {
187
188
    'mon': ['allow r'],
188
189
    'osd': ['allow rwx']
189
 
    }
 
190
}
190
191
 
191
192
 
192
193
def get_named_key(name, caps=None):
196
197
        '--name', 'mon.',
197
198
        '--keyring',
198
199
        '/var/lib/ceph/mon/ceph-{}/keyring'.format(
199
 
                                        utils.get_unit_hostname()
200
 
                                        ),
 
200
            get_unit_hostname()
 
201
        ),
201
202
        'auth', 'get-or-create', 'client.{}'.format(name),
202
 
        ]
 
203
    ]
203
204
    # Add capabilities
204
205
    for subsystem, subcaps in caps.iteritems():
205
206
        cmd.extend([
206
207
            subsystem,
207
208
            '; '.join(subcaps),
208
 
            ])
 
209
        ])
209
210
    output = subprocess.check_output(cmd).strip()  # IGNORE:E1103
210
211
    # get-or-create appears to have different output depending
211
212
    # on whether its 'get' or 'create'