-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathceph_osd_bootstrap_key.rb
58 lines (47 loc) · 1.38 KB
/
ceph_osd_bootstrap_key.rb
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
# Fact: ceph_osd_bootstrap_key
#
# Purpose:
#
# Resolution:
#
# Caveats:
#
require 'facter'
require 'timeout'
timeout = 10
cmd_timeout = 10
# ceph_osd_bootstrap_key
# Fact that gets the ceph key "client.bootstrap-osd"
Facter.add(:ceph_admin_key, :timeout => timeout) do
if system("timeout #{cmd_timeout} ceph -s > /dev/null 2>&1")
setcode { Facter::Util::Resolution.exec("timeout #{cmd_timeout} ceph auth get-key client.admin") }
end
end
## blkid_uuid_#{device} / ceph_osd_id_#{device}
## Facts that export partitions uuids & ceph osd id of device
# Load the osds/uuids from ceph
ceph_osds = Hash.new
begin
Timeout::timeout(timeout) {
if system("timeout #{cmd_timeout} ceph -s > /dev/null 2>&1")
ceph_osd_dump = Facter::Util::Resolution.exec("timeout #{cmd_timeout} ceph osd dump")
ceph_osd_dump and ceph_osd_dump.each_line do |line|
if line =~ /^osd\.(\d+).* ([a-f0-9\-]+)$/
ceph_osds[$2] = $1
end
end
end
}
rescue Timeout::Error
Facter.warnonce('ceph command timeout in ceph_osd_bootstrap_key fact')
end
# Load the disks uuids
blkid = Facter::Util::Resolution.exec("blkid")
blkid and blkid.each_line do |line|
if line =~ /^\/dev\/(.+):\s*UUID="([a-fA-F0-9\-]+)"/
device = $1
uuid = $2
Facter.add("blkid_uuid_#{device}") { setcode { uuid } }
Facter.add("ceph_osd_id_#{device}") { setcode { ceph_osds[uuid] } }
end
end