Debian Codegraph @

ansible_collections/community/general/plugins/modules/btrfs_info.py

raw
1 #!/usr/bin/python
2
3 # Copyright (c) 2022, Gregory Furlong <[email protected]>
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5 # SPDX-License-Identifier: GPL-3.0-or-later
6
7 from __future__ import annotations
8
9 DOCUMENTATION = r"""
10 module: btrfs_info
11 short_description: Query btrfs filesystem info
12 version_added: "6.6.0"
13 description: Query status of available btrfs filesystems, including UUID, label, subvolumes and mountpoints.
14
15 author:
16 - Gregory Furlong (@gnfzdz)
17
18 extends_documentation_fragment:
19 - community.general._attributes
20 - community.general._attributes.info_module
21 """
22
23 EXAMPLES = r"""
24 - name: Query information about mounted btrfs filesystems
25 community.general.btrfs_info:
26 register: my_btrfs_info
27 """
28
29 RETURN = r"""
30 filesystems:
31 description: Summaries of the current state for all btrfs filesystems found on the target host.
32 type: list
33 elements: dict
34 returned: success
35 contains:
36 uuid:
37 description: A unique identifier assigned to the filesystem.
38 type: str
39 sample: 96c9c605-1454-49b8-a63a-15e2584c208e
40 label:
41 description: An optional label assigned to the filesystem.
42 type: str
43 sample: Tank
44 devices:
45 description: A list of devices assigned to the filesystem.
46 type: list
47 sample:
48 - /dev/sda1
49 - /dev/sdb1
50 default_subvolume:
51 description: The ID of the filesystem's default subvolume.
52 type: int
53 sample: 5
54 subvolumes:
55 description: A list of dicts containing metadata for all of the filesystem's subvolumes.
56 type: list
57 elements: dict
58 contains:
59 id:
60 description: An identifier assigned to the subvolume, unique within the containing filesystem.
61 type: int
62 sample: 256
63 mountpoints:
64 description: Paths where the subvolume is mounted on the targeted host.
65 type: list
66 sample: ["/home"]
67 parent:
68 description: The identifier of this subvolume's parent.
69 type: int
70 sample: 5
71 path:
72 description: The full path of the subvolume relative to the btrfs fileystem's root.
73 type: str
74 sample: /@home
75 """
76
77
78 from ansible.module_utils.basic import AnsibleModule
79
80 from ansible_collections.community.general.plugins.module_utils._btrfs import BtrfsFilesystemsProvider
81
82
83 def run_module():
84 module_args = dict()
85
86 module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)
87
88 provider = BtrfsFilesystemsProvider(module)
89 filesystems = [x.get_summary() for x in provider.get_filesystems()]
90 result = {
91 "filesystems": filesystems,
92 }
93 module.exit_json(**result)
94
95
96 def main():
97 run_module()
98
99
100 if __name__ == "__main__":
101 main()