+
    h~6  c                   s    ^ RI t ^ RIt^ RIt^RIHt ^RIHt ^RIHt ^RIHt ^RIH	t	 ^RI
Ht ^RIHt ^R	IHtHt ^R
IHtHt R t ! R R4      tR# )    N)Capabilities)pollhelpers)support)xmlutil)Guest)log)
NodeDevice)StoragePoolStorageVolume)URIMagicURIc                 s    Rp \        \        V 4      '       g%   \        \        V \        P                  ! 4       4       \	        \        V 4      # )zW
Lookup the local libvirt library version, but cache the value since
it never changes.
Z__virtinst_cached_getVersion)ZhasattrlibvirtZsetattr
getVersiongetattr)key    ./usr/share/virt-manager/virtinst/connection.py_real_local_libvirt_versionr      s8    
 )C7C  g00237C      c                   s  a  ] tR t^"t o Rt]R 4       t]R 4       tR tR t	R t
]! ]
4      tR t]! ]4      tR tR	 tR
 tR tR tR tR tR tRtRtRtRtR tR tR tR tR tR t R t!R t"R t#R t$R t%R t&R  t'R! t(R" t)R# t*R$ t+R% t,R& t-R' t.R( t/R) t0R* t1R+ t2R, t3R- t4R. t5R/ t6R0 t7R1 t8R2 t9R3 t:R4 t;R5 t<R6 t=R7 t>R8 t?R9 t@R:tAV tBR;# )<VirtinstConnectionz
Wrapper for libvirt connection that provides various bits like
- caching static data
- lookup for API feature support
- simplified API wrappers that handle new and old ways of doing things
c                 s    \         P                  P                  R 4      p V '       g    \         P                  P	                  R4      p \         P                  P                  V R4      # )ZXDG_CACHE_HOMEz~/.cachezvirt-manager)osenvirongetpath
expanduserZjoin)retr   r   get_app_cache_dirZ$VirtinstConnection.get_app_cache_dir*   sA    jjnn-.''$$Z0Cww||C00r   c                 s,    \         P                  ! 4       # N)r   in_testsuite r   r   r   ZVirtinstConnection.in_testsuite1   s    ##%%r   c                s   T;'       g    R p\         P                  ! V4      '       d   \        V4      V n        V P                  P                  V n        V P                  P
                  ;'       g    V P                  V n        V P                  P                  V n        V P                  P                  V n
        V P                  P                  V n        M(RV n        W n        W n        RV n        RV n        RV n
        RV n        RV n        RV n        \!        V P                  4      V n        RV n        / V n        RV n        RV n        RV n        RV n        RV n        \2        P4                  ! \6        P8                  ! V 4      4      V n        R# ) NF)r   Zuri_is_magic
_magic_uriZopen_uri	_open_uriZfakeuri_uriZpredictable_fake_conn_predictableconn_version_fake_conn_versionZlibvirt_version_fake_libvirt_version_daemon_version_conn_version_libvirtconnr
   _uriobj_caps_fetch_cachecb_fetch_all_domainscb_fetch_all_poolscb_fetch_all_volscb_fetch_all_nodedevscb_cache_new_poolr   ZSupportCacheweakrefproxy)selfuriZ_initial_uri   && r   __init__ZVirtinstConnection.__init__5   s2   yyb  ..&|4DO!__55DN//AA4>>DI*.//*E*ED'&*oo&B&BD#)-)H)HD&"DO)N$I*/D')-D&&*D##! 499~
 %)!"&!%%)"!%++GMM$,?@r   c                sN    V P                   P                  R 4      p\        W!4      # r)   )Z__dict__r   r   )r4   ZattrZlibvirtconnr6   r   __getattr__ZVirtinstConnection.__getattr__`   s!    mm''7{))r   c                sB    V P                   ;'       g    V P                  # r   )r"   r!   r4      &r   _get_uriZVirtinstConnection._get_urie   s    yy**DNN*r   c                s    V P                   '       gM   V P                  P                  4       p\        W4      V n         \        P
                  ! R V P                  V4       V P                   # )zFetched capabilities for %s: %s)r+   r)   ZgetCapabilitiesr   r   debugr"   )r4   Zcapsxml   & r   	_get_capsZVirtinstConnection._get_capsj   sJ    zzz''779G%d4DJII7GLzzr   c                    V P                   # r   r8   r:   r;   r   get_conn_for_api_argZ'VirtinstConnection.get_conn_for_api_args   s       r   c           	     s    R  p\         P                  ! RV! V P                  4       4      V! V P                  4       4      V! V P	                  4       4      4       R# )c                 s    \        V R ,          4      p\        V R,          4      R,          pV R,          pV: RV: RV: 2# )i@B i  Z.)Zint)ZnumZmajorZminorZmicros   &   r   format_versionZ8VirtinstConnection._log_versions.<locals>.format_version{   s8    g&Ed
