
    Vh)                     z    d dl mZmZmZ eZddgddZdZdZdZ	d d	l
mZ d d
lmZmZ d dlZd Zedk(  r e        yy)    )absolute_importdivisionprint_functionz1.1preview	community)metadata_versionstatussupported_bya  
---
module: mso_backup
short_description: Manages backups
description:
- Manage backups on Cisco ACI Multi-Site.
author:
- Shreyas Srish (@shrsr)
- Lionel Hercot (@lhercot)
- Sabari Jaganathan (@sajagana)
options:
  location_type:
    description:
    - The type of location for the backup to be stored
    type: str
    choices: [ local, remote]
    default: local
  backup:
    description:
    - The name given to the backup
    - C(backup) is mutually exclusive with C(backup_id). Only use one of the two.
    type: str
    aliases: [ name ]
  backup_id:
    description:
    - The id of a specific backup
    - C(backup_id) is mutually exclusive with C(backup). Only use one of the two.
    type: str
    aliases: [ id ]
  remote_location:
    description:
    - The remote location's name where the backup should be stored
    type: str
  remote_path:
   description:
    - This path is relative to the remote location.
    - A '/' is automatically added between the remote location folder and this path.
    - This folder structure should already exist on the remote location.
   type: str
  description:
    description:
    - Brief information about the backup.
    type: str
  destination:
    description:
    - Location where to download the backup to
    type: str
  state:
    description:
    - Use C(present) or C(absent) for adding or removing.
    - Use C(query) for listing an object or multiple objects.
    - Use C(upload) for uploading backup.
    - Use C(restore) for restoring backup.
    - Use C(download) for downloading backup.
    - Use C(move) for moving backup from local to remote location.
    type: str
    choices: [ absent, present, query, upload, restore, download, move ]
    default: present
extends_documentation_fragment: cisco.mso.modules
a  
- name: Create a new local backup
  cisco.mso.mso_backup:
    host: mso_host
    username: admin
    password: SomeSecretPassword
    backup: Backup
    description: via Ansible
    location_type: local
    state: present

- name: Create a new remote backup
  cisco.mso.mso_backup:
    host: mso_host
    username: admin
    password: SomeSecretPassword
    backup: Backup
    description: via Ansible
    location_type: remote
    remote_location: ansible_test
    state: present

- name: Move backup to remote location
  cisco.mso.mso_backup:
    host: mso_host
    username: admin
    password: SomeSecretPassword
    backup: Backup0
    remote_location: ansible_test
    remote_path: test
    state: move

- name: Download a backup
  cisco.mso.mso_backup:
    host: mso_host
    username: admin
    password: SomeSecretPassword
    backup: Backup
    destination: ./
    state: download

- name: Upload a backup
  cisco.mso.mso_backup:
    host: mso_host
    username: admin
    password: SomeSecretPassword
    backup: ./Backup
    state: upload

- name: Restore a backup
  cisco.mso.mso_backup:
    host: mso_host
    username: admin
    password: SomeSecretPassword
    backup: Backup
    state: restore

- name: Remove a Backup
  cisco.mso.mso_backup:
    host: mso_host
    username: admin
    password: SomeSecretPassword
    backup: Backup
    state: absent

- name: Query a backup
  cisco.mso.mso_backup:
    host: mso_host
    username: admin
    password: SomeSecretPassword
    backup: Backup
    state: query
  register: query_result

- name: Query a backup with its complete name
  cisco.mso.mso_backup:
    host: mso_host
    username: admin
    password: SomeSecretPassword
    backup: Backup_20200721220043
    state: query
  register: query_result

- name: Query all backups
  cisco.mso.mso_backup:
    host: mso_host
    username: admin
    password: SomeSecretPassword
    state: query
  register: query_result

)AnsibleModule)	MSOModulemso_argument_specNc                  4   t               } | j                  t        ddddg      t        d      t        ddg      t        ddg      t        d      t        d      t        dd	g d
      t        d             t        | ddddggddddgdgdd	dggddddgdgddddgdgddddgdgdddggddddgdgddddggg	dg      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }|j                  j                  d      }	t        |      }
