
    Uٵg                     F   d dl mZ d dlmZmZmZmZmZmZm	Z	 d dl
mZ d dlmZ d dlmZmZ d dlmZ d dlmZ d dlmZ d d	lmZmZmZmZmZ d d
lmZmZm Z  d dl!m"Z"  G d dee      Z#de#fdZ$dede#fdZ%dede#fdZ& edde%d      Z'ddde#ejP                  dfgdddZ)y)    )List)daemonentitlements
exceptionslockmessagestimerutil)ProgressWrapper)APIEndpoint)AdditionalInfoErrorWarningObject)_reboot_required)_is_attached)UAConfig)BoolDataValue
DataObjectFieldStringDataValue	data_list)machine_tokennoticesstate_files)update_motd_messagesc                   Z    e Zd Z ed ee      d       eded      gZdee	   de
fdZy)DetachResultdisabledz1The services disabled during the detach operation)docreboot_requiredz?True if the system requires a reboot after the detach operationc                      || _         || _        y Nr   r   )selfr   r   s      >/usr/lib/python3/dist-packages/uaclient/api/u/pro/detach/v1.py__init__zDetachResult.__init__0   s     .    N)__name__
__module____qualname__r   r   r   r   fieldsr   strboolr%    r&   r$   r   r      sK    o&C	

 			
F /c /T /r&   r   returnc                  (    t        t                     S r!   )_detachr   r-   r&   r$   detachr1   5   s    8:r&   cfgc                    t        j                         st        j                  	 t	        j
                  d      5  t        |       }ddd       |S # 1 sw Y   S xY w# t        $ r}t	        j                          |d}~ww xY w)zZ
    This endpoint allows the user to detach the machine from a Pro
    subscription.
    zpro.api.u.pro.detach.v1)lock_holderN)	r
   we_are_currently_rootr   NonRootUserErrorr   	RetryLock_detach_in_lock	Exceptionclear_lock_file_if_present)r2   retes      r$   r0   r0   9   s|    
 %%')))^^1
 	' "#&C	' J	' J  '')s4   A AA AA A 	B(A>>Bc           	         t        |       j                  st        g d      S g }g }t        j                  |       D ]  }	 t        j
                  | |      }|j                  d      \  }}|s3|j                  t                     \  }}|s}|r9|j                  r-|j                  j                  }	|j                  j                  }
n"t        j                  j!                  |      }	d}
|j#                  t%        |	|
d|i	             |j#                  |        t'        j(                  t&        j*                  j,                         t/        j0                          t3        j4                         j7                          t9        |        t;        j<                          t?        j@                          tC        |       }t        tE        |      |jF                  d
k(        }||_$        |S # t        j                  $ r Y w xY w)NFr"   )r2   nameT)ignore_dependent_services)title service)r@   codemetayes)%r   is_attachedr   r   entitlements_disable_orderentitlement_factoryr   EntitlementNotFoundErrorcan_disabledisabler   messagemsgr>   r   DISABLE_FAILED_TMPLformatappendr   r   removeNoticeLIMITED_TO_RELEASEr   delete_state_filesr   get_machine_token_filedeleter   r   startr	   stopr   sortedr   warnings)r2   r   rZ   ent_nameentrJ   _r;   reasonrM   rC   reboot_required_resultresults                r$   r8   r8   L   s   ((!
 	

 HH ;;C@ *	22sJC 4HQ++o&78KCfnn ..,,C!>>..D"66==H=MCD&!!'2 )9*< NN7>>445""$((*113
LLN	JJL-c2!.>>%GF FOMU 22 		s    G**H Hv1DetachN)versionr>   fnoptions_cls32TzD
from uaclient.api.u.pro.detach.v1 import detach

result = detach()
z1Raised if a non-root user executes this endpoint.zpro api u.pro.detach.v1zL
{
    "disabled": ["service1", "service2"],
    "reboot_required": false
}
)introduced_inrequires_networkexample_pythonresult_classr   example_cliexample_json)*typingr   uaclientr   r   r   r   r   r	   r
   uaclient.apir   uaclient.api.apir   uaclient.api.data_typesr   r   5uaclient.api.u.pro.security.status.reboot_required.v1r   (uaclient.api.u.pro.status.is_attached.v1r   uaclient.configr   uaclient.data_typesr   r   r   r   r   uaclient.filesr   r   r   uaclient.timer.update_messagingr   r   r1   r0   r8   endpointr6   _docr-   r&   r$   <module>rz      s       ) ( F B $  ? > @/:~ /,  l &6 6l 6r 		 
 ! ''@	
 -!r&   