
    [h              
           U d Z ddlZddlZddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ d	d
dgeg dZeed<    ej$                  e      Zd ZdefdZdede	dededdf
dZde	defdZy)z5Grub Dpkg: Configure grub debconf installation device    N)subputil)Cloud)Config)
MetaSchema)PER_INSTANCE)ProcessExecutionErrorcc_grub_dpkgubuntudebian)iddistros	frequencyactivate_by_schema_keysmetac                     d} g }d}d}t               rd}d}	 t        j                  dd||gd	      j                  j                         } | rt        j                  j!                  |       sy	 t        j                  dddd| gd	      j                  j                         j#                         }t        j                  ddj%                  |             |D cg c]	  }d|v s| }}t        j                  ddj%                  |             |rt'        |      d   n| }t        j                  d|       |S # t        $ r`}t        |j                  t              rt        j                  d
       n%d|j                  v rt        j                  d       n Y d}~Qd}~wt        $ r t        j                  t        d       Y zw xY w# t        $ r t        j                  t        d|        Y @w xY wc c}w )z
    Fetches the /dev/disk/by-id device grub is installed to.
    Falls back to plain disk name if no by-id entry is present.
     diskz/bootdevicez	/boot/efiz
grub-probez-tT)capturez'grub-probe' not found in $PATHzfailed to get canonical pathz)grub-probe 'failed to get canonical path'Nz*grub-probe failed to execute for grub_dpkgudevadminfoz--rootz--query=symlinkz3udevadm DEVLINKS symlink query failed for disk='%s'z%considering these device symlinks: %s,z
disk/by-idz)filtered to these disk/by-id symlinks: %sr   zselected %s)is_efi_bootedr   stdoutstripr	   
isinstancereasonFileNotFoundErrorLOGdebugstderr	Exceptionr   logexcospathexistssplitjoinsorted)r   devicesprobe_targetprobe_mountedevidevss          ?/usr/lib/python3/dist-packages/cloudinit/config/cc_grub_dpkg.pyfetch_idevsr2      s   
 DG LK!Gyy4{;T

& 	( rww~~d+
 IIFH.?F VEEGUW 	 II5sxx7HI%=s)<s=G=II9388G;LM")F7OAtEIImU#LY !  ahh 12II78
 ,qxx7IIAB  GCEFG"  
F	

 >s=   3D8 .AG	 	G4#G48	GAF&GG	$G10G1returnc                      	 t         j                  j                  d      S # t        $ r } t        j                  d|        Y d} ~ yd} ~ ww xY w)z4
    Check if the system is booted in EFI mode.
    z/sys/firmware/efiz7Failed to determine if system is booted in EFI mode: %sNF)r%   r&   r'   OSErrorr    error)r.   s    r1   r   r   c   s=    ww~~122 		KQOs   ! 	A
AA
namecfgcloudargsc                    |j                  d|j                  di             }|si }|j                  dd      }t        j                  |      rt        j	                  d| |       y t        |      }t        j	                  d|       	 t        j                  dg|       y # t        $ r%}t        j                  t        d	|       Y d }~y d }~ww xY w)
N	grub_dpkgz	grub-dpkgenabledTz*%s disabled by config grub_dpkg/enabled=%sz-Setting grub debconf-set-selections with '%s'zdebconf-set-selections)dataz6Failed to run debconf-set-selections for grub_dpkg: %s)	getr   is_falser    r!   get_debconf_configr   r#   r$   )r7   r8   r9   r:   mycfgr=   	dconf_selr.   s           r1   handlerD   o   s    GGKb!9:Eii	4(G}}W		>gN"5)III=yI
		+,9= 
I1	
 	

s   B! !	C*C

CrB   c                 h   t               r(t        j                  | dd      }|
t               }d|z  S t        j                  | dd      }|
t               }| j	                  d      }|| }n%t        |t              st        j                  |      }t        |      j                         }d|d|dS )	zd
    Returns the debconf config for grub-pc or
    grub-efi depending on the systems boot mode.
    zgrub-efi/install_devicesNz+grub-pc grub-efi/install_devices string %s
zgrub-pc/install_deviceszgrub-pc/install_devices_emptyz'grub-pc grub-pc/install_devices string z/
grub-pc grub-pc/install_devices_empty boolean 
)
r   r   get_cfg_option_strr2   r?   r   booltranslate_boolstrlower)rB   r0   idevs_emptys      r1   rA   rA      s    
 ''-t
 =ME=EE''/H$O=MEii ?@#)KK.--k:K+&,,. k#	
    )__doc__loggingr%   	cloudinitr   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   cloudinit.settingsr   cloudinit.subpr	   r   __annotations__	getLogger__name__r    r2   rH   r   rJ   listrD   rA    rM   r1   <module>r[      s    <  	   ! # . + 0 (#!	j  g!AH	t 	
 
6 
% 
t 
 
* 
f  
  
rM   