o
    f^                  
   @   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'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 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   


"@