
    W'Fg)                        S SK r SSKJr  SSKJrJrJr   " S S\5      r " S S\5      r " S	 S
\5      r	 " S S\5      r
 " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)    N   )log)
XMLBuilderXMLChildPropertyXMLPropertyc                   H    \ rS rSrSr\" S5      r\" S5      r\" S5      rSr	g)_CapsCPU   cpu./arch./modelz./vendor N)
__name__
__module____qualname____firstlineno__XML_NAMEr   archmodelvendor__static_attributes__r       0/usr/share/virt-manager/virtinst/capabilities.pyr	   r	      s%    Hx D	"E$Fr   r	   c                   8    \ rS rSrSr\" S5      r\" S5      rSrg)_CapsSecmodelBaselabel   	baselabel./@type.r   N)	r   r   r   r   r   r   typecontentr   r   r   r   r   r      s    Hy!D#Gr   r   c                   8    \ rS rSrSr\" S5      r\" \5      r	Sr
g)_CapsSecmodel$   secmodelr   r   N)r   r   r   r   r   r   r   r   r   
baselabelsr   r   r   r   r#   r#   $   s    H	"E!"89Jr   r#   c                   <    \ rS rSrSr\" \5      r\" \SS9r	S r
Srg)	_CapsHost*   hostT	is_singlec                    U R                    H  nUR                  S:w  a  M  S nUR                   H!  nUR                  S;   d  M  UR                  n  O   U(       d  MQ   [        UR                  S5      S   R                  SS5      5      n[        R                  " U5      S   nXT4s  $    g
! [         a    [        R                  " SUSS	9   M  f = f)Ndac)qemukvm:r   + z'Exception parsing qemu dac baselabel=%sT)exc_info)NN)	secmodelsr   r&   r    r!   intsplitreplacepwdgetpwuid	Exceptionr   debug)selfr%   labelr   uidusers         r   get_qemu_baselabel_CapsHost.get_qemu_baselabel/   s    H~~&E%00	>>_4%--E 1 *%++c*1-55c2>?||C(+y / '6   *		CD**s   AB-- CCr   N)r   r   r   r   r   r   r#   r5   r	   r   rA   r   r   r   r   r(   r(   *   s"    H /I
8t
4Cr   r(   c                   8    \ rS rSrSr\" S5      r\" S5      rSrg)_CapsMachineR   machiner   z./@canonicalr   N)	r   r   r   r   r   r   name	canonicalr   r   r   r   rD   rD   R   s    HsDN+Ir   rD   c                   H    \ rS rSrSr\" S5      r\" S5      r\" \	5      r
Srg)_CapsDomainX   domainr   z
./emulatorr   N)r   r   r   r   r   r   hypervisor_typeemulatorr   rD   machinesr   r   r   r   rJ   rJ   X   s%    H!),O<(H-Hr   rJ   c                   P    \ rS rSrSr\" SSS9r\" SSS9r\" SSS9r\" S	SS9r	S
r
g)_CapsGuestFeatures_   featuresz./paeT)is_boolz./acpi/@default)is_onoffz./apic/@defaultz./externalSnapshotr   N)r   r   r   r   r   r   paeacpiapicexternalSnapshotr   r   r   r   rQ   rQ   _   s;    H
gt
,C(48D(48D"#7Fr   rQ   c                       \ rS rSrSr\" S5      r\" S5      r\" S5      r\" S5      r	\
" \SS9r\
" \S	S
9r\
" \SS9rS rS rS rS rS rS rS rSrg)
_CapsGuesth   guestz	./os_typez./arch/@namez./arch/loaderz./arch/emulatorr   )relative_xpathTr+   c                 "   U=(       a    UR                   =(       d    U R                   n/ nU H^  nUR                  UR                  5        UR                  (       d  M1  UR                  U;  d  MC  UR                  UR                  5        M`     U$ )zq
Return all machine string names, including canonical aliases for
the guest+domain combo but avoiding duplicates
)rO   appendrG   rH   )r=   rL   mobjsretms        r   all_machine_names_CapsGuest.all_machine_namesy   se    
 +FOO=AJJqvv{{{q{{#5

1;;'  
r   c                     U=(       a    UR                   =(       d    U R                   nU H'  nUR                  U:X  d  M  UR                  U:X  d  M'    g   g)z8
Determine if machine @src is an alias for machine @tgt
TF)rO   rG   rH   )r=   rL   srctgtra   rc   s         r   is_machine_alias_CapsGuest.is_machine_alias   sC     +FOO=Avv}!3  r   c                 N    U R                    H  nUR                  S:X  d  M    g   g)z,
Return True if kvm guests can be installed
r0   TF)domainsrM   )r=   ds     r   is_kvm_available_CapsGuest.is_kvm_available   s(     A  E)  r   c                 @    [        U R                  R                  5      $ )z4
Return True if capabilities report support for PAE
)boolrS   rV   r=   s    r   supports_pae_CapsGuest.supports_pae   s     DMM%%&&r   c                 @    [        U R                  R                  5      $ )z5
Return Tree if capabilities report support for ACPI
)rq   rS   rW   rr   s    r   supports_acpi_CapsGuest.supports_acpi        DMM&&''r   c                 @    [        U R                  R                  5      $ )z5
Return Tree if capabilities report support for APIC
)rq   rS   rX   rr   s    r   supports_apic_CapsGuest.supports_apic   rx   r   c                 @    [        U R                  R                  5      $ )zC
Return True if capabilities report support for external snapshots
)rq   rS   rY   rr   s    r   supports_externalSnapshot$_CapsGuest.supports_externalSnapshot   s     DMM2233r   r   N)r   r   r   r   r   r   os_typer   loaderrN   r   rJ   rl   rQ   rS   rD   rO   rd   ri   rn   rs   rv   rz   r}   r   r   r   r   r[   r[   h   sx    H+&G~&D)F,-H{8DG 2dCHXFH'((4r   r[   c                   $    \ rS rSrSrS rS rSrg)	_CapsInfo   za
Container object to hold the results of guest_lookup, so users don't
need to juggle two objects
c                    Xl         X l        X0l        U R                  R                  U l        U R                  R                  U l        U R                  R
                  U l        U R                  R                  U l        U R                  R                  =(       d    U R                  R                  U l        U R                  R                  U R                  5      U l	        g N)
connr]   rL   rM   r   r   r   rN   rd   rO   )r=   r   r]   rL   s       r   __init___CapsInfo.__init__   s    	
#{{::zz))JJOO	jj'',,C

