
    =Ki                         S SK Jr  S SKJrJr  S SKJr  SSKJr  S SK	r	S SK
r
\
R                  " S5      r " S S	5      rg)
    )ApiException)clientconfig)	ApiClient   )LeaderElectionRecordNleaderelectionc                   8    \ rS rSrS rS rS rS rS rS r	Sr
g	)
ConfigMapLock   c                     [         R                  " 5       U l        SU l        Xl        X l        [        U5      U l        SU l        SSSSS.U l	        g)z|
:param name: name of the lock
:param namespace: namespace
:param identity: A unique identifier that the candidate is using
z(control-plane.alpha.kubernetes.io/leaderN)holderIdentityleaseDurationSecondsacquireTime	renewTime)
r   	CoreV1Apiapi_instance#leader_electionrecord_annotationkeyname	namespacestridentityconfigmap_referencelock_record)selfr   r   r   s       v/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/kubernetes/leaderelection/resourcelock/configmaplock.py__init__ConfigMapLock.__init__   sP     #,,.3]0	"H#' "$(	    c                     U R                   R                  X5      nUR                  R                  nUb  US:X  a$  U R                  S0UR                  l        X0l        gUR                  U R                  5      (       d$  U R                  S0UR                  l        X0l        gU R                  [        R                  " X@R                     5      5      nX0l        SU4$ ! [         a  nSU4s SnA$ SnAff = f)z
:param name: Name of the configmap object information to get
:param namespace: Namespace in which the configmap object is to be searched
:return: 'True, election record' if object found else 'False, exception response'
N )TNTF)r   read_namespaced_config_mapmetadataannotationsr   r   getget_lock_objectjsonloadsr   )r   r   r   api_responser$   r   es          r   r%   ConfigMapLock.get-   s    	,,GGXL '//;;K"kR&7595]5]_a4b%%1+7(! ??4#K#KLL595]5]_a4b%%1+7(!..tzz+FnFn:o/pqK'3$$$ 	!8O	s+   AC  AC $:C 
C7)C2,C72C7c           	      <   [         R                  " UU R                  [        R                  " U R                  U5      5      0S.S9n U R                  R                  X$SS9ng! [         a.  n[        R                  SR                  U5      5         SnAgSnAff = f)z
:param electionRecord: Annotation string
:param name: Name of the configmap object to be created
:param namespace: Namespace in which the configmap object is to be created
:return: 'True' if object is created else 'False' if failed
)r   r$   )r#   T)prettyzFailed to create lock as {}NF)r   V1ConfigMapr   r'   dumpsget_lock_dictr   create_namespaced_config_mapr   loggerinfoformat)r   r   r   election_recordbodyr)   r*   s          r   createConfigMapLock.createJ   s     !!"&*&N&NPTPZPZ[_[m[mn}[~P  &ABC	,,II)bfIgL 	KK5<<Q?@	s   A# #
B-$BBc                 d    [         R                  " U R                  U5      5      U R                  R                  R
                  U R                  '   U R                  R                  XU R                  S9ng! [         a.  n[        R                  SR                  U5      5         SnAgSnAff = f)z
:param name: name of the lock to be updated
:param namespace: namespace the lock is in
:param updated_record: the updated election record
:return: True if update is successful False if it fails
)r   r   r6   TzFailed to update lock as {}NF)r'   r/   r0   r   r#   r$   r   r   replace_namespaced_config_mapr   r2   r3   r4   )r   r   r   updated_recordr)   r*   s         r   updateConfigMapLock.update\   s    	fjfpfpqu  rD  rD  ES  rT  gUD$$--99$:b:bc,,JJPTPTPhPh K jL 	KK5<<Q?@	s   A4A7 7
B/$B**B/c                 "   [        S S S S 5      nUR                  S5      (       a
  US   Ul        UR                  S5      (       a
  US   Ul        UR                  S5      (       a
  US   Ul        UR                  S5      (       a
  US   Ul        U$ Nr   r   r   r   )r   r%   holder_identitylease_durationacquire_time
renew_time)r   r   leader_election_records      r   r&   ConfigMapLock.get_lock_objectm   s    !5dD$!M??+,,5@AQ5R"2??1224?@V4W"1??=))2=m2L"/??;''0;K0H"-%%r   c                     UR                   U R                  S'   UR                  U R                  S'   UR                  U R                  S'   UR                  U R                  S'   U R                  $ r?   )r@   r   rA   rB   rC   )r   rD   s     r   r0   ConfigMapLock.get_lock_dict{   sh    -C-S-S)*3I3X3X/0*@*M*M'(>(I(I%r   )r   r   r   r   r   r   r   N)__name__
__module____qualname____firstlineno__r   r%   r7   r<   r&   r0   __static_attributes__ r   r   r   r      s     (:$"& r   r   )kubernetes.client.restr   
kubernetesr   r   kubernetes.client.api_clientr   leaderelectionrecordr   r'   logging	getLoggerr2   r   rM   r   r   <module>rT      s6    0 % 2 7  			+	,i  i r   