o
    x[hN  ã                
   @   sö   U d Z ddlZddl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mZmZmZ ddlmZ dd	lmZ dd
lmZ e e¡ZddgedgdœZeed< 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)ÚCloud)ÚDistroTF)ÚsubpÚ
temp_utilsÚ
type_utilsÚutil)ÚConfig)Ú
MetaSchema)ÚPER_INSTANCEÚcc_ubuntu_driversÚubuntuÚdrivers)ÚidÚdistrosÚ	frequencyÚactivate_by_schema_keysÚmetazDubuntu-drivers: error: argument <command>: invalid choice: 'install'zÉTemplate: 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 s€w   Y  W n tyœ }
 z
t tdt|
ƒ¡ ‚ d }
~
ww W tj |¡r©t |¡ ntj |¡r¶t |¡ w w zt
 
ddd|g¡ W d S  t
jyæ } zt|j v r×t !d¡ ‚ d|j"v rát !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© rC   úD/usr/lib/python3/dist-packages/cloudinit/config/cc_ubuntu_drivers.pyÚinstall_drivers9   sz   
ÿÿ
ÿ

üÿ€
ÿ€ü€
€ÿÿ
ÿ
þ
€ørE   Únamer8   Ú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_DEBCONFr6   rE   r   Úinstall_packages)rF   r8   rG   rH   rC   rC   rD   Úhandley   s   þÿrL   )!Ú__doc__Úloggingr&   Úcloudinit.cloudr   Úcloudinit.distrosr   r+   rJ   ÚImportErrorÚ	cloudinitr   r   r   r   Úcloudinit.configr   Úcloudinit.config.schemar	   Úcloudinit.settingsr
   Ú	getLoggerÚ__name__r    r   Ú__annotations__r4   r*   r   rE   r0   ÚlistrL   rC   rC   rC   rD   Ú<module>   s8   þ
üÿ

"@