
    VhX                     z    d dl mZmZmZ eZdZdZdZd dl	m
Z
 ddlmZmZ  G d d	e      Zd
 Zedk(  r e        yy)    )absolute_importdivisionprint_functionu  
---
module: snapshot
short_description: Manages snapshots on Vultr
description:
  - Create and remove snapshots.
version_added: "1.7.0"
author: "René Moser (@resmo)"
options:
  description:
    description:
      - Description of the snapshot.
    required: true
    aliases: [ name ]
    type: str
  instance:
    description:
      - The description or ID of the instance from which to take the snapshot.
      - Mutually exclusive with I(url).
      - I(instance) or I(url) is required if I(state=present).
    type: str
  url:
    description:
      - The URL of the snapshot image (RAW) to be uploaded.
      - Mutually exclusive with I(instance).
      - I(instance) or I(url) is required if I(state=present).
    type: str
  state:
    description:
      - State of the snapshot.
    default: present
    choices: [ present, absent ]
    type: str
extends_documentation_fragment:
  - vultr.cloud.vultr_v2
a  
- name: Ensure a snapshot is present
  vultr.cloud.snapshot:
    description: my snapshot of my instance
    instance: my instance

- name: Ensure a snapshot is present
  vultr.cloud.snapshot:
    description: debian 11 generic
    url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-generic-amd64.raw

- name: Ensure a snapshot is absent
  vultr.cloud.snapshot:
    description: my snapshot of my instance
    state: absent
a"  
---
vultr_api:
  description: Response from Vultr API with a few additions/modification.
  returned: success
  type: dict
  contains:
    api_timeout:
      description: Timeout used for the API requests.
      returned: success
      type: int
      sample: 60
    api_retries:
      description: Amount of max retries for the API requests.
      returned: success
      type: int
      sample: 5
    api_retry_max_delay:
      description: Exponential backoff delay in seconds between retries up to this max delay value.
      returned: success
      type: int
      sample: 12
    api_endpoint:
      description: Endpoint used for the API requests.
      returned: success
      type: str
      sample: "https://api.vultr.com/v2"
vultr_snapshot:
  description: Response from Vultr API.
  returned: success
  type: dict
  contains:
    id:
      description: ID of the snapshot.
      returned: success
      type: str
      sample: cb676a46-66fd-4dfb-b839-443f2e6c0b60
    description:
      description: Description of the snapshot.
      returned: success
      type: str
      sample: my vpc
    date_created:
      description: Date the snapshot was created.
      returned: success
      type: str
      sample: "2020-10-10T01:56:20+00:00"
    size:
      description: Size of the snapshot.
      returned: success
      type: int
      sample: 42949672960
    compressed_size:
      description: Compressed size of the snapshot.
      returned: success
      type: int
      sample: 949678560
    status:
      description: Status of the snapshot.
      returned: success
      type: str
      sample: complete
    os_id:
      description: ID of the OS.
      returned: success
      type: int
      sample: 215
    app_id:
      description: ID of the app.
      returned: success
      type: int
      sample: 0
)AnsibleModule   )AnsibleVultrvultr_argument_specc                   $     e Zd Zd Z fdZ xZS )AnsibleVultrSnapshotc                 .    | j                  ddddd      S )Nlabelinstancez
/instances	instancesT)key_name	param_keypath
result_keyfail_not_found)query_filter_list_by_name)selfs    h/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/vultr/cloud/plugins/modules/snapshot.pyget_instancez!AnsibleVultrSnapshot.get_instance   s)    -- " . 
 	
    c                 &    d}t         fd|D              s. j                  j                  ddj                  |      z          j                  j                  j                  d      0 j                  j                  d        j                  dz    _        nE j                         d    j                  j                  d	<    j                  j                  d	       t        t         3         }d
 _        |r j                  |ddg      }|S )N)urlr   c              3   l   K   | ]+  }j                   j                  j                  |      d u - y w)N)moduleparamsget).0xr   s     r   	<genexpr>z.AnsibleVultrSnapshot.create.<locals>.<genexpr>   s+     MQ4;;%%))!,D8Ms   14z>missing required arguements, one of the following required: %sz, )msgr   z/create-from-urlidinstance_id
/snapshotsstatuscomplete)resourcekeystates)anyr   	fail_jsonjoinr   r   resource_create_param_keysappendresource_pathr   superr   createwait_for_state)r   
param_keysr)   	__class__s   `  r   r3   zAnsibleVultrSnapshot.create   s    (
M*MMKK!!&fimirirs}i~&~!;;!!%(4++2259!%!3!36H!HD040A0A0CD0IDKK}-++22=A-t;= ***H(T^S_*`Hr   )__name__
__module____qualname__r   r3   __classcell__)r6   s   @r   r   r      s    
 r   r   c                  v   t               } | j                  t        t        dddg      t        d      t        d      t        dddgd      	             t        | d
d      }t	        |ddddgdgdd      }|j
                  j                  d      dk(  r|j                          y |j                          y )NstrTname)typerequiredaliases)r>   presentabsent)r>   choicesdefault)descriptionr   r   state))r   r   )argument_specmutually_exclusivesupports_check_modevultr_snapshotr&   snapshotrE   PUT)r   	namespacer1   ressource_result_key_singularr/   resource_update_param_keysresource_key_nameresource_update_methodrF   )	r	   updatedictr   r   r   r   rB   rA   )rG   r   vultrs      r   mainrU      s    ')M%$Iu%% EIx+@)T		
 #1 F !""&0$
 $
 ($E }}!X-r   __main__N)
__future__r   r   r   r>   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   module_utils.vultr_v2r   r	   r   rU   r7    r   r   <module>r_      sZ    A @#J"H
T 5 E< D#L zF r   