Od*E$JE!&u55r   z7libvirt URI versions library=%s driver=%s hypervisor=%sN)r   r=   local_libvirt_versiondaemon_versionr$   )r4   rB   r>   r   _log_versionsZ VirtinstConnection._log_versionsz   sK    	6 			E455784..014,,./		
r   c                s    ^ pV P                   '       d   V P                   P                  4       pRV n         RV n        / V n        V# r    N)r)   closer"   r,   r4   r   r>   r   rG   ZVirtinstConnection.close   sC    ##))+C 	
r   c                r@   r   )r#   r:   r;   r   fake_conn_predictableZ(VirtinstConnection.fake_conn_predictable   s    ***r   c                s    R V n         R # r   )r+   r:   r;   r   invalidate_capsZ"VirtinstConnection.invalidate_caps   s	    
r   c                s,    \        V P                  4      # r   )boolr)   r:   r;   r   is_openZVirtinstConnection.is_open   s    D%%&&r   c                s   V P                   '       d   V P                   P                  4        \        P                  \        P                  \        P
                  \        P                  \        P                  \        P                  .p^ p\        P                  ! V P                  W1V.V4      pV P                   '       d   V P                   P                  V4       WPn        V P                  '       g:   V P                  P                  4       V n        \        V P                  4      V n        V P#                  4        V P%                  4        R# rF   )r    Zvalidater   ZVIR_CRED_AUTHNAMEZVIR_CRED_ECHOPROMPTZVIR_CRED_REALMZVIR_CRED_PASSPHRASEZVIR_CRED_NOECHOPROMPTZVIR_CRED_EXTERNALZopenAuthr!   Zoverwrite_conn_functionsr)   getURIr"   r
   r*   rE   r?   )r4   ZauthcbZcbdataZvalid_auth_optionsZ
open_flagsZconns   &&&   r   openZVirtinstConnection.open   s    ???OO$$& %%''""''))%%
 
