
    Vh                     R    d Z dZdZddlmZ  G d de      Zd Zedk(  r e        y	y	)
a  
---
module: volume_backup
short_description: Add/Delete Volume backup
author: OpenStack Ansible SIG
description:
  - Add or Remove Volume Backup in OpenStack.
options:
  description:
    description:
      - String describing the backup
    type: str
    aliases: ['display_description']
  force:
    description:
      - Indicates whether to backup, even if the volume is attached.
    type: bool
    default: False
  is_incremental:
    description: The backup mode
    type: bool
    default: False
    aliases: ['incremental']
  metadata:
    description: Metadata for the backup
    type: dict
  name:
    description:
      - Name that has to be given to the backup
    required: true
    type: str
    aliases: ['display_name']
  snapshot:
    description: Name or ID of the Snapshot to take backup of.
    type: str
  state:
    description:
      - Should the resource be present or absent.
    choices: [present, absent]
    default: present
    type: str
  volume:
    description:
      - Name or ID of the volume.
      - Required when I(state) is C(present).
    type: str
notes:
    - This module does not support updates to existing backups.
extends_documentation_fragment:
- openstack.cloud.openstack
a+
  
backup:
    description: Same as C(volume_backup), kept for backward compatibility.
    returned: On success when C(state=present)
    type: dict
volume_backup:
    description: Dictionary describing the volume backup.
    returned: On success when C(state=present)
    type: dict
    contains:
        availability_zone:
            description: Backup availability zone.
            type: str
        container:
            description: The container name.
            type: str
        created_at:
            description: Backup creation time.
            type: str
        data_timestamp:
            description: The time when the data on the volume was first saved.
                         If it is a backup from volume, it will be the same as
                         C(created_at) for a backup. If it is a backup from a
                         snapshot, it will be the same as created_at for the
                         snapshot.
            type: str
        description:
            description: Backup desciption.
            type: str
        fail_reason:
            description: Backup fail reason.
            type: str
        force:
            description: Force backup.
            type: bool
        has_dependent_backups:
            description: If this value is true, there are other backups
                         depending on this backup.
            type: bool
        id:
            description: Unique UUID.
            type: str
            sample: "39007a7e-ee4f-4d13-8283-b4da2e037c69"
        is_incremental:
            description: Backup incremental property.
            type: bool
        links:
            description: A list of links associated with this volume.
            type: list
        metadata:
            description: Backup metadata.
            type: dict
        name:
            description: Backup Name.
            type: str
        object_count:
            description: backup object count.
            type: int
        project_id:
            description: The UUID of the owning project.
            type: str
        size:
            description: The size of the volume, in gibibytes (GiB).
            type: int
        snapshot_id:
            description: Snapshot ID.
            type: str
        status:
            description: Backup status.
            type: str
        updated_at:
            description: Backup update time.
            type: str
        user_id:
            description: The UUID of the project owner.
            type: str
        volume_id:
            description: Volume ID.
            type: str
ax  
- name: Create backup
  openstack.cloud.volume_backup:
    name: test_volume_backup
    volume: "test_volume"

- name: Create backup from snapshot
  openstack.cloud.volume_backup:
    name: test_volume_backup
    snapshot: "test_snapshot"
    volume: "test_volume"

- name: Delete volume backup
  openstack.cloud.volume_backup:
    name: test_volume_backup
    state: absent
    )OpenStackModulec                       e Zd Z e edg       edd       edddg       ed	       ed
dg       e        edddg       e             Z edddgfgd
      Zd Zd Zd Zd Z	y)VolumeBackupModuledisplay_description)aliasesFbool)defaulttypeincremental)r	   r
   r   dict)r
   Tdisplay_name)requiredr   presentabsent)r	   choices)descriptionforceis_incrementalmetadatanamesnapshotstatevolumer   r   )required_ifsupports_check_modec                    | j                   d   }| j                   d   }| j                  j                  j                  |      }| j                  j
                  r"| j                  | j                  ||             |dk(  rG|sE| j                         }| j                  d|j                  d      |j                  d             y |dk(  r7|r5| j                  d|j                  d      |j                  d             y |d	k(  r&|r$| j                  |       | j                  d       y | j                  d       y )
Nr   r   )changedr   TF)computed)r   backupvolume_backupr   )paramsconnblock_storagefind_backupansible
check_mode	exit_json_will_change_createto_dict_delete)selfr   r   r   s       q/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/openstack/cloud/plugins/modules/volume_backup.pyrunzVolumeBackupModule.run   s   {{6"G$((44T:<<""NN4#4#4UF#CNDIf\\^FNN4"(..%."@)/)G  I iF NN5"(..%."@)/)G  I h6LL NN4N( NN5N)    c                 X   t               }dD ]$  }| j                  |   | j                  |   ||<   & | j                  d   }| j                  j                  j	                  |d      }|j
                  |d<   | j                  d   }|r6| j                  j                  j                  |d      }|j
                  |d<    | j                  j                  j                  di |}| j                  d   r5| j                  j                  j                  |d	| j                  d
         }|S )N)r   r   r   r   r   r   F)ignore_missing	volume_idr   snapshot_idwait	availabletimeout)statusr4    )	r   r!   r"   r#   find_volumeidfind_snapshotcreate_backupwait_for_status)r,   argskvolume_name_or_idr   snapshot_name_or_idr   r   s           r-   r)   zVolumeBackupModule._create   s$   v 	)A{{1~)++a.Q	)
 !KK1((445FDI 5 K"II["kk*5yy..<<#E = ;H"*++D6((66>>;;vYY,,<<{Y1G = IF r/   c                     | j                   j                  j                  |       | j                  d   r5| j                   j                  j	                  || j                  d          y y )Nr4   r6   )r4   )r"   r#   delete_backupr!   wait_for_delete)r,   r   s     r-   r+   zVolumeBackupModule._delete   sV    		--f5;;vII##33T[[3 4 5 r/   c                 4    |dk(  r|sy|dk(  r|ry|dk(  r|ryy)Nr   TFr   r8   )r,   r   r   s      r-   r(   zVolumeBackupModule._will_change   s0    IfiF h6 r/   N)
__name__
__module____qualname__r   argument_specmodule_kwargsr.   r)   r+   r(   r8   r/   r-   r   r      s    "7!895v.E!'%2O5 6"4.)9:9x.CDvM i(,
 !	M*:45r/   r   c                  &    t               }  |         y )N)r   )modules    r-   mainrM     s    !F
Hr/   __main__N)DOCUMENTATIONRETURNEXAMPLESBansible_collections.openstack.cloud.plugins.module_utils.openstackr   r   rM   rF   r8   r/   r-   <module>rS      sK   2hO
b$ _^ ^B
 zF r/   