]>
Commit | Line | Data |
---|---|---|
91327a77 AA |
1 | # -*- coding: utf-8 -*- |
2 | ||
3 | import argparse | |
4 | import pprint | |
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 | self.args = parser.parse_args(self.argv) | |
35 | if self.args.path: | |
36 | self.format_report(Device(self.args.path)) | |
37 | else: | |
38 | self.format_report(Devices()) | |
39 | ||
40 | def format_report(self, inventory): | |
41 | if self.args.format == 'json': | |
42 | print(inventory.json_report()) | |
43 | elif self.args.format == 'json-pretty': | |
44 | pprint.pprint(inventory.json_report()) | |
45 | else: | |
46 | print(inventory.pretty_report()) |