Add volume_backup_info module

Change-Id: I5ef76247a449b1b8653bb2bb91fccd5f3db57cf8
This commit is contained in:
Artem Goncharov 2020-09-29 20:38:46 +02:00
parent 39a8362d7a
commit a39470ac2b
3 changed files with 132 additions and 0 deletions

View File

@ -16,10 +16,18 @@
volume: ansible_volume
register: vol_backup
- name: Get backup info
openstack.cloud.volume_backup_info:
cloud: "{{ cloud }}"
name: ansible_volume_backup
register: backup_info
- debug: var=vol
- debug: var=vol_backup
- debug: var=backup_info
- name: Delete volume backup
openstack.cloud.volume_backup:
cloud: "{{ cloud }}"

View File

@ -89,6 +89,7 @@ action_groups:
- subnets_info
- volume
- volume_backup
- volume_backup_info
- volume_info
- volume_snapshot
os:
@ -180,6 +181,8 @@ action_groups:
- subnet
- subnets_info
- volume
- volume_backup
- volume_backup_info
- volume_info
- volume_snapshot
- os_auth

View File

@ -0,0 +1,121 @@
#!/usr/bin/python
# coding: utf-8 -*-
#
# Copyright (c) 2020 by Open Telekom Cloud, operated by T-Systems International GmbH
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
DOCUMENTATION = '''
---
module: volume_backup_info
short_description: Get Backups
author: OpenStack Ansible SIG
description:
- Get Backup info from the Openstack cloud.
options:
name:
description:
- Name of the Backup.
type: str
volume:
description:
- Name of the volume.
type: str
requirements: ["openstacksdk"]
extends_documentation_fragment:
- openstack.cloud.openstack
'''
RETURN = '''
volume_backups:
description: List of dictionaries describing volume backups.
type: list
elements: dict
returned: always.
contains:
availability_zone:
description: Backup availability zone.
type: str
created_at:
description: Backup creation time.
type: str
description:
description: Backup desciption.
type: str
id:
description: Unique UUID.
type: str
sample: "39007a7e-ee4f-4d13-8283-b4da2e037c69"
is_incremental:
description: Backup incremental property.
type: bool
metadata:
description: Backup metadata.
type: dict
name:
description: Backup Name.
type: str
snapshot_id:
description: Snapshot ID.
type: str
status:
description: Backup status.
type: str
updated_at:
description: Backup update time.
type: str
volume_id:
description: Volume ID.
type: str
'''
EXAMPLES = '''
# Get backups.
- openstack.cloud.volume_backup_info:
register: backup
- openstack.cloud.volume_backup_info:
name: my_fake_backup
register: backup
'''
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
class VolumeBackupInfoModule(OpenStackModule):
argument_spec = dict(
name=dict(required=False, type='str'),
volume=dict(required=False, type='str')
)
def run(self):
name_filter = self.params['name']
volume = self.params['volume']
data = []
attrs = {}
if name_filter:
attrs['name'] = name_filter
if volume:
attrs['volume_id'] = self.conn.block_storage.find_volume(volume)
for raw in self.conn.block_storage.backups(**attrs):
dt = raw.to_dict()
dt.pop('location')
data.append(dt)
self.exit_json(
changed=False,
volume_backups=data
)
def main():
module = VolumeBackupInfoModule()
module()
if __name__ == '__main__':
main()