Debian Codegraph @

ansible_collections/community/proxmox/plugins/modules/proxmox_storage_contents_info.py

raw
1 #!/usr/bin/python
2 #
3 # Copyright Julian Vanden Broeck (@l00ptr) <julian.vandenbroeck at dalibo.com>
4 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
5 # SPDX-License-Identifier: GPL-3.0-or-later
6
7
8 DOCUMENTATION = r"""
9 module: proxmox_storage_contents_info
10 short_description: List content from a Proxmox VE storage
11 description:
12 - Retrieves information about stored objects on a specific storage attached to a node.
13 options:
14 storage:
15 description:
16 - Only return content stored on that specific storage.
17 aliases: ['name']
18 type: str
19 required: true
20 node:
21 description:
22 - Proxmox node to which the storage is attached.
23 type: str
24 required: true
25 content:
26 description:
27 - Filter on a specific content type.
28 type: str
29 choices: ["all", "backup", "rootdir", "images", "iso", "import"]
30 default: "all"
31 vmid:
32 description:
33 - Filter on a specific VMID.
34 type: int
35 author: Julian Vanden Broeck (@l00ptr)
36 extends_documentation_fragment:
37 - community.proxmox.proxmox.actiongroup_proxmox
38 - community.proxmox.proxmox.documentation
39 - community.proxmox.attributes
40 - community.proxmox.attributes.info_module
41 """
42
43
44 EXAMPLES = r"""
45 - name: List existing storages
46 community.proxmox.proxmox_storage_contents_info:
47 storage: lvm2
48 content: backup
49 vmid: 130
50 """
51
52
53 RETURN = r"""
54 proxmox_storage_content:
55 description: Content of of storage attached to a node.
56 type: list
57 returned: success
58 elements: dict
59 contains:
60 content:
61 description: Proxmox content of listed objects on this storage.
62 type: str
63 returned: success
64 ctime:
65 description: Creation time of the listed objects.
66 type: str
67 returned: success
68 format:
69 description: Format of the listed objects (can be V(raw), V(pbs-vm), V(iso),...).
70 type: str
71 returned: success
72 size:
73 description: Size of the listed objects.
74 type: int
75 returned: success
76 subtype:
77 description: Subtype of the listed objects (can be V(qemu) or V(lxc)).
78 type: str
79 returned: When storage is dedicated to backup, typically on PBS storage.
80 verification:
81 description: Backup verification status of the listed objects.
82 type: dict
83 returned: When storage is dedicated to backup, typically on PBS storage.
84 sample: {
85 "state": "ok",
86 "upid": "UPID:backup-srv:00130F49:1A12D8375:00001CD7:657A2258:verificationjob:daily\\x3av\\x2dd0cc18c5\\x2d8707:root@pam:"
87 }
88 volid:
89 description: Volume identifier of the listed objects.
90 type: str
91 returned: success
92 """
93
94
95 from ansible_collections.community.proxmox.plugins.module_utils.proxmox import (
96 ProxmoxAnsible,
97 create_proxmox_module,
98 )
99
100
101 def module_args():
102 return dict(
103 storage=dict(type="str", required=True, aliases=["name"]),
104 content=dict(
105 type="str", required=False, default="all", choices=["all", "backup", "rootdir", "images", "iso", "import"]
106 ),
107 vmid=dict(type="int"),
108 node=dict(required=True, type="str"),
109 )
110
111
112 def module_options():
113 return {}
114
115
116 def main():
117 module = create_proxmox_module(module_args(), **module_options())
118 proxmox = ProxmoxAnsible(module)
119
120 result = dict(changed=False)
121 res = proxmox.get_storage_content(
122 node=module.params["node"],
123 storage=module.params["storage"],
124 content=None if module.params["content"] == "all" else module.params["content"],
125 vmid=module.params["vmid"],
126 )
127 result["proxmox_storage_content"] = res
128 module.exit_json(**result)
129
130
131 if __name__ == "__main__":
132 main()