]>
Commit | Line | Data |
---|---|---|
91327a77 AA |
1 | # -*- coding: utf-8 -*- |
2 | ||
3 | import argparse | |
f64942e4 | 4 | import json |
91327a77 AA |
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 | ) | |
f91f0fd5 TL |
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 | ) | |
91327a77 AA |
48 | self.args = parser.parse_args(self.argv) |
49 | if self.args.path: | |
f91f0fd5 | 50 | self.format_report(Device(self.args.path, with_lsm=self.args.with_lsm)) |
91327a77 | 51 | else: |
f91f0fd5 TL |
52 | self.format_report(Devices(filter_for_batch=self.args.filter_for_batch, |
53 | with_lsm=self.args.with_lsm)) | |
91327a77 | 54 | |
f6b5b4d7 TL |
55 | def get_report(self): |
56 | if self.args.path: | |
f91f0fd5 | 57 | return Device(self.args.path, with_lsm=self.args.with_lsm).json_report() |
f6b5b4d7 | 58 | else: |
f91f0fd5 | 59 | return Devices(filter_for_batch=self.args.filter_for_batch, with_lsm=self.args.with_lsm).json_report() |
f6b5b4d7 | 60 | |
91327a77 AA |
61 | def format_report(self, inventory): |
62 | if self.args.format == 'json': | |
f64942e4 | 63 | print(json.dumps(inventory.json_report())) |
91327a77 | 64 | elif self.args.format == 'json-pretty': |
f64942e4 | 65 | print(json.dumps(inventory.json_report(), indent=4, sort_keys=True)) |
91327a77 AA |
66 | else: |
67 | print(inventory.pretty_report()) |