§
    ÎÑßj:?  ã                   ó¬   — d gZ ddlmZmZmZmZ ddlmZmZ ddl	m
Z
mZ ddlmZ dZdZ G d„ d	e
¦  «        Z G d
„ de¦  «        Z G d„ d e¦  «        ZdS )ÚGCEBackupDriveré    )ÚBackupDriverÚBackupTargetÚBackupTargetJobÚBackupTargetRecoveryPoint)ÚBackupTargetTypeÚBackupTargetJobStatusType)ÚGoogleResponseÚGoogleBaseConnection)Ú
parse_dateÚv1é´   c                   ó   — e Zd ZdS )ÚGCEResponseN)Ú__name__Ú
__module__Ú__qualname__© ó    úO/opt/saltstack/salt/lib/python3.11/site-packages/libcloud/backup/drivers/gce.pyr   r       s   € € € € € Ø€Dr   r   c                   óF   ‡ — e Zd ZdZdZeZ	 	 	 dˆ fd„	Zˆ fd„Zˆ fd„Z	ˆ xZ
S )ÚGCEConnectiona{  
    Connection class for the GCE driver.

    GCEConnection extends :class:`google.GoogleBaseConnection` for 2 reasons:
      1. modify request_path for GCE URI.
      2. Implement gce_params functionality described below.

    If the parameter gce_params is set to a dict prior to calling request(),
    the URL parameters will be updated to include those key/values FOR A
    SINGLE REQUEST. If the response contains a nextPageToken,
    gce_params['pageToken'] will be set to its value. This can be used to
    implement paging in list:

    >>> params, more_results = {'maxResults': 2}, True
    >>> while more_results:
    ...     driver.connection.gce_params=params
    ...     driver.ex_list_urlmaps()
    ...     more_results = 'pageToken' in params
    ...
    [<GCEUrlMap id="..." name="cli-map">, <GCEUrlMap id="..." name="lc-map">]
    [<GCEUrlMap id="..." name="web-map">]
    zwww.googleapis.comNc                 ó”   •—  t          ¦   «         j        ||f|||dœ|¤Ž d                     t          |¦  «        | _        i | _        d S )N)ÚsecureÚ	auth_typeÚcredential_fileú/compute/{}/projects/{})ÚsuperÚ__init__ÚformatÚAPI_VERSIONÚrequest_pathÚ
gce_params)	ÚselfÚuser_idÚkeyr   r   r   ÚprojectÚkwargsÚ	__class__s	           €r   r   zGCEConnection.__init__?   sj   ø€ ð 	�‰ŒÔØØð	
ð ØØ+ð	
ð 	
ð ð	
ð 	
ð 	
ð 6×<Ò<½[È'ÑRÔRˆÔØˆŒˆˆr   c                 ó˜   •— t          ¦   «                              ||¦  «        \  }}| j        r|                     | j        ¦  «         ||fS )zŒ
        Update URL parameters with values from self.gce_params.

        @inherits: :class:`GoogleBaseConnection.pre_connect_hook`
        )r   Úpre_connect_hookr#   Úupdate)r$   ÚparamsÚheadersr)   s      €r   r+   zGCEConnection.pre_connect_hookT   sJ   ø€ õ  ™'œ'×2Ò2°6¸7ÑCÔC‰ˆ�ØŒ?ð 	+Ø�MŠM˜$œ/Ñ*Ô*Ð*Ø�wˆÐr   c                 ó¶   •—  t          ¦   «         j        |i |¤Ž}| j        r7d|j        v r|j        d         | j        d<   nd| j        v r| j        d= d| _        |S )zŠ
        Perform request then do GCE-specific processing of URL params.

        @inherits: :class:`GoogleBaseConnection.request`
        ÚnextPageTokenÚ	pageTokenN)r   Úrequestr#   Úobject)r$   Úargsr(   Úresponser)   s       €r   r2   zGCEConnection.request_   sq   ø€ ð #•5‘7”7”? DÐ3¨FÐ3Ð3ˆð Œ?ð 	#Ø (¤/Ð1Ð1Ø/7¬¸Ô/O�” Ñ,Ð,Ø ¤Ð/Ð/Ø”O KÐ0Ø"ˆDŒOàˆr   )NNN)r   r   r   Ú__doc__Úhostr   ÚresponseClsr   r+   r2   Ú__classcell__©r)   s   @r   r   r   $   s�   ø€ € € € € ðð ð.  €DØ€Kð ØØðð ð ð ð ð ð*	ð 	ð 	ð 	ð 	ðð ð ð ð ð ð ð ð r   r   c                   óò   ‡ — e Zd ZdZdZeZ	 	 	 	 	 dˆ fd„	Zd„ Zd„ Z	e
