o
    w7eR                  
   @   s(  U d Z ddlZddlmZ ddlmZ ddlmZ zddlZdZ	W n e
y.   dZdZ	Y nw ddlmZ dd	l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 eeZdgZdddedeedgedgdZeed< eeZ dZdZ dZ!defddZ"de#dedede$d df
d!d"Z%dS )#z<Ubuntu Drivers: Interact with third party drivers in Ubuntu.    N)dedent)Cloud)DistroTF)log)subp
temp_utils
type_utilsutil)Config)
MetaSchemaget_meta_doc)PER_INSTANCEubuntucc_ubuntu_driverszUbuntu Driversz,Interact with third party drivers in Ubuntu.zo        This module interacts with the 'ubuntu-drivers' command to install
        third party driver packages.zN        drivers:
          nvidia:
            license-accepted: true
        drivers)idnametitledescriptiondistrosexamples	frequencyactivate_by_schema_keysmetazDubuntu-drivers: error: argument <command>: invalid choice: 'install'zTemplate: linux/nvidia/latelink
Type: boolean
Default: true
Description: Late-link NVIDIA kernel modules?
 Enable this to link the NVIDIA kernel modules in cloud-init and
 make them available for use.
X_LOADTEMPLATEFILEdistroc              
   C   s  t | tstdt| | f d}tt| |}|s&t	d|| d S t
ds5t	d |dg d}t| d}|rF|d	|7 }t	d
|||rO|nd tj| dd}tj|d}zGz#t|t td}	|	t| W d    n1 sw   Y  W n ty }
 z
ttdt|
  d }
~
ww W tj|rt| ntj|rt| w w zt

ddd|g W d S  t
jy } zt|j v rt!d  d|j"v rt!d  d }~ww )Nz.'drivers' config expected dict, found '%s': %sznvidia/license-acceptedz$Not installing NVIDIA drivers. %s=%szubuntu-driverszI'ubuntu-drivers' command not available.  Installing ubuntu-drivers-commonzubuntu-drivers-commonnvidiaznvidia/versionz:{}z<Installing and activating NVIDIA drivers (%s=%s, version=%s)latestT)dir	needs_exeznvidia.templatez
cloud-initz.Failed to register NVIDIA debconf template: %sinstallz--gpgpuz[the available version of ubuntu-drivers is too old to perform requested driver installationz"No drivers found for installation.z0ubuntu-drivers found no drivers for installation)#
isinstancedict	TypeErrorr   obj_namer	   translate_boolget_cfg_by_pathLOGdebugr   whichformatr   mkdtempget_tmp_exec_pathospathjoin
write_fileNVIDIA_DEBCONF_CONTENTdebconfDebconfCommunicatorcommandr   	Exceptionlogexcstrisdirdel_dirProcessExecutionError OLD_UBUNTU_DRIVERS_STDERR_NEEDLEstderrwarningstdout)cfgpkg_install_funcr   cfgpathnv_acc
driver_argversion_cfgtdirdebconf_filedceexc rJ   D/usr/lib/python3/dist-packages/cloudinit/config/cc_ubuntu_drivers.pyinstall_driversN   sz   








rL   r   r?   cloudargsreturnc                 C   sF   d|vrt d|  d S tst d|  d S t|d |jj|j d S )Nr   z4Skipping module named %s, no 'drivers' key in configz<Skipping module named %s, 'python3-debconf' is not installed)r'   r(   HAS_DEBCONFr=   rL   r   install_packages)r   r?   rM   rN   rJ   rJ   rK   handle   s   rR   )&__doc__r-   textwrapr   cloudinit.cloudr   cloudinit.distrosr   r2   rP   ImportError	cloudinitr   loggingr   r   r   r	   cloudinit.configr
   cloudinit.config.schemar   r   cloudinit.settingsr   	getLogger__name__r'   r   r   __annotations__r;   r1   r   rL   r7   listrR   rJ   rJ   rJ   rK   <module>   sP   
	

"@