]> git.proxmox.com Git - ceph.git/blob - ceph/src/ceph-volume/ceph_volume/inventory/main.py
Import ceph 15.2.8
[ceph.git] / ceph / src / ceph-volume / ceph_volume / inventory / main.py
1 # -*- coding: utf-8 -*-
2
3 import argparse
4 import json
5
6 from ceph_volume.util.device import Devices, Device
7
8
9 class Inventory(object):
10
11 help = "Get this nodes available disk inventory"
12
13 def __init__(self, argv):
14 self.argv = argv
15
16 def main(self):
17 parser = argparse.ArgumentParser(
18 prog='ceph-volume inventory',
19 formatter_class=argparse.RawDescriptionHelpFormatter,
20 description=self.help,
21 )
22 parser.add_argument(
23 'path',
24 nargs='?',
25 default=None,
26 help=('Report on specific disk'),
27 )
28 parser.add_argument(
29 '--format',
30 choices=['plain', 'json', 'json-pretty'],
31 default='plain',
32 help='Output format',
33 )
34 parser.add_argument(
35 '--filter-for-batch',
36 action='store_true',
37 help=('Filter devices unsuitable to pass to an OSD service spec, '
38 'no effect when <path> is passed'),
39 default=False,
40 )
41 parser.add_argument(
42 '--with-lsm',
43 action='store_true',
44 help=('Attempt to retrieve additional health and metadata through '
45 'libstoragemgmt'),
46 default=False,
47 )
48 self.args = parser.parse_args(self.argv)
49 if self.args.path:
50 self.format_report(Device(self.args.path, with_lsm=self.args.with_lsm))
51 else:
52 self.format_report(Devices(filter_for_batch=self.args.filter_for_batch,
53 with_lsm=self.args.with_lsm))
54
55 def get_report(self):
56 if self.args.path:
57 return Device(self.args.path, with_lsm=self.args.with_lsm).json_report()
58 else:
59 return Devices(filter_for_batch=self.args.filter_for_batch, with_lsm=self.args.with_lsm).json_report()
60
61 def format_report(self, inventory):
62 if self.args.format == 'json':
63 print(json.dumps(inventory.json_report()))
64 elif self.args.format == 'json-pretty':
65 print(json.dumps(inventory.json_report(), indent=4, sort_keys=True))
66 else:
67 print(inventory.pretty_report())