
    W'Fg.                     T    S SK r SSKJr  S rS r " S S\5      rS r " S	 S
5      rg)    N   )xmlutilc           
      4   U R                  S5      u  pE[        [        US5      nU(       d  g[        XeS5      (       d  gSnU(       a  [        [        US5      nUc  gU4nUc  g[        X65      (       d)  [	        SU< S[        U5      < S[        U5      < 35      eUn	U(       a  X-  n	 [        X55      " U6   g! [        R                   a>  n
[        R                  U
5      (       a   Sn
A
g[        U5      (       a   Sn
A
g Sn
A
gSn
A
f[         a     gf = f)z
Make sure function and option flag is present in the libvirt module.
If run_args specified, try actually running the function against
the passed 'data' object
.NFzPassed obj z with args must be of type z, was T)splitgetattrlibvirt
isinstance
ValueErrorstrtypelibvirtErrorSupportCacheis_error_nosupportbool	Exception)functionflagrun_argsdataobject_namefunction_nameclassobj
flag_tuple
found_flaguse_argses              +/usr/share/virt-manager/virtinst/support.py_check_functionr      s    "*!4KwT2H8D11JWdD1
 ]
 d%%3x=$t*./ 	/ H	$h/   **1--
 
   s$   +B: :DD-DDDc                 2   U c  g U S:X  a  gU R                  S5      S:w  a  [        R                  " SU -  5      e[        U R	                  S5      S   5      S-  [        U R	                  S5      S   5      S-  -   [        U R	                  S5      S   5      -   $ )Nr   r      z(version string '%s' needs two '.' in it.i@B r   i  )countr   DevErrorintr   )verstrs    r   _version_str_to_intr&   =   s    ~{||CA:VCE 	E c"1%&0c"1%&-/25fll36G6J2KM N    c                   0    \ rS rSrSr  SS jrSS jrSrg)	_SupportCheckK   a  
@version: Minimum libvirt version required for this feature. Not used
    if 'args' provided.

@function: Function name to check exists. Expected to be of the
    format $obj.$func. Like virDomain.isActive

@run_args: Argument tuple to actually test 'function' with, and check
    for an 'unsupported' error from libvirt.

@flag: A flag to check exists. This will be appended to the argument
    :list if run_args are provided, otherwise we will only check against
    that the flag is present in the python bindings.

@hv_version: A dictionary with hypervisor names for keys, and
    hypervisor versions as values. This is for saying 'this feature
    is only supported with qemu version 1.5.0' or similar. If the
    version is 0, then perform no version check.

@hv_libvirt_version: Similar to hv_version, but this will check
    the version of libvirt for a specific hv key. Use this to say
    'this feature is supported with qemu and libvirt version 1.0.0,
     and xen with libvirt version 1.1.0'
Nc                    Xl         X l        X0l        X@l        U=(       d    0 U l        U=(       d    0 U l        U R                   (       a   [        UR                  S5      5      S:X  d   eU R                  /[        U R
                  R                  5       5      -   nU H:  n[        U5      n	Uc  M  U	S:w  d  M  U	S:  d  M#  [        R                  " SU-  5      e   g )Nr   r!   r   i[  zrCannot enforce support checks for libvirt versions less than 0.7.3, since required APIs were not available. ver=%s)r   r   r   version
hv_versionhv_libvirt_versionlenr   listvaluesr&   r   r#   )
selfr   r   r   r,   r-   r.   versionsvstrvs
             r   __init___SupportCheck.__init__d   s     ! 	$*"4":==x~~c*+q000\\NT$*A*A*H*H*J%KKD#D)AAFq4x&&EGKLM M r'   c                    S[        U5      ;   a  UR                  5       nU R                  (       a1  [        U R                  U R                  U R
                  U5      nUb  U$ UR                  5       nUR                  5       nUR                  5       n[        U R                  5      nU(       a  Xu:  a  gU R                  (       a>  X@R                  ;  a  SU R                  ;  a  gOU[        U R                  U   5      :  a  gU R                  (       a?  X@R                  ;  a  SU R                  ;  a  g gU[        U R                  U   5      :  a  gg)a  
Attempt to determine if a specific libvirt feature is support given
the passed connection.

:param virtconn: VirtinstConnection to check feature on
:param feature: Feature type to check support for
:type feature: One of the SUPPORT_* flags
:param data: Option libvirt object to use in feature checking
:type data: Could be virDomain, virNetwork, virStoragePool, hv name, etc

:returns: True if feature is supported, False otherwise
VirtinstConnectionFallT)reprget_conn_for_api_argr   r   r   r   get_uri_driverdaemon_versionconn_versionr&   r,   r-   r.   )r2   virtconnr   rethv_typeactual_libvirt_versionactual_hv_versionr5   s           r   __call___SupportCheck.__call__z   s.     4:-,,.D==!MM499dmmTCC
 ))+!)!8!8!:$113  -!,??oo-/  0#%doog&>?@""555 7 77  8 	 )%d&=&=g&FGHr'   )r   r   r.   r-   r   r,   )NNNNNNN)__name__
__module____qualname____firstlineno____doc__r6   rE   __static_attributes__ r'   r   r)   r)   K   s    2 59CGM,1r'   r)   c                  .   ^ [        U 0 UD6mSU4S jjnU$ )z
Create a _SupportCheck from the passed args, then turn it into a
SupportCache method which captures and caches the returned support
value in self._cache
c                    > TU R                   ;  a4  T" U R                  U=(       d    U R                  5      nX R                   T'   U R                   T   $ rG   _cache	_virtconn)r2   r   support_retsupport_objs      r   cache_wrapper_make.<locals>.cache_wrapper   sC    dkk)%dnnd6LdnnMK'2KK${{;''r'   rG   )r)   )argskwargsrV   rU   s      @r   _makerZ      s!      00K( r'   c                   x   \ rS rSrSr\S 5       r\S 5       rS r\	" SSS9r
\	" S	SS9r\	" S
SS9r\	" SSS9r\	" SSS9r\	" SSS.S9r\	" SSS.S9r\	" SS0S9r\	" SSS.S9r\	" SSSS.S9r\	" SSSS.S9r\	" SSS9r\	" SSSS.S9r\	" S S!SS"S.S#9r\	" S$S%9r\	" S&S%9r\	" S'S%9r\	" S(S%9r\	" S)SS*0S9r\	" SS*0S9r\	" SSS.S9r\	" S+SS0S9r\	" S,S-S.S9r \	" SS.S/.SSS/.S09r!\	" S1SS2S39r"\	" S1SS4S39r#\	" S5SS9r$\	" S6SS9r%\	" S7SS9r&\	" S8SS9r'\	" S9SS9r(\	" S:S;SS0S#9r)\	" SS<0S9r*\	" S=S>S?9r+\	" S@SS9r,SA r-SBr.gC)Dr      z_
Class containing all support checks and access APIs, and support for
caching returned results
c                     [        U [        R                  5      (       d  gU R                  5       [        R                  :H  $ )z^
Small helper to check if the passed exception is a libvirt error
with code VIR_ERR_NO_DOMAIN
F)r
   r	   r   get_error_codeVIR_ERR_NO_DOMAINerrs    r   is_libvirt_error_no_domain'SupportCache.is_libvirt_error_no_domain   s4     #w3344!!#w'@'@@@r'   c                     [        U [        R                  5      (       d  gU R                  5       [        R                  :X  d"  U R                  5       [        R
                  :X  a  gg)z
Check if passed exception indicates that the called libvirt command isn't
supported

:param err: Exception raised from command call
:returns: True if command isn't supported, False if we can't determine
FT)r
   r	   r   r^   VIR_ERR_RPCVIR_ERR_NO_SUPPORTr`   s    r   r   SupportCache.is_error_nosupport   sN     #w3344 G$7$77 G$>$>>r'   c                     0 U l         Xl        g rG   rQ   )r2   r@   s     r   r6   SupportCache.__init__   s    !r'   zvirConnect.listAllDomainsrN   )r   r   zvirConnect.listAllStoragePoolszvirConnect.listDevices)Nr   zvirConnect.listNetworkszvirConnect.newStream)r   z4.0.0r   )xenr:   )r-   z1.2.0)qemutestrk   z1.0.6)r.   z1.1.0)r,   r-   z1.2.2z1.5.3z virConnect.getDomainCapabilities)NNNNz1.2.16z2.2.0zvirDomain.setMemoryStatsPeriodz1.1.1z5.6.0)r   r,   r-   z2.0.0r,   z1.3.4z1.3.5z3.0.0z3.3.0z2.9.0z5.3.0z2.11.00z4.2.0)rk   rj   )r-   r.   zvirDomain.XMLDescVIR_DOMAIN_XML_INACTIVE)r   r   r   VIR_DOMAIN_XML_SECUREzvirDomain.hasManagedSaveImagezvirDomain.jobInfozvirDomain.listAllSnapshotszvirDomain.memoryStatszvirDomain.statezvirDomain.openGraphicsFDz1.2.8z8.9.0(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATAz1.0.1)r   r,   zvirNodeDevice.isActivec                 :    [        US9nU" U R                  S5      $ )zf
Check libvirt version. Useful for the test suite so we don't need
to keep adding new support checks.
rm   N)r)   rS   )r2   r,   sobjs      r   _check_versionSupportCache._check_version9  s    
 W-DNND))r'   rQ   N)/rH   rI   rJ   rK   rL   staticmethodrb   r   r6   rZ   conn_domainconn_storageconn_nodedevconn_networkconn_streamconn_working_xen_eventsconn_default_qcow2conn_autosocketconn_pm_disableconn_qcow2_lazy_refcountsconn_hyperv_clockconn_domain_capabilitiesconn_vmportconn_mem_stats_periodconn_graphics_listen_noneconn_rng_urandomconn_usb3_portsconn_machvirt_pci_defaultconn_qemu_xhciconn_vnc_none_authconn_device_boot_orderconn_riscv_virt_pci_defaultqemu_q35_defaultconn_disk_driver_name_qemudomain_xml_inactivedomain_xml_securedomain_managed_savedomain_job_infodomain_list_snapshotsdomain_memory_statsdomain_statedomain_open_graphicsdomain_undefine_keep_tpmpool_metadata_preallocnodedev_isactivert   rM   rN   r'   r   r   r      s   
 A A  $" ,r;K1B@L)I?L*R9L !7$GK#wq/IJ 7A*FG/@AO'CDO %Wa$@!BWa$@B$3) + gq%ACK!1Q$@B
 !&g 6W-G,O %g 677HIN67*;<"q!.DE"'VWDU"V
 3(GH
 "'g.$%g6"8
  )<r&(':R$&0 %82FO!-<(27"3bAL *DVQK1$ &0 2 #7 )B8*r'   r   )	r	    r   r   r&   objectr)   rZ   r   rN   r'   r   <module>r      s9     ,^N`F `F$* *r'   