
    W'Fg+                         S SK r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SS	K	J
r
  SS
KJr  \" SS5      u  rrrrS r " S S\5      r " S S\5      rg)    N   )	urldetect)
urlfetcher)perform_initrd_injections   )progress)
DeviceDisk)log)OSDB   c                     U R                  S5      =(       d)    U R                  S5      =(       d    U R                  S5      $ )Nzhttp://zhttps://zftp://)
startswith)urls    >/usr/share/virt-manager/virtinst/install/installertreemedia.py_is_urlr      s5    NN9% %NN:&%NN8$&    c                       \ rS rSrS rSrg)_LocationData   c                     Xl         X l        X0l        X@l        S U l        U R                   (       a6  [
        R                  " U R                   5      nUR                  5       U l        g g N)
os_variantkernel_pairsos_mediaos_treekernel_url_argr   	lookup_osget_kernel_url_arg)selfr   r   r   r   osobjs         r   __init___LocationData.__init__    sN    $( "??NN4??3E"'":":"<D r   )r   r   r   r   r   N)__name__
__module____qualname____firstlineno__r!   __static_attributes__ r   r   r   r      s    	=r   r   c                       \ rS rSrSr\S 5       r\S 5       r\S 5       rS r	S r
S rS	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rSrg)InstallerTreeMedia,   z
Class representing --location Tree media. Can be one of

  - A network URL: http://dl.fedoraproject.org/...
  - A local directory
  - A local .iso file, which will be accessed with isoinfo
c                     [        U 5      nUR                  Ul        UR                  U5        UR	                  5         UR                  5       $ ! [         au  n[        R                  " SSS9  UR                  S5      (       a  [        R                  " S5        [        S5      [        U5      [        U5      S.-  n[        U5      S eS nAff = f)Nz!Error validating install locationT)exc_infoznfs:zNFS URL installs are no longer supported. Access your install media over an alternate transport like HTTP, or manually mount the NFS share and install from the local directory mount point.z6Validating install media '%(media)s' failed: %(error)s)mediaerror)r	   DEVICE_CDROMdeviceset_source_pathvalidateget_source_path	Exceptionr
   debugr   warning_str
ValueError)connpathdevemsgs        r   validate_path InstallerTreeMedia.validate_path5   s    	,T"C))CJ%LLN&&(( 
	,II9DIv&& < =
 MN!$i#a&9:CS/t+
	,s   AA 
CA0C		Cc                 D    U R                   R                  5       (       a  gg)zC
Return the tmpdir that's accessible by VMs on system libvirt URIs
z/var/lib/xenz/var/lib/libvirt/boot)r;   is_xen)guests    r   get_system_scratchdir(InstallerTreeMedia.get_system_scratchdirI   s    
 ::!&r   c                    [         R                  R                  U R                  R	                  5       S5      n[
        R                  U 5      nU R                  R                  5       (       dN  [         R                  R                  U5      (       a*  [         R                  " U[         R                  5      (       d  [         R                  " USSS9  U$ U$ )zu
Determine the scratchdir for this URI, create it if necessary.
scratchdir is the directory that's accessible by VMs
booti  T)exist_ok)osr<   joinr;   get_app_cache_dirr*   rE   is_unprivilegedexistsaccessW_OKmakedirs)rD   user_scratchdirsystem_scratchdirs      r   make_scratchdir"InstallerTreeMedia.make_scratchdirR   s     '',,

,,.8.DDUK JJ&&((011		+RWW55KK>""  r   c                    Xl         X l        X0l        X@l        XPl        X`l        Xpl        / U l        / U l        U(       d  U(       a=  U(       d  [        [        S5      5      eU(       a  U(       d  [        [        S5      5      eS U l        S U l        / U l        U R                  (       d  U R
                  (       a  [        U l        OU R                   R!                  5       (       d  ["        R$                  R'                  U R                  5      (       ah  ["        R$                  R)                  U R                  5      (       a:  ["        R$                  R+                  U R                  5      U l        [,        U l        O1[/        U R                  5      (       a  [0        U l        O[2        U l        U R                   R!                  5       (       aI  U R                  [0        :X  d5  U R                  [        :X  d!  [        [        S5      U R                  -  5      eU R                  [2        :X  a+  [4        R7                  U R                   U R                  5        g g )NzElocation kernel/initrd may only be specified with a location URL/pathz2location kernel/initrd must be specified as a pairz3Cannot access install tree on remote connection: %s)r;   location_location_kernel_location_initrd_install_kernel_install_initrd_install_kernel_args_initrd_injections_extra_argsr:   r8   _cached_fetcher_cached_data	_tmpfilesMEDIA_KERNEL_media_type	is_remoterJ   r<   rN   isdirabspath	MEDIA_DIRr   	MEDIA_URL	MEDIA_ISOr*   r@   )r   r;   rW   location_kernellocation_initrdinstall_kernelinstall_initrdinstall_kernel_argss           r   r!   InstallerTreeMedia.__init__f   s   	  / /--$7!"$o  $< "= > >#  $- ". / /  $ 4#7#7+D))%%''ggnnT]]++ggmmDMM**GGOODMM:DM(DT]]##(D(DII!!$$	1  L0Q  ! "$(MM2 3 3 y(,,TYYF )r   c                 `   [         R                  " U5      nU R                  (       dl  [        R	                  U5      nU R
                  [        :X  a  [        R                  " S X25      U l        O&[        R                  " U R                  X25      U l        X R                  l        U R                  $ r   )r   ensure_meterr_   r*   rT   rc   rb   r   DirectFetcherfetcherForURIrW   meter)r   rD   rt   
scratchdirs       r   _get_fetcherInstallerTreeMedia._get_fetcher   s    %%e,##+;;EBJ</'1'?'?*(-$ (2'?'?MM:(6$ &+"###r   c                 .   U R                   (       a  U R                   $ S nS nS nS n/ n[        U R                  =(       a    U R                  5      nU R                  [
        :X  a  U R                  U R                  4/nO[        R                  " XUS9nU(       a@  UR                  5       nUR                  5       nUR                  5       nUR                  5       nU(       a  U R                  U R                  4/n[        XGXV5      U l         U R                   $ )N)
skip_error)r`   boolrX   rY   rc   rb   rZ   r[   r   getDistroStoreget_kernel_pathsget_osdict_infoget_os_mediaget_os_treer   )	r   rD   fetcherstorer   r   r   kernel_pathshas_location_kernels	            r   _get_cached_data#InstallerTreeMedia._get_cached_data   s   $$$
"%%?$*?*?A |+))4+?+?@BL ,,U24E  113L..0J))+H'')G**D,A,ABDL **#   r   c                 "  ^^ UnUU4S jnU" 5       u  pgTR                  U5      nU R                  R                  U5        TR                  U5      n	U R                  R                  U	5        [        U	U R                  TR
                  5        X4$ )Nc                     > TR                    H8  u  pTR                  U 5      (       d  M  TR                  U5      (       d  M5  X4s  $    [        [        S5      5      e)Nz&Couldn't find kernel for install tree.)r   hasFileRuntimeErrorr8   )kpathipathcacher   s     r   _check_kernel_pairsCInstallerTreeMedia._prepare_kernel_url.<locals>._check_kernel_pairs   sT     % 2 2??5))gooe.D.D <' !3 >?A Ar   )acquireFilera   appendr   r]   ru   )
r   rD   r   r   ignorer   
kernelpath
initrdpathkernelinitrds
     ``      r   _prepare_kernel_url&InstallerTreeMedia._prepare_kernel_url   s    	A "5!6
$$Z0f%$$Z0f%!&"&"9"9")"4"4	6 ~r   c                     U(       d  g U HZ  nUR                  5       nUR                  5       nU R                  R                  U5        U R                  R                  XC45        M\     g r   )get_expected_filenamewritera   r   r]   )r   scriptsscriptexpected_filename
scriptpaths        r   _prepare_unattended_data+InstallerTreeMedia._prepare_unattended_data   sU    F & < < >JNN!!*-##**J+JK	 r   c                     UR                   =(       d    UR                  R                  n[        R                  " U5      nUR                  5       $ r   )r   osinfonamer   r   r   )r   rD   r   r   r    s        r   _prepare_kernel_url_arg*InstallerTreeMedia._prepare_kernel_url_arg   s9    %%:):):
z*''))r   c                 ~   S nU(       a^  / nU H-  nUR                  5       nU(       d  M  UR                  U5        M/     SR                  U5      n[        R                  " SU5        O@U R                  5       (       a+  U R                  X5      nU(       a  U< SU R                  < 3nU(       a  U R                  R                  U5        U R                  (       a  U R                  n	OSR                  U R                  5      n	U R                  [        :X  a&  U	(       d  [        R                  " [        S5      5        U	$ )N z Generated unattended cmdline: %s=zDirectory tree installs typically do not work unless extra kernel args are passed to point the installer at a network accessible install tree.)generate_cmdliner   rK   r
   r6   is_network_urlr   rW   r^   r\   rc   rg   r7   r8   )
r   rD   r   unattended_scriptsinstall_argsargsunattended_scriptcmdliner   rets
             r   _prepare_kernel_args'InstallerTreeMedia._prepare_kernel_args   s    D%7!+<<>7KK( &8  ::d+LII8,G  ""!99%GN*8$--H##L1$$++C((4++,Cy(KK B C D 
r   c                     U R                  X5      nU R                  X5      nU R                  U5        U R                  XU5      nU R	                  XU5      u  pxXxU4$ r   )rv   r   r   r   r   )	r   rD   rt   r   r   r   kernel_argsr   r   s	            r   prepareInstallerTreeMedia.prepare  sc    ##E1%%e5%%&89//>PQ11%H{**r   c                     UnU R                    H9  n[        R                  " S[        U5      5        [        R
                  " U5        M;     / U l         g )NzRemoving %s)ra   r
   r6   r9   rJ   unlink)r   rD   r   fs       r   cleanupInstallerTreeMedia.cleanup  s;    AIImSV,IIaL   r   c                     Xl         g r   )r]   )r   initrd_injectionss     r   set_initrd_injections(InstallerTreeMedia.set_initrd_injections"  s    "3r   c                     Xl         g r   )r^   )r   
extra_argss     r   set_extra_args!InstallerTreeMedia.set_extra_args%  s    %r   c                 F    U R                   [        4;   a  U R                  $ g r   )rc   ri   rW   r   s    r   
cdrom_pathInstallerTreeMedia.cdrom_path(  !    	{*==  +r   c                 F    U R                   [        4;   a  U R                  $ g r   )rc   rh   rW   r   s    r   r   !InstallerTreeMedia.is_network_url,  r   r   c                 `    U R                  US 5      nU R                  X5      nUR                  $ r   )rv   r   r   )r   rD   r   r   s       r   detect_distro InstallerTreeMedia.detect_distro0  s0    ##E40%%e5r   c                 ^    U R                  X5      nU R                  X5      nUR                  $ r   )rv   r   r   r   rD   rt   r   r   s        r   r~   InstallerTreeMedia.get_os_media5  s,    ##E1%%e5~~r   c                 ^    U R                  X5      nU R                  X5      nUR                  $ r   )rv   r   r   r   s        r   r   InstallerTreeMedia.get_os_tree:  s,    ##E1%%e5}}r   c                     U R                   [        [        4;   a  gU R                  X5      nU(       a  UR	                  5       $ g)NTF)rc   rh   rg   r~   
is_netinst)r   rD   rt   r   s       r   requires_internet$InstallerTreeMedia.requires_internet?  s=    	955$$U2&&((r   )r`   r_   r^   r]   r[   rZ   r\   rY   rX   rc   ra   r;   rW   N)r#   r$   r%   r&   __doc__staticmethodr@   rE   rT   r!   rv   r   r   r   r   r   r   r   r   r   r   r   r   r~   r   r   r'   r(   r   r   r*   r*   ,   s     , ,& ' ' ! !&,Gf$ !@6L*
:+4&!! 


r   r*   )rJ    r   r   installerinjectr   r   devicesr	   loggerr
   osdictr   rangerg   ri   rh   rb   r   objectr   r*   r(   r   r   <module>r      sY    
   6      q!

&
=F 
=Z Zr   