j        dfd„Ze
j        dfd„Ze
j        dfd	„Zd
„ Zd„ Zdd„Zdd„Zdd„Zd„ Zd„ Zdd„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z d„ Z!ˆ xZ"S )r   z#Google Compute Engine Backup Driverzhttp://cloud.google.com/Nc                 óö   •— |st          d¦  «        ‚|| _        || _        || _        |p	d| j        z   | _         t          ¦   «         j        ||fi |¤Ž d                     t          | j        ¦  «        | _	        dS )a�  
        :param  user_id: The email address (for service accounts) or Client ID
                         (for installed apps) to be used for authentication.
        :type   user_id: ``str``

        :param  key: The RSA Key (for service accounts) or file path containing
                     key or Client Secret (for installed apps) to be used for
                     authentication.
        :type   key: ``str``

        :keyword  project: Your GCE project name. (required)
        :type     project: ``str``

        :keyword  auth_type: Accepted values are "SA" or "IA" or "GCE"
                             ("Service Account" or "Installed Application" or
                             "GCE" if libcloud is being used on a GCE instance
                             with service account enabled).
                             If not supplied, auth_type will be guessed based
                             on value of user_id or if the code is being
                             executed in a GCE instance.
        :type     auth_type: ``str``

        :keyword  scopes: List of authorization URLs. Default is empty and
                          grants read/write to Compute, Storage, DNS.
        :type     scopes: ``list``

        :keyword  credential_file: Path to file for caching authentication
                                   information used by GCEConnection.
        :type     credential_file: ``str``
        z7Project name must be specified using "project" keyword.z~/.gce_libcloud_auth.r   N)
Ú
ValueErrorr   r'   Úscopesr   r   r   r    r!   Ú	base_path)	r$   r%   r&   r'   r   r>   r   r(   r)   s	           €r   r   zGCEBackupDriver.__init__x   sŠ   ø€ ðP ð 	[ÝÐYÑZÔZÐZà"ˆŒØˆŒØˆŒØ.Ð]Ð2NÐQUÔQ]Ñ2]ˆÔà�‰ŒÔ˜ #Ð0Ð0¨Ð0Ð0Ð0ð 3×9Ò9½+ÀtÄ|ÑTÔTˆŒˆˆr   c                 ó   — t           j        gS )z‚
        Get a list of backup target types this driver supports

        :return: ``list`` of :class:``BackupTargetType``
        )r   ÚVOLUME©r$   s    r   Úget_supported_target_typesz*GCEBackupDriver.get_supported_target_types®   s   € õ !Ô'Ð(Ð(r   c                 ó    — t          d¦  «        ‚)z[
        List all backuptargets

        :rtype: ``list`` of :class:`BackupTarget`
        z,list_targets not implemented for this driver©ÚNotImplementedErrorrB   s    r   Úlist_targetszGCEBackupDriver.list_targets¶   s   € õ "Ð"PÑQÔQÐQr   c                 ó,   — |                       |¦  «        S )aÁ  
        Creates a new backup target

        :param name: Name of the target
        :type name: ``str``

        :param address: The volume ID.
        :type address: ``str``

        :param type: Backup target type (Physical, Virtual, ...).
        :type type: :class:`BackupTargetType`

        :param extra: (optional) Extra attributes (driver specific).
        :type extra: ``dict``

        :rtype: Instance of :class:`BackupTarget`
        ©Úex_get_target_by_source)r$   ÚnameÚaddressÚtypeÚextras        r   Úcreate_targetzGCEBackupDriver.create_target¾   ó   € ð& ×+Ò+¨GÑ4Ô4Ð4r   c                 ó¦   — |j         d         }|�4|                      |j        |d         d         t          j        d¬¦  «        S t          d¦  «        ‚)a’  
        Creates a new backup target from an existing node

        :param node: The Node to backup
        :type  node: ``Node``

        :param type: Backup target type (Physical, Virtual, ...).
        :type type: :class:`BackupTargetType`

        :param extra: (optional) Extra attributes (driver specific).
        :type extra: ``dict``

        :rtype: Instance of :class:`BackupTarget`
        ÚdisksNr   Úsource)rK   rL   rM   rN   z$Node does not have any block devices)rN   rO   rK   r   rA   ÚRuntimeError)r$   ÚnoderM   rN   rR   s        r   Úcreate_target_from_nodez'GCEBackupDriver.create_target_from_nodeÓ   s^   € ð  ”
