
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
\me<                 @   s  U d Z ddlZddlZddlmZ ddlmZ ddlmZ yddl	Z	dZ
W n ek
rf   dZ	dZ
Y nX 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jeZdgZdddedeedgedgdZeeeZ dZdZdZedddZ e!eee"ddddZ#dS )z<Ubuntu Drivers: Interact with third party drivers in Ubuntu.    N)dedent)Cloud)DistroTF)subp
temp_utils
type_utilsutil)Config)
MetaSchemaget_meta_doc)PER_INSTANCEZubuntuZ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distrosZexamplesZ	frequencyZactivate_by_schema_keyszDubuntu-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j| | f d}tjtj| |}|sLtj	d|| d S t
jdsjtj	d |dg d}tj| d}|r|d	j|7 }tj	d
|||r|nd tj|j dd}tjj|d}zpy2tj|t tjd}	|	jt| W d Q R X W n8 tk
r0 }
 ztjtdt|
  W Y d d }
~
X nX W d tjj|rNtj| X yt
j
ddd|g W nV t
jk
r } z6t|j krtj!d nd|j"krtj!d  W Y d d }~X nX d S )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-commonZnvidiaznvidia/versionz:{}z<Installing and activating NVIDIA drivers (%s=%s, version=%s)ZlatestT)dirZ	needs_exeznvidia.templatez
cloud-initz.Failed to register NVIDIA debconf template: %sZ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   Zobj_namer   Ztranslate_boolZget_cfg_by_pathLOGdebugr   Zwhichformatr   ZmkdtempZget_tmp_exec_pathospathjoinZ
write_fileNVIDIA_DEBCONF_CONTENTdebconfZDebconfCommunicatorZcommandr   	ExceptionZlogexcstrisdirZdel_dirZProcessExecutionError OLD_UBUNTU_DRIVERS_STDERR_NEEDLEstderrwarningstdout)cfgZpkg_install_funcr   ZcfgpathZnv_accZ
driver_argZversion_cfgZtdirZdebconf_fileZdceexc r+   '/usr/lib/python3.6/cc_ubuntu_drivers.pyinstall_driversN   sV    



r-   )r   r(   cloudargsreturnc             C   sF   d|krt jd|  d S ts,t j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&   r-   r   Zinstall_packages)r   r(   r.   r/   r+   r+   r,   handle   s    r2   )$__doc__Zloggingr   textwrapr   Zcloudinit.cloudr   Zcloudinit.distrosr   r    r1   ImportErrorZ	cloudinitr   r   r   r   Zcloudinit.configr	   Zcloudinit.config.schemar
   r   Zcloudinit.settingsr   Z	getLogger__name__r   r   metar$   r   r   r-   r"   listr2   r+   r+   r+   r,   <module>   sB   

@