From a39470ac2b7b34fea07e89835618f0e738539ac3 Mon Sep 17 00:00:00 2001 From: Artem Goncharov Date: Tue, 29 Sep 2020 20:38:46 +0200 Subject: [PATCH] Add volume_backup_info module Change-Id: I5ef76247a449b1b8653bb2bb91fccd5f3db57cf8 --- ci/roles/volume/tasks/main.yml | 8 ++ meta/runtime.yml | 3 + plugins/modules/volume_backup_info.py | 121 ++++++++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 plugins/modules/volume_backup_info.py diff --git a/ci/roles/volume/tasks/main.yml b/ci/roles/volume/tasks/main.yml index cae067a4..583dde8c 100644 --- a/ci/roles/volume/tasks/main.yml +++ b/ci/roles/volume/tasks/main.yml @@ -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 }}" diff --git a/meta/runtime.yml b/meta/runtime.yml index 2ebe1a01..1d639581 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -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 diff --git a/plugins/modules/volume_backup_info.py b/plugins/modules/volume_backup_info.py new file mode 100644 index 00000000..b0f614b3 --- /dev/null +++ b/plugins/modules/volume_backup_info.py @@ -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()