˜7Ô#ˆØÐØ×%Ò%Ø”YØ˜aœ Ô*Ý%Ô,Øð	 &ñ ô ð õ ÐEÑFÔFÐFr   c                 ó    — t          d¦  «        ‚)a©  
        Creates a new backup target from an existing storage container

        :param node: The Container to backup
        :type  node: ``Container``

        :param type: Backup target type (Physical, Virtual, ...).
        :type type: :class:`BackupTargetType`

        :param extra: (optional) Extra attributes (driver specific).
        :type extra: ``dict``

        :rtype: Instance of :class:`BackupTarget`
        z<create_target_from_container not implemented for this driverrE   )r$   Ú	containerrM   rN   s       r   Úcreate_target_from_containerz,GCEBackupDriver.create_target_from_containerî   s   € õ "Ð"`ÑaÔaÐar   c                 ó,   — |                       |¦  «        S )aÚ  
        Update the properties of a backup target

        :param target: Backup target to update
        :type  target: Instance of :class:`BackupTarget`

        :param name: Name of the target
        :type name: ``str``

        :param address: Hostname, FQDN, IP, file path etc.
        :type address: ``str``

        :param extra: (optional) Extra attributes (driver specific).
        :type extra: ``dict``

        :rtype: Instance of :class:`BackupTarget`
        rI   )r$   ÚtargetrK   rL   rN   s        r   Úupdate_targetzGCEBackupDriver.update_targetÿ   rP   r   c                 ó    — t          d¦  «        ‚)z‘
        Delete a backup target

        :param target: Backup target to delete
        :type  target: Instance of :class:`BackupTarget`
        z-delete_target not implemented for this driverrE   ©r$   r[   s     r   Údelete_targetzGCEBackupDriver.delete_target  s   € õ "Ð"QÑRÔRÐRr   c                 ót   — d}| j                              |d¬¦  «        j        }|                      ||¦  «        S )aç  
        List the recovery points available for a target

        :param target: Backup target to delete
        :type  target: Instance of :class:`BackupTarget`

        :param start_date: The start date to show jobs between (optional)
        :type  start_date: :class:`datetime.datetime`

        :param end_date: The end date to show jobs between (optional)
        :type  end_date: :class:`datetime.datetime``

        :rtype: ``list`` of :class:`BackupTargetRecoveryPoint`
        z/global/snapshotsÚGET©Úmethod)Ú