1CV0TV`a???OO44T: ~~~))002DItyy>DLr   c                s    V P                  4       '       d   R # \        P                  P                  R\        P                  P                  R4      4      # )z/var/lib/libvirtZXDG_DATA_HOMEz~/.local/share/libvirt)is_privilegedr   r   r   r   r   r:   r;   r   get_libvirt_data_root_dirZ,VirtinstConnection.get_libvirt_data_root_dir   s9    %zz~~orww/A/ABZ/[\\r   ZvmspoolsvolsZnodedevsc                s    V'       d   V! 4       # WP                   9  d   V! 4       V P                   V&   V P                   V,          R ,          # ):NNN)r,   )r4   r   Zraw_cbZoverride_cbs   &&&&r   _fetch_helperZ VirtinstConnection._fetch_helper   sA    = '''%+XDc"  %a((r   c                sL   \         P                  ! V / R  4      w  rp. pV FE  p VP                  ^ 4      pTP                  \        \        P                  ! T 4      TR7      4       KG  	  V#   \        P                   d#   p\
        P                  ! RT4        Rp?K}  Rp?ii ; i)c                     V # r   r   objZignore   &&r   <lambda>Z;VirtinstConnection._fetch_all_domains_raw.<locals>.<lambda>   s    RUr   zFetching domain XML failed: %sNZparsexml)r   Z	fetch_vmsXMLDescr   libvirtErrorr   r=   appendr   r2   r3   )r4   dummy1dummy2r   ZdomainsrV   xmle   &       r   _fetch_all_domains_rawZ)VirtinstConnection._fetch_all_domains_raw   s    )33D">UVCkk!n NN5t!4sCD  	 '' 		:A>s   A,,B#BB#c                sb    \        \        P                  ! V 4      VP                  ^ 4      R7      # )r    rY   )r   r2   r3   rZ   r4   poolobjrW   r   _build_pool_rawZ"VirtinstConnection._build_pool_raw   s!    7==.9KLLr   c                s   \         P                  ! V / R  4      w  rp. pV F&  p V P                  V4      pTP                  T4       K(  	  V#   \        P                   d#   p\
        P                  ! RT4        Rp?K^  Rp?ii ; i)c                 rT   r   r   rU   rW   r   rX   Z9VirtinstConnection._fetch_all_pools_raw.<locals>.<lambda>   s    TWr   zFetching pool XML failed: %sN)r   Zfetch_poolsre   r   r[   r   r=   r\   )r4   r]   r^   r   rQ   rd   poolr`   ra   r   _fetch_all_pools_rawZ'VirtinstConnection._fetch_all_pools_raw   s    )55dB@WXG++G4 LL  	 '' 		8!<s   AB"A??Bc           	     s    \         P                  ! V / R  4      w  rpV Uu. uF2  p\        \        P                  ! V 4      VP                  ^ 4      4      NK4  	  up# u upi )c                 rT   r   r   rU   rW   r   rX   Z<VirtinstConnection._fetch_all_nodedevs_raw.<locals>.<lambda>   s    WZr   )r   Zfetch_nodedevsr   r2   r3   rZ   )r4   r]   r^   r   rV   s   &    r   _fetch_all_nodedevs_rawZ*VirtinstConnection._fetch_all_nodedevs_raw   sL    )88rCZ[KNO3C
7==.A?3OOOs   8Ac                s*   . p V P                   P                  VP                  4      pTP                  4       ^ ,          \        P                  8w  d   T# \        P                  ! Y/ R 4      w  rEpT FE  p TP                  ^ 4      pTP                  \        \        P                  ! T 4      TR7      4       KG  	  T#   \        P                   d    Tu # i ; i  \        P                   d#   p	\        P                  ! RT	4        Rp	?	K  Rp	?	ii ; i)r    c                 rT   r   r   rU   rW   r   rX   Z4VirtinstConnection._fetch_vols_raw.<locals>.<lambda>   s    ]`r   rY   zFetching volume XML failed: %sN)r)   ZstoragePoolLookupByNameZnamer   r[   ZinfoZVIR_STORAGE_POOL_RUNNINGr   Zfetch_volumesrZ   r\   r	   r2   r3   r   r=   )
r4   
poolxmlobjr   rf   r]   r^   rR   Zvolr_   r`   s
   &&        r   _fetch_vols_rawZ"VirtinstConnection._fetch_vols_raw   s    	$$<<Z__MD 99;q>W===J*88RI`aC?kk!n

=t)<sKL  
 ## 	J	 '' ?		:A>>?s*   %B> 7AC>CCD0DDc                sx    . pV P                  4        F#  pVP                  V P                  V4      4       K%  	  V# r   )fetch_all_poolsextendrj   )r4   r   ri   s   &  r   _fetch_all_vols_rawZ&VirtinstConnection._fetch_all_vols_raw  s6    ..0JJJt++J78 1
