1 from __future__
import print_function
5 from textwrap
import dedent
6 from ceph_volume
import decorators
, process
9 logger
= logging
.getLogger(__name__
)
11 def direct_report(devices
):
13 Other non-cli consumers of listing information will want to consume the
14 report without the need to parse arguments or other flags. This helper
15 bypasses the need to deal with the class interface which is meant for cli
19 return _list
.generate(devices
)
24 help = 'list BlueStore OSDs on raw devices'
26 def __init__(self
, argv
):
29 def generate(self
, devs
=None):
31 logger
.debug('Listing block devices via lsblk...')
33 out
, err
, ret
= process
.call([
34 'lsblk', '--paths', '--nodeps', '--output=NAME', '--noheadings'
40 logger
.debug('Examining %s' % dev
)
42 out
, err
, ret
= process
.call([
43 'ceph-bluestore-tool', 'show-label',
44 '--dev', dev
], verbose_on_failure
=False)
46 logger
.debug('No label on %s' % dev
)
48 oj
= json
.loads(''.join(out
))
51 if oj
[dev
]['description'] != 'main':
52 # ignore non-main devices, for now
54 whoami
= oj
[dev
]['whoami']
57 'osd_id': int(whoami
),
59 for f
in ['osd_uuid', 'ceph_fsid']:
60 result
[whoami
][f
] = oj
[dev
][f
]
61 result
[whoami
]['device'] = dev
64 @decorators.needs_root
66 report
= self
.generate(args
.device
)
67 if args
.format
== 'json':
68 print(json
.dumps(report
, indent
=4, sort_keys
=True))
71 raise SystemExit('No valid Ceph devices found')
72 raise RuntimeError('not implemented yet')
75 sub_command_help
= dedent("""
76 List OSDs on raw devices with raw device labels (usually the first
79 Full listing of all identifiable (currently, BlueStore) OSDs
84 List a particular device, reporting all metadata about it::
86 ceph-volume raw list /dev/sda1
89 parser
= argparse
.ArgumentParser(
90 prog
='ceph-volume raw list',
91 formatter_class
=argparse
.RawDescriptionHelpFormatter
,
92 description
=sub_command_help
,
99 help='Path to a device like /dev/sda1'
104 help='output format, defaults to "pretty"',
106 choices
=['json', 'pretty'],
109 args
= parser
.parse_args(self
.argv
)