
    x[hN              
          U d Z ddlZddlZddlmZ ddlmZ 	 ddlZdZ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j*                  e      ZddgedgdZeed<   dZdZdZdefdZdededededdf
dZ y# e	$ r dZdZY dw xY w)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                 |   t        | t              s$t        dt        j                  |       d|       d}t        j                  t        j                  | |            }|st        j                  d||       y t        j                  d      st        j                  d        |dg       d}t        j                  | d	      }|r|d
j                  |      z  }t        j                  d|||r|nd       t        j                  |j                         d      }t         j"                  j%                  |d      }	 t        j&                  |t(               t+        j,                  d      5 }	|	j/                  t0        |       d d d        t         j"                  j9                  |      rt        j:                  |       	 	 t        j                  ddd|g       y # 1 sw Y   YxY w# t2        $ r*}
t        j4                  t        dt7        |
              d }
~
ww xY w# t         j"                  j9                  |      rt        j:                  |       w w xY w# t        j<                  $ rQ}t>        |j@                  v rt        jC                  d        d|jD                  v rt        jC                  d        d }~ww xY w)Nz''drivers' config expected dict, found 'z': z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excs               D/usr/lib/python3/dist-packages/cloudinit/config/cc_ubuntu_drivers.pyinstall_driversrF   9   s<   c4 ""3'.
 	

 (G   !5!5c7!CDF		8'6J::&'		/	
 	123J&&s,<=Kell;//
IIF"	 &":":"<MD77<<&78L&<=((6 	9"JJ)<8	9 77==LL
		#Y	:FG	9 	9 A3q6	
 		 77==LL 
 %% +szz9KKD 	 2SZZ?KKJKsU   =/G' ,GG' I G$ G' '	H0%HHH 7IJ;*AJ66J;namer:   cloudargsreturnc                     d|vrt         j                  d|        y t        st         j                  d|        y t	        |d   |j
                  j                  |j
                         y )Nr   z4Skipping module named %s, no 'drivers' key in configz<Skipping module named %s, 'python3-debconf' is not installed)r"   r#   HAS_DEBCONFr8   rF   r   install_packages)rG   r:   rH   rI   s       rE   handlerN   y   sW    		H$OJ	
 	I55u||    )!__doc__loggingr(   cloudinit.cloudr   cloudinit.distrosr   r-   rL   ImportError	cloudinitr   r   r   r   cloudinit.configr	   cloudinit.config.schemar
   cloudinit.settingsr   	getLogger__name__r"   r   __annotations__r6   r,   r   rF   r2   listrN    rO   rE   <module>r^      s    C  	 ! $K 9 8 # . +g! z ){	j  K !  * =6 =@ 6 % t  U  GKs   A8 8	BB