r   c                sr   V P                   V P                  9  d   R # V P                  V P                   ,          pV P                  V4      pVP                  V4       V P                  V P                  9  d   R # V P                  V P                  ,          pVP                  V P                  V4      4       R # r   )_FETCH_KEY_POOLSr,   re   r\   _FETCH_KEY_VOLSrl   rj   )r4   rd   Zpoollistri   Zvollists   &&   r   _cache_new_pool_rawZ&VirtinstConnection._cache_new_pool_raw  s      (9(99 $$T%:%:;))'2

#t'8'88##D$8$89t++J78r   c                sj    V P                   '       d   V P                  V4      # V P                  V4      # )z*
Insert the passed poolobj into our cache
)r1   rp   rc   rW   r   cache_new_poolZ!VirtinstConnection.cache_new_pool  s2     !!!))'22''00r   c                d    V P                  V P                  V P                  V P                  4      # )z#
Returns a list of Guest() objects
)rS   _FETCH_KEY_DOMAINSrb   r-   r:   r;   r   fetch_all_domainsZ$VirtinstConnection.fetch_all_domains$  s0     !!##T%@%@$B[B[
 	
r   c                rr   )z'
Returns a list of StoragePool objects
)rS   rn   rg   r.   r:   r;   r   rk   Z"VirtinstConnection.fetch_all_pools,  s0     !!!!4#<#<d>U>U
 	
r   c                rr   )z)
Returns a list of StorageVolume objects
)rS   ro   rm   r/   r:   r;   r   fetch_all_volsZ!VirtinstConnection.fetch_all_vols4  s0     !!  $":":D<R<R
 	
r   c                rr   )z(
Returns a list of NodeDevice() objects
)rS   _FETCH_KEY_NODEDEVSrh   r0   r:   r;   r   fetch_all_nodedevsZ%VirtinstConnection.fetch_all_nodedevs<  s0     !!$$d&B&BDD^D^
 	
r   c                r@   r   )r"   r:   r;   r   rM   ZVirtinstConnection.getURIH  s    yyr   c                sJ    V P                   e   V P                   # \        4       # r   )r&   r   r:   r;   r   rC   Z(VirtinstConnection.local_libvirt_versionO  s#    %%1---*,,r   c                sx   V P                   e   V P                   # V P                  4       '       g   \        4       # V P                  f4   ^ V n         V P                  P                  4       V n        V P                  # V P                  #   \         d'    \        P                  ! RRR7        T P                  # i ; i)NzError calling getLibVersionTZexc_info)	r&   	is_remoter   r'   r)   ZgetLibVersion	Exceptionr   r=   r:   r;   r   rD   Z!VirtinstConnection.daemon_versionU  s    %%1---~~.00'#$D H'+'8'8'F'F'H$ ###t###  H		7$G###Hs   B #B98B9c                s8   V P                   e   V P                   # V P                  f4   ^ V n         V P                  P                  4       V n        V P                  # V P                  #   \         d'    \
        P                  ! RRR7        T P                  # i ; i)NzError calling getVersionTrx   )r%   r(   r)   r   rz   r   r=   r:   r;   r   r$   ZVirtinstConnection.conn_versionc  s    "".***%!"DE%)%6%6%A%A%C" !!!t!!!  E		4tD!!!Es   A( (#BBc                s@    \        V P                  P                  4      # r   )rK   r*   hostnamer:   r;   r   ry   ZVirtinstConnection.is_remotes  s    DLL))**r   c                s    V P                  4       R 8X  d   R# V P                  4       R8X  d   \        P                  ! 4       ^ 8H  # R# )z/sessionFz/embedT)get_uri_pathr   Zgetuidr:   r;   r   rO   Z VirtinstConnection.is_privilegedv  s;    *,(*99;!##r   c                s,    V P                  4       '       * # r   )rO   r:   r;   r   is_unprivilegedZ"VirtinstConnection.is_unprivileged}  s    %%'''r   c                .    V P                   P                  # r   )r*   r{   r:   r;   r   get_uri_hostnameZ#VirtinstConnection.get_uri_hostname      ||$$$r   c                r~   r   )r*   Zportr:   r;   r   get_uri_portZVirtinstConnection.get_uri_port      ||   r   c                r~   r   )r*   Zusernamer:   r;   r   get_uri_usernameZ#VirtinstConnection.get_uri_username  r   r   c                s    V P                  4       '       d   V P                  P                  '       g   R # V P                  P                  # )Ztls)r   r*   Z	transportr:   r;   r   get_uri_transportZ$VirtinstConnection.get_uri_transport  s5      ""4<<+A+A+A ||%%%r   c                r~   r   )r*   r   r:   r;   r   r|   ZVirtinstConnection.get_uri_path  r   r   c                r~   r   )r*   schemer:   r;   r   get_uri_driverZ!VirtinstConnection.get_uri_driver  s    ||"""r   c                L    V P                   P                  P                  R 4      # )Zqemur*   r   
startswithr:   r;   r   is_qemuZVirtinstConnection.is_qemu      ||""--f55r   c                R    V P                  4       ;'       d    V P                  4       # r   )r   rO   r:   r;   r   is_qemu_privilegedZ%VirtinstConnection.is_qemu_privileged  s    ||~66$"4"4"66r   c                r   r   )r   r}   r:   r;   r   is_qemu_unprivilegedZ'VirtinstConnection.is_qemu_unprivileged  s    ||~88$"6"6"88r   c                s^    \        V P                  4      P                  P                  R 4      # Ztest)r
   r!   r   r   r:   r;   r   is_really_testZ!VirtinstConnection.is_really_test  s"    4>>"))44V<<r   c                r   r   r   r:   r;   r   is_testZVirtinstConnection.is_test  r   r   c                    V P                   P                  P                  R 4      ;'       g&    V P                   P                  P                  R4      # )ZxenZlibxlr   r:   r;   r   is_xenZVirtinstConnection.is_xen  s;    ||""--e4__8K8K8V8VW^8__r   c                r   )Zlxcr   r:   r;   r   is_lxcZVirtinstConnection.is_lxc  s    ||""--e44r   c                r   )Zopenvzr   r:   r;   r   	is_openvzZVirtinstConnection.is_openvz  s    ||""--h77r   c                sR    V P                  4       ;'       g    V P                  4       # r   )r   r   r:   r;   r   is_container_onlyZ$VirtinstConnection.is_container_only  s    {{}00 00r   c                r   )ZvzZ	parallelsr   r:   r;   r   is_vzZVirtinstConnection.is_vz  s;    ||""--d3bbt||7J7J7U7UVa7bbr   c                r   )Zbhyver   r:   r;   r   is_bhyveZVirtinstConnection.is_bhyve  s    ||""--g66r   c                s    V P                   P                  4       pV P                  '       g   V P                  4       '       d   R pV P	                  4       ;'       g    T# )F)r   Zconn_streamr    r   r   rH   r>   r   support_remote_url_installZ-VirtinstConnection.support_remote_url_install  sC    ll&&(???dllnnC  "))c)r   )r+   r(   r'   r#   r%   r&   r,   r)   r    r!   r"   r*   r1   r-   r0   r.   r/   r   N)CZ__name__Z
__module__Z__qualname__Z__firstlineno__Z__doc__Zstaticmethodr   r   r7   r9   r<   Zpropertyr5   r?   ZcapsrA   rE   rG   rI   rJ   rL   rN   rP   rs   rn   ro   rv   rS   rb   re   rg   rh   rj   rm   rp   rq   rt   rk   ru   rw   rM   rC   rD   r$   ry   rO   r}   r   r   r   r   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   Z__static_attributes__Z__classdictcell__)Z__classdict__s   @r   r   r   "   si     1 1 & &%AV*
+ 8
C ID!
$+'8] O$)MP*9 1



-$
" +(%!%&!#679=6`581c7* *r   r   )r   r2   r   r   r   r   r   r   Zguestr   Zloggerr   Znodedevr   Zstorager   r	   r5   r
   r   r   r   r   r   r   <module>r      s<    
          / !]* ]*r   