
    Vh                         d Z dZdZ	 ddlZddlmZ ddlmZ ddl	m
Z d Zd	 Zd
 Zd Zedk(  r e        yy# e$ r Y 3w xY w)ac  
---
module: elasticache_snapshot
version_added: 1.0.0
short_description: Manage cache snapshots in Amazon ElastiCache
description:
  - Manage cache snapshots in Amazon ElastiCache.
  - Returns information about the specified snapshot.
author:
  - "Sloane Hertel (@s-hertel)"
options:
  name:
    description:
      - The name of the snapshot we want to create, copy, delete.
    required: true
    type: str
  state:
    description:
      - Actions that will create, destroy, or copy a snapshot.
    required: true
    choices: ['present', 'absent', 'copy']
    type: str
  replication_id:
    description:
      - The name of the existing replication group to make the snapshot.
    type: str
  cluster_id:
    description:
      - The name of an existing cache cluster in the replication group to make the snapshot.
    type: str
  target:
    description:
      - The name of a snapshot copy.
    type: str
  bucket:
    description:
      - The s3 bucket to which the snapshot is exported.
    type: str
extends_documentation_fragment:
  - amazon.aws.common.modules
  - amazon.aws.region.modules
  - amazon.aws.boto3
a  
# Note: These examples do not set authentication details, see the AWS Guide for details.

- name: 'Create a snapshot'
  community.aws.elasticache_snapshot:
    name: 'test-snapshot'
    state: 'present'
    cluster_id: '{{ cluster }}'
    replication_id: '{{ replication }}'
aX  
response_metadata:
  description: response metadata about the snapshot
  returned: always
  type: dict
  sample:
    http_headers:
      content-length: 1490
      content-type: text/xml
      date: 'Tue, 07 Feb 2017 16:43:04 GMT'
      x-amzn-requestid: 7f436dea-ed54-11e6-a04c-ab2372a1f14d
    http_status_code: 200
    request_id: 7f436dea-ed54-11e6-a04c-ab2372a1f14d
    retry_attempts: 0
snapshot:
  description: snapshot data
  returned: always
  type: dict
  sample:
    auto_minor_version_upgrade: true
    cache_cluster_create_time: '2017-02-01T17:43:58.261000+00:00'
    cache_cluster_id: test-please-delete
    cache_node_type: cache.m1.small
    cache_parameter_group_name: default.redis3.2
    cache_subnet_group_name: default
    engine: redis
    engine_version: 3.2.4
    node_snapshots:
      cache_node_create_time: '2017-02-01T17:43:58.261000+00:00'
      cache_node_id: 0001
      cache_size:
    num_cache_nodes: 1
    port: 11211
    preferred_availability_zone: us-east-1d
    preferred_maintenance_window: wed:03:00-wed:04:00
    snapshot_name: deletesnapshot
    snapshot_retention_limit: 0
    snapshot_source: manual
    snapshot_status: creating
    snapshot_window: 10:00-11:00
    vpc_id: vpc-c248fda4
changed:
  description: if a snapshot has been created, deleted, or copied
  returned: always
  type: bool
  sample:
    changed: true
    N)camel_dict_to_snake_dict)is_boto3_error_code)AnsibleCommunityAWSModulec                     	 |j                  |||      }d}||fS # t        d      $ r
 i }d}Y ||fS t        j                  j                  $ r }| j                  |d       Y d}~fS d}~ww xY w)zCreate an ElastiCache backup.)ReplicationGroupIdCacheClusterIdSnapshotNameTSnapshotAlreadyExistsFaultFzUnable to create the snapshot.msgN)create_snapshotr   botocore
exceptionsClientErrorfail_json_aws)module
connectionreplication_id
cluster_idnameresponsechangedes           v/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/aws/plugins/modules/elasticache_snapshot.pycreater   {   s    	F---jW[ . 
  W ;<  W ** FQ$DEEWFs    A/A/A**A/c                     	 |j                  |||      }d}||fS # t        j                  j                  t        j                  j                  f$ r }| j                  |d       Y d}~fS d}~ww xY w)zCopy an ElastiCache backup.)SourceSnapshotNameTargetSnapshotNameTargetBucketTzUnable to copy the snapshot.r   N)copy_snapshotr   r   r   BotoCoreErrorr   )r   r   r   targetbucketr   r   r   s           r   copyr$      s    D++tX^ms+t W ++X-@-@-N-NO DQ$BCCWDs    7A3A..A3c                 (   	 |j                  |      }d}||fS # t        d      $ r
 i }d}Y ||fS t        d      $ r | j                  d       Y fS t        j                  j
                  $ r }| j                  |d       Y d	}~fS d	}~ww xY w)
zDelete an ElastiCache backup.)r	   TSnapshotNotFoundFaultFInvalidSnapshotStatezError: InvalidSnapshotState. The snapshot is not in an available state or failed state to allow deletion.You may need to wait a few minutes.r   zUnable to delete the snapshot.N)delete_snapshotr   	fail_jsonr   r   r   r   )r   r   r   r   r   r   s         r   deleter*      s    F--4-@ W 67  W 56 
@ 	 	
 W ** FQ$DEEWFs     BBB1BBc            
      4   t        t        dd      t        ddg d      t        d      t        d      t        d      t        d            } t        |       }|j                  j                  d	      }|j                  j                  d
      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }	 |j	                  d      }d}
i }|dk(  r2t        ||f      s|j                  d       t        ||||      \  }}
nL|dk(  rt        ||      \  }}
n6|dk(  r1t        ||f      s|j                  d       t        ||||      \  }}
t        dd|
it        |      } |j                   di | y # t
        j                  j                  t
        j                  j                  f$ r}	|j                  |	d       Y d }	~	d }	~	ww xY w)NTstr)requiredtype)presentabsentr$   )r-   r.   choices)r.   )r   stater   r   r"   r#   )argument_specr   r2   r   r   r"   r#   elasticachezFailed to connect to AWSr   Fr/   zGThe state 'present' requires options: 'replication_id' and 'cluster_id'r0   r$   z9The state 'copy' requires options: 'target' and 'bucket'.r    )dictAnsibleAWSModuleparamsgetclientr   r   r   r!   r   allr)   r   r*   r$   r   	exit_json)r3   r   r   r2   r   r   r"   r#   r   r   r   r   facts_results                r   mainr>      s   4e,Du6ST'U#M M:F==V$DMMg&E]]&&'78N""<0J]]x(F]]x(F@]]=1
 GH	NJ/0!jk"6:~zSWX'	(	"6:t<'	&FF#$!\] T66J'NN+CH+MNLF$|$' ++X-@-@-N-NO @Q$>??@s   G 7H:HH__main__)DOCUMENTATIONEXAMPLESRETURNr   ImportError0ansible.module_utils.common.dict_transformationsr   <ansible_collections.amazon.aws.plugins.module_utils.botocorer   >ansible_collections.community.aws.plugins.module_utils.modulesr   r7   r   r$   r*   r>   __name__r5       r   <module>rI      sn   *X	/
b	 V \ x((%V zF E  		s   8 A A 