mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-11 03:31:29 -07:00
Proxmox inventory: Added snapshots fact (#3044)
* Added snapshots fact * Added changelog * Made linter happy again * Processed feedback * Fix changelog type * Punctuation ;-) * Punctuation ;-), take 2
This commit is contained in:
parent
38e70ae0e4
commit
32e9a0c250
3 changed files with 31 additions and 2 deletions
|
@ -325,6 +325,15 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
|||
status_key = self.to_safe('%s%s' % (self.get_option('facts_prefix'), status_key.lower()))
|
||||
self.inventory.set_variable(name, status_key, status)
|
||||
|
||||
def _get_vm_snapshots(self, node, vmid, vmtype, name):
|
||||
ret = self._get_json("%s/api2/json/nodes/%s/%s/%s/snapshot" % (self.proxmox_url, node, vmtype, vmid))
|
||||
|
||||
snapshots_key = 'snapshots'
|
||||
snapshots_key = self.to_safe('%s%s' % (self.get_option('facts_prefix'), snapshots_key.lower()))
|
||||
|
||||
snapshots = [snapshot['name'] for snapshot in ret if snapshot['name'] != 'current']
|
||||
self.inventory.set_variable(name, snapshots_key, snapshots)
|
||||
|
||||
def to_safe(self, word):
|
||||
'''Converts 'bad' characters in a string to underscores so they can be used as Ansible groups
|
||||
#> ProxmoxInventory.to_safe("foo-bar baz")
|
||||
|
@ -393,9 +402,10 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
|||
elif lxc['status'] == 'running':
|
||||
self.inventory.add_child(running_group, lxc['name'])
|
||||
|
||||
# get LXC config for facts
|
||||
# get LXC config and snapshots for facts
|
||||
if self.get_option('want_facts'):
|
||||
self._get_vm_config(node['node'], lxc['vmid'], 'lxc', lxc['name'])
|
||||
self._get_vm_snapshots(node['node'], lxc['vmid'], 'lxc', lxc['name'])
|
||||
|
||||
self._apply_constructable(lxc["name"], self.inventory.get_host(lxc['name']).get_vars())
|
||||
|
||||
|
@ -417,9 +427,10 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
|||
elif qemu['status'] == 'running':
|
||||
self.inventory.add_child(running_group, qemu['name'])
|
||||
|
||||
# get QEMU config for facts
|
||||
# get QEMU config and snapshots for facts
|
||||
if self.get_option('want_facts'):
|
||||
self._get_vm_config(node['node'], qemu['vmid'], 'qemu', qemu['name'])
|
||||
self._get_vm_snapshots(node['node'], qemu['vmid'], 'qemu', qemu['name'])
|
||||
|
||||
self._apply_constructable(qemu["name"], self.inventory.get_host(qemu['name']).get_vars())
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue