]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-create-keys: Create a bootstrap-osd key too.
authorTommi Virtanen <tv@inktank.com>
Thu, 13 Sep 2012 21:06:04 +0000 (14:06 -0700)
committerSage Weil <sage@inktank.com>
Fri, 14 Sep 2012 19:31:03 +0000 (12:31 -0700)
Signed-off-by: Tommi Virtanen <tv@inktank.com>
debian/ceph.dirs
src/ceph-create-keys

index fcb9258730835727fa4eaf0ba395dfb00e90c17b..b9b8a21816fa5bc2300ea7ff1eff0cda100bf1c0 100644 (file)
@@ -4,3 +4,4 @@ var/lib/ceph/tmp
 var/lib/ceph/mon
 var/lib/ceph/osd
 var/lib/ceph/mds
+var/lib/ceph/bootstrap-osd
index 50a97dfb4ad1f8e912dfb6f166a6c5b66e8b6554..438e51d307679151473dac0c0ce42f822b61d481 100755 (executable)
@@ -94,6 +94,57 @@ def get_key(cluster, mon_id):
                 else:
                     raise
 
+def bootstrap_key(cluster, type_, caps):
+    path = '/var/lib/ceph/bootstrap-{type}/{cluster}.keyring'.format(
+        type=type_,
+        cluster=cluster,
+        )
+    if os.path.exists(path):
+        log.info('Key exists already: %s', path)
+        return
+    tmp = '{path}.{pid}.tmp'.format(
+        path=path,
+        pid=os.getpid(),
+        )
+
+    args = [
+        'ceph',
+        '--cluster={cluster}'.format(cluster=cluster),
+        'auth',
+        'get-or-create',
+        'client.bootstrap-{type}'.format(type=type_),
+        ]
+    for subsystem, subcaps in caps.iteritems():
+        args.extend([
+            subsystem,
+            '; '.join(subcaps),
+            ])
+
+    while True:
+        try:
+            with file(tmp, 'w') as f:
+                os.fchmod(f.fileno(), 0600)
+                log.info('Talking to monitor...')
+                returncode = subprocess.call(
+                    args=args,
+                    stdout=f,
+                    )
+            if returncode != 0:
+                log.info('Cannot get or create bootstrap key for %s', type_)
+                time.sleep(1)
+                continue
+
+            os.rename(tmp, path)
+            break
+        finally:
+            try:
+                os.unlink(tmp)
+            except OSError as e:
+                if e.errno == errno.ENOENT:
+                    pass
+                else:
+                    raise
+
 
 def parse_args():
     parser = argparse.ArgumentParser(
@@ -139,6 +190,18 @@ def main():
 
     wait_for_quorum(cluster=args.cluster, mon_id=args.id)
     get_key(cluster=args.cluster, mon_id=args.id)
+    bootstrap_key(
+        cluster=args.cluster,
+        type_='osd',
+        caps=dict(
+            mon=[
+                'allow command osd create ...',
+                'allow command osd crush set ...',
+                r'allow command auth add * osd allow\ * mon allow\ rwx',
+                'allow command mon getmap',
+                ],
+            ),
+        )
 
 
 if __name__ == '__main__':