
Ke                 @   s  d  d l  m Z m Z m Z m Z m Z d  d l m Z m Z m	 Z	 m
 Z
 m Z d  d l m Z d  d l m Z m Z d  d l m Z m Z m Z e j   Z Gd d   d e j  Z Gd d	   d	 e  Z Gd
 d   d e  Z Gd d   d e  Z Gd d   d e  Z d S)    )AnyDictOptionalTupleType)aptevent_loggermessagessystemutil)repo)IncompatibleServiceUAEntitlement)MessagingOperationsMessagingOperationsDictStaticAffordancec               @   s  e  Z d  Z d Z e j Z e j Z e j	 Z
 e j j Z d Z d Z d Z d Z d Z e d d d    Z e e e e f d d	 d
    Z e e e d f d d d     Z e e e d f d d d     Z e e  d d d     Z! d d d d    Z" d S)RealtimeKernelEntitlementzrealtime-kernelzubuntu-pro-realtime-kernel.gpgTFZUbuntuRealtimeKernel)returnc             C   s;   t  j d t |  j  d t d g   } t j |  | S)z%Check if system needs to be rebooted.Zinstalled_pkgsZinstalled_pkgs_regexzlinux-.*-realtime)r
   Zshould_rebootsetpackageseventZneeds_reboot)selfZreboot_required r   @/usr/lib/python3/dist-packages/uaclient/entitlements/realtime.py_check_for_reboot   s
    	z+RealtimeKernelEntitlement._check_for_rebootc             C   s   t  j t  t j t t j t i S)N)GenericRealtimevariant_nameNvidiaTegraRealtimeIntelIotgRealtime)r   r   r   r   _get_variants$   s    		z'RealtimeKernelEntitlement._get_variants.c             C   sW   d d l  m } m } d d l m } t | t j  t | t j  t | t j	  f S)Nr   )FIPSEntitlementFIPSUpdatesEntitlement)LivepatchEntitlement)
Zuaclient.entitlements.fipsr    r!   Zuaclient.entitlements.livepatchr"   r   r	   ZREALTIME_FIPS_INCOMPATIBLEZ"REALTIME_FIPS_UPDATES_INCOMPATIBLEZREALTIME_LIVEPATCH_INCOMPATIBLE)r   r    r!   r"   r   r   r   incompatible_services+   s    	z/RealtimeKernelEntitlement.incompatible_servicesc             C   s   t  j d d   d f f S)Nc               S   s
   t  j   S)N)r
   Zis_containerr   r   r   r   <lambda>E   s    z>RealtimeKernelEntitlement.static_affordances.<locals>.<lambda>F)r	   Z#REALTIME_ERROR_INSTALL_ON_CONTAINER)r   r   r   r   static_affordances@   s    	z,RealtimeKernelEntitlement.static_affordancesc             C   s|   d  } |  j  s9 t j d t j d |  j d d i f g } d  } |  j sl t j d t j d |  j i f g } d | d | i S)Nmsg
assume_yesdefaultT
pre_enablepre_disable)Zaccess_onlyr   Zprompt_for_confirmationr	   ZREALTIME_PROMPTr'   purgeZREALTIME_PRE_DISABLE_PROMPT)r   r)   r*   r   r   r   	messagingJ   s    					z#RealtimeKernelEntitlement.messagingNc             C   sV   t  |  j  j t  t j     } | rR t j t |  t j j	 d |  j
   d  S)Ntitle)r   r   intersectionr   Zget_installed_packages_namesremove_packageslistr	   ZDISABLE_FAILED_TMPLformatr-   )r   r   r   r   r   r/   l   s    	z)RealtimeKernelEntitlement.remove_packages)#__name__
__module____qualname__namer	   ZREALTIME_TITLEr-   ZREALTIME_DESCRIPTIONdescriptionZREALTIME_HELP_TEXTZ	help_textZurlsZREALTIME_HOME_PAGEZhelp_doc_urlZrepo_key_fileZapt_noninteractiveZsupports_access_onlyZsupports_purgeoriginboolr   r   strr   r   r   propertyr   r   r#   r   r%   r   r,   r/   r   r   r   r   r      s&   				#""	r   c                   s;   e  Z d  Z e e e d f d   f d d     Z   S)RealtimeVariant.)r   c                s6   t    f d d     j j   D  } t   j | S)Nc          	      s@   g  |  ]6 \ } } t  | t j j d    j d | j    q S)serviceZvariant)r   r	   ZREALTIME_VARIANT_INCOMPATIBLEr1   r-   ).0r5   cls)r   r   r   
<listcomp>|   s   	z9RealtimeVariant.incompatible_services.<locals>.<listcomp>)tupleZother_variantsitemssuperr#   )r   Zincompatible_variants)	__class__)r   r   r#   x   s    z%RealtimeVariant.incompatible_services)r2   r3   r4   r:   r   r   r#   r   r   )rC   r   r;   w   s   r;   c               @   s4   e  Z d  Z d Z e j Z e j Z d Z	 d Z
 d S)r   ZgenericTN)r2   r3   r4   r   r	   ZREALTIME_GENERIC_TITLEr-   ZREALTIME_GENERIC_DESCRIPTIONr6   
is_variantcheck_packages_are_installedr   r   r   r   r      s
   		r   c               @   s4   e  Z d  Z d Z e j Z e j Z d Z	 d Z
 d S)r   znvidia-tegraTN)r2   r3   r4   r   r	   ZREALTIME_NVIDIA_TITLEr-   ZREALTIME_NVIDIA_DESCRIPTIONr6   rD   rE   r   r   r   r   r      s
   		r   c               @   sg   e  Z d  Z d Z e j Z e j Z d Z	 d Z
 e e e f e e e e j f d d d    Z d S)r   z
intel-iotgT)platform_checksr   c          	   C   sf   t  j   j } | j d g   } | | k r1 d Sd t j j d |  j d | d d j |   f Sd  S)	Ncpu_vendor_idsTFr-   ZvendorZsupported_vendors,)TN)	r
   Zget_cpu_info	vendor_idgetr	   ZINAPPLICABLE_VENDOR_NAMEr1   r-   join)r   rF   rI   rG   r   r   r   verify_platform_checks   s    	z(IntelIotgRealtime.verify_platform_checksN)r2   r3   r4   r   r	   ZREALTIME_INTEL_TITLEr-   ZREALTIME_INTEL_DESCRIPTIONr6   rD   rE   r   r9   r   r   r8   r   ZNamedMessagerL   r   r   r   r   r      s   		r   N)Ztypingr   r   r   r   r   Zuaclientr   r   r	   r
   r   Zuaclient.entitlementsr   Zuaclient.entitlements.baser   r   Zuaclient.typesr   r   r   Zget_event_loggerr   ZRepoEntitlementr   r;   r   r   r   r   r   r   r   <module>   s   ((h