connectionr2   r3   Ú_to_recovery_points)r$   r[   Ú
start_dateÚend_dater2   r5   s         r   Úlist_recovery_pointsz$GCEBackupDriver.list_recovery_points  s<   € ð &ˆØ”?×*Ò*¨7¸5Ð*ÑAÔAÔHˆØ×'Ò'¨°&Ñ9Ô9Ð9r   c                 ó    — t          d¦  «        ‚)aÈ  
        Recover a backup target to a recovery point

        :param target: Backup target to delete
        :type  target: Instance of :class:`BackupTarget`

        :param recovery_point: Backup target with the backup data
        :type  recovery_point: Instance of :class:`BackupTarget`

        :param path: The part of the recovery point to recover (optional)
        :type  path: ``str``

        :rtype: Instance of :class:`BackupTargetJob`
        z.recover_target not implemented for this driverrE   )r$   r[   Úrecovery_pointÚpaths       r   Úrecover_targetzGCEBackupDriver.recover_target0  s   € õ "Ð"RÑSÔSÐSr   c                 ó    — t          d¦  «        ‚)am  
        Recover a backup target to a recovery point out-of-place

        :param target: Backup target with the backup data
        :type  target: Instance of :class:`BackupTarget`

        :param recovery_point: Backup target with the backup data
        :type  recovery_point: Instance of :class:`BackupTarget`

        :param recovery_target: Backup target with to recover the data to
        :type  recovery_target: Instance of :class:`BackupTarget`

        :param path: The part of the recovery point to recover (optional)
        :type  path: ``str``

        :rtype: Instance of :class:`BackupTargetJob`
        z;recover_target_out_of_place not implemented for this driverrE   )r$   r[   rj   Úrecovery_targetrk   s        r   Úrecover_target_out_of_placez+GCEBackupDriver.recover_target_out_of_placeA  s   € õ$ "Ð"_Ñ`Ô`Ð`r   c                 óz   ‡— |                       |¦  «        }t          t          ˆfd„|¦  «        ¦  «        d         S )a;  
        Get a specific backup job by ID

        :param target: Backup target with the backup data
        :type  target: Instance of :class:`BackupTarget`

        :param id: Backup target with the backup data
        :type  id: Instance of :class:`BackupTarget`

        :rtype: :class:`BackupTargetJob`
        c                 ó   •— | j         ‰k    S ©N)Úid)Úxrs   s    €r   ú<lambda>z0GCEBackupDriver.get_target_job.<locals>.<lambda>b  s   ø€  Q¤T¨R¢Z€ r   r   )Úlist_target_jobsÚlistÚfilter)r$   r[   rs   Újobss     ` r   Úget_target_jobzGCEBackupDriver.get_target_jobU  s?   ø€ ð ×$Ò$ VÑ,Ô,ˆÝ•FÐ/Ð/Ð/Ð/°Ñ6Ô6Ñ7Ô7¸Ô:Ð:r   c                 ó   — g S )zÜ
        List the backup jobs on a target

        :param target: Backup target with the backup data
        :type  target: Instance of :class:`BackupTarget`

        :rtype: ``list`` of :class:`BackupTargetJob`
        r   r^   s     r   rv   z GCEBackupDriver.list_target_jobsd  s	   € ð ˆ	r   c                 ó  — |j         }d                     |j        d         j         |j         ¦  «        }d|j        d         i}| j                             |d|¬¦  «         |                      |                      |¦  «        |¦  «        S )aC  
        Create a new backup job on a target

        :param target: Backup target with the backup data
        :type  target: Instance of :class:`BackupTarget`

        :param extra: (optional) Extra attributes (driver specific).
        :type extra: ``dict``

        :rtype: Instance of :class:`BackupTargetJob`
        z!/zones/{}/disks/{}/createSnapshotÚzonerS   ÚPOST)rc   Údata)rK   r    rN   rd   Úasync_requestÚ_to_jobÚex_get_snapshot)r$   r[   rN   rK   r2   Úsnapshot_datas         r   Úcreate_target_jobz!GCEBackupDriver.create_target_jobo  s„   € ð Œ{ˆØ5×<Ò<ØŒL˜Ô Ô%ØŒKñ
ô 
ˆð " 6¤<°Ô#9Ð:ˆØŒ×%Ò% g°fÀ=Ð%ÑQÔQÐQØ�|Š|˜D×0Ò0°Ñ6Ô6¸Ñ?Ô?Ð?r   c                 ó    — t          d¦  «        ‚)a3  
        Resume a suspended backup job on a target

        :param target: Backup target with the backup data
        :type  target: Instance of :class:`BackupTarget`

        :param job: Backup target job to resume
        :type  job: Instance of :class:`BackupTargetJob`

        :rtype: ``bool``
        z/resume_target_job not supported for this driverrE   ©r$   r[   Újobs      r   Úresume_target_jobz!GCEBackupDriver.resume_target_job„  ó   € õ "Ð"SÑTÔTÐTr   c                 ó    — t          d¦  «        ‚)a3  
        Suspend a running backup job on a target

        :param target: Backup target with the backup data
        :type  target: Instance of :class:`BackupTarget`

        :param job: Backup target job to suspend
        :type  job: Instance of :class:`BackupTargetJob`

        :rtype: ``bool``
        z0suspend_target_job not supported for this driverrE   r†   s      r   Úsuspend_target_jobz"GCEBackupDriver.suspend_target_job’  s   € õ "Ð"TÑUÔUÐUr   c                 ó    — t          d¦  «        ‚)a)  
        Cancel a backup job on a target

        :param target: Backup target with the backup data
        :type  target: Instance of :class:`BackupTarget`

        :param job: Backup target job to cancel
        :type  job: Instance of :class:`BackupTargetJob`

        :rtype: ``bool``
        z/cancel_target_job not supported for this driverrE   r†   s      r   Úcancel_target_jobz!GCEBackupDriver.cancel_target_job   r‰   r   c                 ó.   ‡ ‡— ˆ ˆfd„|j         D ¦   «         S )Nc                 ó<   •— g | ]}‰                      |‰¦  «        ‘ŒS r   )Ú_to_recovery_point©Ú.0Úitemr$   r[   s     €€r   ú
<listcomp>z7GCEBackupDriver._to_recovery_points.<locals>.<listcomp>¯  s)   ø€ ÐMÐMÐM¸$�×'Ò'¨¨fÑ5Ô5ÐMÐMÐMr   ©Úitems©r$   r   r[   s   ` `r   re   z#GCEBackupDriver._to_recovery_points®  s#   øø€ ØMÐMÐMÐMÐMÀ$Ä*ÐMÑMÔMÐMr   c                 ó|   — |j         }t          |j        ¦  «        }t          |||| j        j        d|i¬¦  «        }|S )Nzsnapshot-id)rs   Údater[   ÚdriverrN   )rs   r   ÚcreationTimestampr   rd   rš   )r$   r“   r[   rs   r™   Úpoints         r   r�   z"GCEBackupDriver._to_recovery_point±  sM   € ØŒWˆÝ˜$Ô0Ñ1Ô1ˆÝ)ØØØØ”?Ô)Ø  "Ð%ð
ñ 
ô 
ˆð ˆr   c                 ó.   ‡ ‡— ˆ ˆfd„|j         D ¦   «         S )Nc                 ó<   •— g | ]}‰                      |‰¦  «        ‘ŒS r   )r�   r‘   s     €€r   r”   z,GCEBackupDriver._to_jobs.<locals>.<listcomp>¾  s'   ø€ ÐBÐBÐB¨t�—’˜T 6Ñ*Ô*ÐBÐBÐBr   r•   r—   s   ` `r   Ú_to_jobszGCEBackupDriver._to_jobs½  s#   øø€ ØBÐBÐBÐBÐB°t´zÐBÑBÔBÐBr   c                 óf   — |j         }t          |t          j        d|| j        j        i ¬¦  «        }|S )Nr   )rs   ÚstatusÚprogressr[   rš   rN   )rs   r   r	   ÚPENDINGrd   rš   )r$   r“   r[   rs   r‡   s        r   r�   zGCEBackupDriver._to_jobÀ  s>   € ØŒWˆÝØÝ,Ô4ØØØ”?Ô)Øð
ñ 
ô 
ˆð ˆ
r   c                 óR   — d|z  }| j                              |d¬¦  «        j        }|S )Nz/global/snapshots/%sra   rb   )rd   r2   r3   )r$   rK   r2   r5   s       r   r‚   zGCEBackupDriver.ex_get_snapshotÌ  s.   € Ø(¨DÑ1ˆØ”?×*Ò*¨7¸5Ð*ÑAÔAÔHˆØˆr   c           	      óX   — t          |||t          j        | j        j        d|i¬¦  «        S )NrS   )rs   rK   rL   rM   rš   rN   )r   r   rA   rd   rš   )r$   rS   s     r   rJ   z'GCEBackupDriver.ex_get_target_by_sourceÑ  s8   € ÝØØØÝ!Ô(Ø”?Ô)Ø˜VÐ$ð
ñ 
ô 
ð 	
r   )NNNNN)NNrr   )#r   r   r   rK   Úwebsiter   ÚconnectionClsr   rC   rG   r   rA   rO   ÚVIRTUALrV   ÚOBJECTrY   r\   r_   rh   rl   ro   rz   rv   r„   rˆ   r‹   r�   re   r�   rŸ   r�   r‚   rJ   r9   r:   s   @r   r   r   s   s  ø€ € € € € Ø0€DØ(€GØ!€Mð
 ØØØØð4Uð 4Uð 4Uð 4Uð 4Uð 4Uðl)ð )ð )ðRð Rð Rð 1AÔ0GÈtð 5ð 5ð 5ð 5ð* 2BÔ1IÐQUð Gð Gð Gð Gð6 <LÔ;RÐZ^ð bð bð bð bð"5ð 5ð 5ð*Sð Sð Sð:ð :ð :ð :ð&Tð Tð Tð Tð"að að að að(;ð ;ð ;ð	ð 	ð 	ð@ð @ð @ð @ð*Uð Uð UðVð Vð VðUð Uð UðNð Nð Nð
ð 
ð 
ðCð Cð Cð
ð 
ð 
ðð ð ð

ð 
ð 
ð 
ð 
ð 
ð 
r   N)Ú__all__Úlibcloud.backup.baser   r   r   r   Úlibcloud.backup.typesr   r	   Úlibcloud.common.googler
   r   Úlibcloud.utils.iso8601r   r!   ÚDEFAULT_TASK_COMPLETION_TIMEOUTr   r   r   r   r   r   ú<module>r°      s7  ðð  Ð
€ðð ð ð ð ð ð ð ð ð ð ð ð NÐ MÐ MÐ MÐ MÐ MÐ MÐ MØ GÐ GÐ GÐ GÐ GÐ GÐ GÐ GØ -Ð -Ð -Ð -Ð -Ð -à€Ø"%Ð ð	ð 	ð 	ð 	ð 	�.ñ 	ô 	ð 	ðLð Lð Lð Lð LÐ(ñ Lô Lð Lð^f
ð f
ð f
ð f
ð f
�lñ f
ô f
ð f
ð f
ð f
r   