g }|
j                  dd      |
_        |s|r|
j                  r|
j                  }g |
_        |D ]  }|r||j                  d      k(  s>|s||j                  d      j                  d      d    k(  s||j                  d      k(  sW|
j                  j                  |       |j                  |j                  d              |d!k(  r|
j                          n|dk(  r|
j                  |
_        t        |
j                        d"kD  r;|
j                  j                  d#j!                  d$j#                  |            %       npt        |
j                        d"k(  rX|j$                  ri |
_        nD|
j'                  d&j!                  |
j                  d    j                  d      '      d()      |
_        |
j                          n|d	k(  r|
j                  |
_        t        |||*      }|dk(  rg|
j)                  |      }|j                  |j                  d      +       |r3d,j!                  |j                  d-      |      }|j                  |.       ||
_        |j$                  r|
j*                  |
_        n|
j'                  d/d0|1      |
_        |
j                          n |dk(  r|
j                  |
_        |j$                  r|
j*                  |
_        n	 d2}t               }|
j,                  d3k(  rR|||
j                  j                  d4%       |
j)                  |      }d5j!                  |j                  d            }n6t        t.        j0                  j3                  |      t5        |d6      d7f8      }|
j7                  ||9      |
_        |
j                          t        |
j                        d k(  r-|
j                  j                  d=j!                  |      %       n t        |
j                        d"kD  r<|
j                  j                  d#j!                  d$j#                  |            %       n|dk(  rv|
j                  |
_        |j$                  r|
j*                  |
_        nw|
j'                  d>j!                  |
j                  d    j                  d      '      d?)      |
_        n1|dk(  rt|
j                  |
_        |j$                  r|
j*                  |
_        n|
j;                  d@j!                  |
j                  d    j                  d      '      |	A      |
_        n|dk(  r|
j                  |
_        |
j)                  |      }d,j!                  |j                  d-      |      }t        |j                  d      ||
j                  d    j                  d      B      }|j$                  r|
j*                  |
_        n|
j'                  dCd0|1      |
_        |
j                          y # t8        $ rX}|
j                  j                  d:j!                  |d$j#                  |j                  d;      d<d              %       Y d }~d }~ww xY w)DNstrlocalremote)typedefaultchoices)r   name)r   aliasesidpresent)absentr   queryuploadrestoredownloadmove)location_typedescriptionbackup	backup_idremote_locationremote_pathstatedestinationTr    r$   r&   r   r"   r#   r   r   r   r'   r   r%   )r"   r#   )argument_specsupports_check_moderequired_ifmutually_exclusiver!   zbackups/backupRecordsbackupRecords)key_r   r      zOMultiple backups with same name found. Existing backups with similar names: {0}z, )msgzbackups/backupRecords/{id})r   DELETE)method)r   r!   locationType)remoteLocationIdz{0}/{1}path)
remotePathbackupsPOST)r2   datazbackups/uploadndz\NDO backup upload failed: remote_location and remote_path are required for NDO backup uploadzbackups/remoteUpload/{0}rbzapplication/x-gzip)r   )fieldsz-Upload failed due to: {0}, Backup file: '{1}'/zBackup '{0}' does not existzbackups/{id}/restorePUTzbackups/{id}/download)r'   )r4   r6   backupRecordIdzbackups/remote-location)r   updatedictr   paramsgetr   
query_objsexistingsplitappend	exit_jsonpreviouslenmodule	fail_jsonformatjoin
check_moderequestlookup_remote_locationproposedplatformosr5   basenameopenrequest_upload	Exceptionrequest_download)r(   rL   r!   r    r&   r"   r#   r$   r%   r'   msobackup_namesr9   backup_infopayloadremote_location_inforequest_urlerrors                     h/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cisco/mso/plugins/modules/mso_backup.pymainrc      s   %'Mw(@STe$1ED62%(e$y  ;B  Ce$  	 # h):(;<h; 7>i(,h; 7>i(K!8$?j8["94@j=/2fx5t<f0-@A

 $
F& --##M2KMM%%o6MMMg&E]]x(F!!+.Imm''(9:O--##M2K--##M2K
F
CL>>"9>OCL<<<<DCL# A){t/D"D+//&*A*G*G*LQ*O OSY]h]l]lms]tStLL''4 ''(?@A 	(	||s||q JJ  %v%}%}  C  H  H  IU  V  &W   X!#  !"{{+G+N+NRUR^R^_`RaReRefjRk+N+lu}{~	)	||F-XH$#&#=#=o#N NN,@,D,DT,JNK'../C/G/G/OQ\]+6<<CL;;yg;NCL	(	||<<CLK.&<<4'&.+2E

,,  2P,  Q+.+E+Eo+V("<"C"CDXD\D\]aDb"cK")9)9&)A4PTCUWk(lmG"11+g1N 	
3<<A

!>!E!Ef!MN	S\\	Q	

!r!y!yz~  {D  {D  EQ  {R  "S  	T	)	||<<CL;;'='D'DUVH[H[\`Ha'D'bkp;qCL	*	||<<CL//0G0N0NRUR^R^_`RaReRefjRk0N0l  {F/  GCL	&||"99/J&&';'?'?'GU(<(@(@(FS^oro{o{|}o~  pC  pC  DH  pI  J<<CL;;'@V];^CLMMOC  K

$$)X)_)_`egkgpgpqwq}q}  B  rC  DF  DG  rH  hI  *J$  K  KKs   B;^6 6	`?A``__main__)
__future__r   r   r   r   __metaclass__ANSIBLE_METADATADOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   6ansible_collections.cisco.mso.plugins.module_utils.msor   r   rU   rc   __name__     rb   <module>rp      sa    A @(-)Vab ;zZx
 5 _ 	M` zF ro   