0C0C

44T[[Ar   c                 N    U R                   R                  U R                  X5      $ r   )r]   ri   rL   )r=   rg   rh   s      r   ri   _CapsInfo.is_machine_alias   s    zz**4;;AAr   )	r   r   rL   rN   r]   rM   r   rO   r   N)r   r   r   r   __doc__r   ri   r   r   r   r   r   r      s    BBr   r   c                   X    \ rS rSrS rSr\" \SS9r\" \	5      r
S rS rS rSS
 jrSrg	)Capabilities   c                 F    [         R                  " U /UQ70 UD6  0 U l        g r   )r   r   _cpu_models_cache)r=   argskwargss      r   r   Capabilities.__init__   s"    D24262!#r   capabilitiesTr+   c                     U/nUc"  U R                   R                  R                  S /nU HD  nU R                   H1  nUb  UR                  U:X  d  M  Ub  UR                  U:X  d  M-  Us  s  $    MF     g r   )r*   r   r   guestsr   )r=   r   r   archsags         r   _guestForOSTypeCapabilities._guestForOSType   sb    <YY]]''.EA[[_		W(<Y!&&A+H ! r   c                 H   / nUR                    HX  nU(       a   UR                  UR                  5       :w  a  M*  U(       a  X1R                  U5      ;  a  MG  UR	                  U5        MZ     U(       d  g/ SQnU H"  nU H  nUR                  U:X  d  M  Us  s  $    M$     US   $ )zT
Return the recommended domain for use if the user does not explicitly
request one.
N)r0   xenhvfr/   )rl   rM   lowerrd   r`   )r=   r]   dtyperF   rl   rm   priorityts           r   _bestDomainTypeCapabilities._bestDomainType   s    
 A**ekkm;7*A*A!*DDNN1  0A$$)H   r{r   c                 P    U R                    H  nUR                  (       d  M    g   g)z8
Return True if there are any install options available
TF)r   rl   )r=   r]   s     r   has_install_options Capabilities.has_install_options  s#     [[E}}} ! r   Nc                 "   US:X  a  SnU R                  X5      nU(       de  U(       a  U(       a  [        S5      XS.-  nO;U(       a  [        S5      SU0-  nO#U(       a  [        S5      SU0-  nO[        S	5      n[        U5      eU R                  XSU5      nUc^  U(       a'  [        S
5      X5R                  UR
                  US.-  nO%[        S5      X5R                  UR
                  S.-  n[        U5      e[        U R                  XW5      nU$ )a1  
Simple virtualization availability lookup

Convenience function for looking up 'Guest' and 'Domain' capabilities
objects for the desired virt type. If type, arch, or os_type are none,
we return the default virt type associated with those values. These are
typically:

    - os_type : hvm, then xen
    - typ     : kvm over plain qemu
    - arch    : host arch over all others

Otherwise the default will be the first listed in the capabilities xml.
This function throws C{ValueError}s if any of the requested values are
not found.

:param typ: Virtualization type ('hvm', 'xen', ...)
:param arch: Guest architecture ('x86_64', 'i686' ...)
:param os_type: Hypervisor name ('qemu', 'kvm', 'xen', ...)
:param machine: Optional machine type to emulate

:returns: A _CapsInfo object containing the found guest and domain
linuxr   zTHost does not support virtualization type '%(virttype)s' for architecture '%(arch)s')virttyper   zLHost does not support any virtualization options for architecture '%(arch)s'r   z8Host does not support virtualization type '%(virttype)s'r   z0Host does not support any virtualization optionszHost does not support domain type %(domain)s with machine '%(machine)s' for virtualization type '%(virttype)s' with architecture '%(arch)s')rL   r   r   rF   zpHost does not support domain type %(domain)s for virtualization type '%(virttype)s' with architecture '%(arch)s')rL   r   r   )r   _
ValueErrorr   r   r   r   r   )	r=   r   r   typrF   r]   msgrL   capsinfos	            r   guest_lookupCapabilities.guest_lookup
  s2   4 gG$$W3 F G&-<=  7 8 $(  * +$g./ JKS/!%%e':> G H %(]]!&AA  3 4 %(]]!&--
 S/!TYY6r   )r   )NNNN)r   r   r   r   r   r   r   r(   r*   r[   r   r   r   r   r   r   r   r   r   r   r      s9    $ HI6Dj)F	6@r   r   )r9   loggerr   
xmlbuilderr   r   r   r	   r   r#   r(   rD   rJ   rQ   r[   objectr   r   r   r   r   <module>r      s      A A%z %Z :J :!
 !P,: ,.* .G GG4 G4\B B,~: ~r   