+
    h?T  c                   s   ^ RI t ^ RIt^ RIt^RIHt ^RIHtHtHtHt ^RI	H
t
 ^RIHt ^RIHt R tR tR	 tR
 t ! R R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R lt!R t"RR lt#R t$R# )     N)cli)failfail_conflictingprint_stdoutprint_stderr)Guest)log)xmlutilc                 sT    V R,           p\         P                  P                  V4       \         P                  P                  4        \         P                  P                  4       P                  4       P                  4       pVR9   d   R# VR9   d   R# \        \        R4      4       K  )   z (y/n): TFzPlease enter 'yes' or 'no'.)ZyZyes)ZnZno)
sysZstdoutZwriteZflushstdinZreadlineZlowerZstripr   _)msgZprintmsgZinps   &  +/usr/share/virt-manager/virtinst/virtxml.pyprompt_yes_or_nor      sy    
#

"

ii  "((*002,K89:    c                 s    \         P                  ! WR R4      pV'       d   \        P                  ! RV4       V# \        P                  ! R4       V# )zOriginal XMLzAltered XMLzXML diff:
%sz(No XML diff, didn't generate any change.)r   diffr   debug)origxmlnewxmlr      && r   get_diffr   &   s@    <<GD		/4( K 			<=Kr   c                 s    Vf   R # \         P                  ! V4      pVP                  4       '       d"   V P                  VP                  4       4       R # R # N)r   Zparse_osinfoZget_nameZset_os_name)guestosinfoZosdatar   r   
set_osinfor   0   sA    ~f%F&//+, r   c                 sn    \         P                  ! VR R7      p\        WR7      P                  4       pWB8H  # )T)Zinactiveparsexml)r   Zget_xmldescr   get_xml)conndomainoriginal_xmlZrawxmlZnew_xmls   &&&  r   defined_xml_is_unchangedr!   9   s.    __Vd3FD*224G""r   c                   sj   a  ] tR t^Dt o RtR t]R 4       t]R 4       t]R 4       t	]R 4       t
RtV tR# )	Actionz_
Helper class tracking one pair of
    XML ACTION (ex. --edit) and
    XML OPTION (ex. --disk)
c                s6    Wn         W n        W0n        W@n        R # r   )action_nameselectorparserclassparservalue)selfr#   r$   r%   r&   s   &&&&&r   __init__ZAction.__init__K   s    & &&r   c                     V P                   R 8H  # )editr#   r'      &r   is_editZAction.is_editU   s    6))r   c                r)   )
add-devicer+   r,   r-   r   is_add_deviceZAction.is_add_deviceY   s    <//r   c                r)   )remove-devicer+   r,   r-   r   is_remove_deviceZAction.is_remove_device]   s    ?22r   c                r)   )	build-xmlr+   r,   r-   r   is_build_xmlZAction.is_build_xmla   s    ;..r   )r#   r%   r&   r$   N)Z__name__Z
__module__Z__qualname__Z__firstlineno__Z__doc__r(   Zpropertyr.   r0   r2   r4   Z__static_attributes__Z__classdictcell__)Z__classdict__s   @r   r"   r"   D   s_     ' * * 0 0 3 3 / /r   r"   c                 sF   VP                   es   V P                  '       d   \        \        R4      4       V P                  '       d   \        \        R4      4       V P
                  '       d   \        \        R4      4       V P                  P                  '       gO   V P
                  '       d=   \        \        R4      P                  V P                  P                  4       R7      4       \        V4      pV P                  P                  V4      '       g   V P                  '       d=   \        \        R4      P                  V P                  P                  4       R7      4       V P                  '       d=   \        \        R4      P                  V P                  P                  4       R7      4       VP                  '       d]   V P                  P                  '       g?   \        \        R4      P                  V P                  P                  4       R7      4       R # R # R # )	Nz2--osinfo/--os-variant is not supported with --editz;--osinfo/--os-variant is not supported with --remove-devicez7--osinfo/--os-variant is not supported with --build-xmlz(--build-xml not supported for {cli_flag}cli_flagz*Cannot use --remove-device with {cli_flag}z'Cannot use --add-device with {cli_flag}z)Don't know how to --update for {cli_flag})r   r.   r   r   r2   r4   r%   guest_propnameformatcli_flag_namer   Zprop_is_listr0   update)actionr   optionsZ
stub_guests   &&& r   validate_actionr=   f   s   ~~!>>>GHI"""PQRLMN,,,1D1D1D89@@++99; A 	
 tJ**:66""">?FF#//==? G 
 ;<CC#//==? D  ~~~f00???9:AA++99; B 	
 @~r   c                 s   . p. ROpV F;  pVP                  RR4      p\        W4      pVR9  g   K)  VP                  W534       K=  	  \        V4      ^ 8X  dB   \	        \        R4      RP                  V Uu. uF  pRV,           NK  	  up4      ,          4       \        V4      ^8  dI   \	        \        R4      RP                  V Uu. uF  pRV^ ,          ,           NK  	  up4      ,          4       V^ ,          w  rxWx3# u upi u upi )	r*   -r   zOne of %s must be specified.z, --zConflicting options %s)r*   r/   r1   r3   )F)Zreplacegetattrappendlenr   r   Zjoin)	r<   
collisionsZactionsZclinameZoptnamevaluecr#   r$   s	   &        r   check_action_collisionrG      s    JBG//#s+)#w./	  :!Q-.g;VgD1HHg;V1WWX
:Q'(499:5V:adQqTkk:5V+WWX&qMK   <W5Vs   6C?Dc                 s   . p\         P                   F4  p\        WP                  4      pV'       g   K"  VP	                  W#34       K6  	  \        V4      ^ 8X  d   \        \        R4      4       \        V4      ^8w  d@   \        \        R4      V Uu. uF  qD^ ,          P                  4       NK  	  up,          4       V^ ,          w  r%W%3# u upi )r    zNo change specified.zCOnly one change operation may be specified (conflicting options %s))	r   ZVIRT_PARSERSrA   Zcli_arg_namerB   rC   r   r   r9   )r<   rD   r%   rE   rF   r&   s   &     r   check_xmlopt_collisionrH      s    J''!9!9:5{23 (
 :!Q%&'
:!ST-78Zt!!#Z89	

  *!}K##	 9s   C
c                 sj    \        V4      w  r#\        V4      w  rE\        WEW#4      p\        W`V4       V# r   )rH   rG   r"   r=   )r   r<   r%   r&   r#   r$   r;   s   &&     r   parse_actionrI      s;      6g>K 37;KK;DFF'*Mr   c           	      sn   \         P                  ! VP                  V 4      4      pR pVf   ^pMUVP                  4       '       g5   VP	                  R4      '       d)   VR,          P                  4       '       d   \        V4      pVe   V^ 8X  d   \        \        R4      V,          4       V'       g3   \        \        R4      P                  VP                  4       R7      4       \        V4      \        V4      8  dI   \        \        RR\        V4      4      P                  V\        V4      VP                  4       R7      4       V^ 8  d
   V^,          pWE,          pV# VR	8X  d   VR
,          pV# V! W R7      pVP                  4       pV'       g$   \        \        R4      RV: RV: 2,          4       V# )Nr>   :r	   NNzInvalid --edit option '%s'z&No {cli_flag} objects found in the XMLr5   zR'--edit {number}' requested but there's only {maxnum} {cli_flag} object in the XMLzU'--edit {number}' requested but there are only {maxnum} {cli_flag} objects in the XML)ZnumberZmaxnumr6   all:NNN)r   z No matching objects found for %sr?   Z )r   listifyZlookup_propZisdigitZ
startswithZintr   r   r8   r9   rC   ZabsZngettextZlookup_child_from_option_string)r   r#   Zeditvalr%   ZobjlistZidxinstZ	parserobj   &&&&    r   _find_objects_to_editrN      sy   ook55e<=G
C			g0055'"+:M:M:O:O'l
!8/07:;:;BB(668 C 
 w<#c("<=L &CL;C\C\C^&_ 71HC| K 
E	qz K  5	88:56{T[:\]^Kr   c           	      s   V P                   pV P                  pV P                  pVP                  '       d   \	        VR WB4      pMJTpV'       dA   VR8w  d:   VR8w  d3   \        \        R4      P                  WBP                  4       R7      4       . p\        P                  ! V4       F"  pV\        P                  ! WW7R7      ,          pK$  	  V# )r*   Z1rJ   zM'--edit {option}' doesn't make sense with {cli_flag}, just use empty '--edit')Zoptionr6   )editinst)r%   r&   r$   r7   rN   r   r   r8   r9   r   rK   r   
run_parser)r;   r   r%   r&   r$   rL   devsrO   s   &&      r   action_editrR      s    $$K$$KH!!!$UFHJCH,=: &3L3L3N&O	 DOOD)u;RR *Kr   c                 s    V P                   pV P                  p\        W4       V'       d   V F  pVP                  V4       K  	  TpV# \        P
                  ! WV4      pV F  pVP                  V4       K  	  V# r   )r%   r&   r   Z
add_devicer   rP   set_defaults)r;   r   r   
input_devsr%   r&   devrQ   rM   r   action_add_devicerV     sx    $$K$$KuCS!  K	 ~~e+>CU#  Kr   c                 s    V P                   pV P                  R,          p\        VRW24      p\        P                  ! V4      pV F  pVP                  V4       K  	  V# )r	   r1   r@   )r%   r&   rN   r   rK   Zremove_devicer;   r   r%   r&   rQ   rU      &&    r   action_remove_devicerY   "  sV    $$K$$R(K RD??4 DC  Kr   c                 s    V P                   pV P                  p\        P                  ! WV4      pV F  pVP	                  V4       K  	  V# r   )r%   r&   r   rP   rS   rW   rX   r   action_build_xmlrZ   .  sE    $$K$$K>>%k:D Kr   c                 s   V P                   '       d   \        WVP                  V4      # V P                  '       d   \	        W4      # V P
                  '       d   \        W4      # \        P                  ! R V P                  ,          4      h)z7perform_action() incorrectly called with action_name=%s)
r0   rV   r   r2   rY   r.   rR   r   DevErrorr#   )r;   r   r<   rT   s   &&&&r   perform_actionr\   8  sm     
KK#F22~~~6))


AFDVDVV r   c                 s    \        V R R4      R8w  d   R# \        P                  ! RV 4       V P                  \        P
                  ! 4       4       R# )ZDEVICE_TYPENZdiskzDoing setup for disk=%s)rA   r   r   Zbuild_storager   Z	get_meter)rU   r-   r   setup_devicer]   D  s9    sM4(F2II'-cmmo&r   c                 sD   V'       d.   \        \        R 4      VP                  ,          4      '       g   R# VP                  '       d   V F  p\	        V4       K  	  V P                  VP                  4       4      p\        \        R4      VP                  ,          4       V# )z!Define '%s' with the changed XML?Fz!Domain '%s' defined successfully.)r   r   namer0   r]   Z	defineXMLr   r   )r   inactive_xmlobjrQ   r;   confirmrU   doms   &&&&&  r   define_changesrb   L  sy    "E FI]I] ]^^C  ..002
3C67/:N:NNOJr   c                 s   V'       d.   \        \        R 4      VP                  ,          4      '       g   R# VP                  '       d   V F  p\	        V4       K  	   V P                  VP                  4       4      p\        \        R4      VP                  ,          4       V#   \        P                   d5   p\        \        R4      RTP                  RT/,          4        Rp?R# Rp?ii ; i)z Start '%s' with the changed XML?F!Domain '%s' started successfully..Failed starting domain '%(domain)s': %(error)sr   errorN)r   r   r^   r0   r]   Z	createXMLr   r   libvirtlibvirtErrorr   )r   xmlobjrQ   r;   r`   rU   ra   es   &&&&&   r   start_domain_transientrj   Z  s    "D E STTC nnV^^-. 	Q:;fkkIJ
  
>?&++	
 	

s   B# #C,8)C''C,c                 sr   VP                   '       d#   \        R 4      p\        R4      p\        R4      pMVP                  '       d#   \        R4      p\        R4      p\        R4      pM[VP                  '       d#   \        R4      p\        R4      p\        R4      pM'\        P
                  ! R	VP                  ,          4      hV EF!  pVP                  4       pV'       d/   VR
VRV P                  4       /,          p	\        V	4      '       g   KJ  VP                   '       d   \        V4        VP                   '       d"   V P                  V\        P                  4       MeVP                  '       d"   V P                  V\        P                  4       M2VP                  '       d!   V P                  V\        P                  4       \)        V4       V'       g   EK  \)        R4       EK$  	  R#   \        P                    d4   p
R\"        P$                  9  d   \'        TRT
/,          4        Rp
?
LkRp
?
ii ; i)z7%(xml)s

Hotplug this device to the guest '%(domain)s'?zDevice hotplug successful.z*Error attempting device hotplug: %(error)sz;%(xml)s

Hotunplug this device from the guest '%(domain)s'?zDevice hotunplug successful.z,Error attempting device hotunplug: %(error)sz7%(xml)s

Update this device for the guest '%(domain)s'?zDevice update successful.z)Error attempting device update: %(error)sz2update_changes() incorrectly called with action=%sxmlr   Z$VIRTXML_TESTSUITE_UPDATE_IGNORE_FAILre   N )r0   r   r2   r.   r   r[   r#   r   r^   r   r]   ZattachDeviceFlagsrf   ZVIR_DOMAIN_AFFECT_LIVEZdetachDeviceFlagsZupdateDeviceFlagsrg   osZenvironr   r   )r   rQ   r;   r`   Zmsg_confirmZmsg_successZmsg_failrU   rk   r   ri   s   &&&&       r   update_changesrn   r  s   ST45AB		 	 	 WX67CD	ST34@A@6CUCUU
 	
 kkms&++-! C $C((		.###((g.L.LM(((((g.L.LM((g.L.LM
 	[!77 * ## 	.5RZZGX!,-	.s6   .G.  G.!G.3 G.G.& G..H6)H11H6c                s   V P                  4       pV P                  V P                  VR7      p\        W%W4      pVP                  4       p\	        WG4      pV'       g    \
        P                  ! \        R4      4       VP                  '       d   V'       d   \        V4       We3# VP                  '       d   \        V4       We3# )z
Perform requested XML edits locally, but don't submit them to libvirt.
Optionally perform any XML printing per user request

:returns: (list of device objects, altered xmlobj)
)r   r   zENo XML diff was generated. The requested changes will have no effect.)r   Z	__class__r   r\   r   r   warningr   
print_diffr   	print_xml)	Zorig_xmlobjr<   r;   rT   r   rh   rQ   r   r   s	   &&&&     r   prepare_changesrr     s     !!#G""(8(87"KF&'>D^^FG$DA]^_ < 
			V<r   c                  s8   \         P                  ! R \        R4      RR7      p \         P                  ! V R4       V P	                  RR\        R4      R7       V P                  \        R	4      4      pVP	                  R
RR5\        R4      R7       VP	                  RR\        R4      R7       VP	                  RR\        R4      R7       VP	                  RR\        R4      R7       V P                  \        R4      4      pVP	                  RR\        R4      R7       VP                  4       pVP	                  RR\        R4      R7       VP	                  RRR\        R4      R7       VP                  RR 7       VP	                  R!R\        R"4      R7       VP	                  R#R\        R$4      R7       VP	                  R%R\        R&4      R7       VP	                  R'R\        R(4      R7       \         P                  ! V R)R*7       V P                  \        R+4      4      p\         P                  P                  4        VP	                  R,R\         P                  P                  \        R-4      R.7       \         P                  P                  4        VP	                  R/R\         P                  P                  \        R04      R.7       V P                  \        R14      4      p\         P                  ! VRR27       \         P                  ! V4       \         P                   ! V4       \         P"                  ! V4       \         P$                  ! V4       \         P&                  ! VRR27       \         P(                  ! V4       \         P*                  ! V4       \         P,                  ! V4       \         P.                  ! V4       V P                  \        R34      4      p\         P0                  ! VR)R)R)R47       \         P2                  ! V 4       V P5                  4       # )6z%(prog)s [options]z,Edit libvirt XML using command line options.T)Zintrospection_epilogvirt-xmlr   Z?zDomain name, id, or uuid)nargshelpzXML actionsz--editzEdit VM XML. Examples:
--edit --disk ...     (edit first disk device)
--edit 2 --disk ...   (edit second disk device)
--edit all --disk ... (edit all disk devices)
--edit target=hda --disk ... (edit disk 'hda')
)rt   Zdefaultru   z--remove-deviceZ
store_truezRemove specified device. Examples:
--remove-device --disk 1 (remove first disk)
--remove-device --disk all (remove all disks)
--remove-device --disk /some/path)r;   ru   z--add-devicez6Add specified device. Example:
--add-device --disk ...z--build-xmlzWOutput built device XML. Domain is optional but recommended to ensure optimal defaults.zOutput options--updatezApply changes to the running VM.
With --add-device, this is a hotplug operation.
With --remove-device, this is a hotunplug operation.
With --edit, this is an update device operation.z--definezKForce defining the domain. Only required if a --print option was specified.z--no-definedefineZstore_falsezForce not defining the domain.)Zdestr;   ru   N)rw   --startzStart the domain.z--print-diffz/Only print the requested change, in diff formatz--print-xmlz3Only print the requested change, in full XML formatz	--confirmz/Require confirmation before saving any results.F)ZvirtinstallzConversion optionsz--convert-to-q35z-Convert an existing VM from PC/i440FX to Q35.)rt   Zconstru   z--convert-to-vnczXConvert an existing VM to use VNC graphics. This removes any remnants of Spice graphics.zXML options)ZeditexamplezMiscellaneous Options)ZpromptZprintxmlZdryrunr@   )r   ZsetupParserr   Zadd_connect_optionZadd_argumentZadd_argument_groupZadd_mutually_exclusive_grouprS   Zadd_osinfo_optionZParserConvertToQ35ZregisterZVirtCLIParserZOPTSTR_EMPTYZParserConvertToVNCZadd_disk_optionZadd_net_optionZadd_gfx_optionZadd_metadata_optionZadd_memory_optionZvcpu_cli_optionsZadd_xml_optionZadd_guest_xml_optionsZadd_boot_optionsZadd_device_optionsZadd_misc_optionsZautocomplete
parse_args)ZparserZactgZoutgZdefine_gZconvZgZmiscs          r   ry   ry     s   __	
89!F 6:.
!4N2OP$$Q}%56D?
	   	0
  	 	HI  
 	6
   $$Q'7%89D?
  	 002H\]  
 H]CcAd   &i1=P;QR@A  
 	DE  
 	Lq1b/c   &e4$$Q';%<=D##%,,>?	   ##%,,;
	   	!!!M"23At,qqA!-qa 1$$Q'>%?@DeeEJVr   c                 s
   \         P                  ! 4        \        4       pVP                  '       g7   VP                  '       g%   VP
                  '       g   VP                  '       d   R Vn        \         P                  ! RVP                  VP                  4       \         P                  ! V4      '       d   ^ # \         P                  ! V4      '       d   ^ # RVn        VP                  '       g   VP                  '       g   \        P                  P                   '       g   \        P                  P#                  4       '       gq   VP                  '       d   \%        \'        R4      4       VP(                  '       d   \%        \'        R4      4       \        P                  P+                  4       Vn        M\%        \'        R4      4       VP                  '       gT   VP
                  '       gB   VP                  '       d   VP,                  '       g   RVn        MVP,                  f   RVn        VP                  '       d   VP                  '       g   RVn        \         P.                  ! VP0                  V 4      p \3        W4      pRpRpRpVP                  '       d%   \         P4                  ! WP                  4      w  r5pM\7        WP                  R7      p\9        V4      pVP:                  '       dD   \=        W%4      pV F0  p\?        \@        PB                  ! VPE                  4       4      4       K2  	  ^ # Rp	R p
VP(                  '       d   VP(                  '       d   VPF                  '       d   \I        RR	4       V'       d(   \K        WAV4      w  r\M        W9W!P                  4       Rp
M\N        PP                  ! \'        R
4      4       VP,                  '       g   ^ # VPE                  4       p\K        WQW)R7      w  rVP,                  '       g,   VPF                  '       d   \S        WWVP                  4       ^ # \U        WWVP                  4      pV'       g   ^ # VPF                  '       d9    VPW                  4        \?        \'        R4      VP\                  ,          4       ^ # V'       d   V
'       g   \?        \'        R4      4       ^ # \_        WV4      '       d    \N        PP                  ! \'        R4      4       ^ #   \X        PZ                   d4   p\%        \'        R4      RTP\                  RT/,          4        Rp?LRp?ii ; i)Frs   Nz%Can't use --confirm with stdin input.z$Can't use --update with stdin input.zA domain must be specifiedTr   rv   rx   z0The VM is not running, --update is inapplicable.)rT   rd   r   re   rc   z?Changes will take effect after the domain is fully powered off.zhXML did not change after domain define. You may have changed a value that libvirt is setting by default.)0r   ZearlyLoggingry   r`   rq   rp   Z	build_xmlZquietZsetupLoggingr   Zcheck_option_introspectionZcheck_osinfo_listZstdinxmlr   r
   r   ZclosedZisattyr   r   r:   Zreadrw   ZgetConnectionZconnectrI   Zget_domain_and_guestr   Zboolr4   rZ   r   r   Zunindent_device_xmlr   Zstartr   rr   rn   r   ro   rj   rb   Zcreaterf   rg   r^   r!   )r   r<   r;   r   Zactive_xmlobjr_   Zvm_is_runningZ
built_devsrU   rT   Zperformed_updateZdummyr    rQ   Zxmlobj_to_definera   ri   s   &                r   mainrz   D  s   lG'+++w/A/A/AWEVEVEVZ>
%%g..
W%%G>>>'"3"3"3yy		(8(8(:(:Q>?@~~~Q=>?"yy~~/G/01 W%7%7%7>>>$(!~~%!%w000!W__d3D$(FFMO~~~141I1I$P^P^1_./?/?@'M%f>
C44S[[]CD  J~~~>>>gmmmZ3 / OJ6vG#KKLMN~~~"**,L,&D >>>==="44Y
w
OC}}}		JJL 	Q:;o>R>RRS  
/QXYZ  
"$\	:	:K	
 ) ## 	BCo22Q 	s   0T   U)UUc                  sf    \         P                  ! \        4       4       R #   \         d,   p \         P                  ! T P                  4        R p ? R # R p ? i\
         d1    \        P                  ! RRR7       \        \        R4      4        R # \         d   p\        T4        R p?R # R p?ii ; i)Nrl   T)Zexc_infozAborted at user request)r
   Zexitrz   Z
SystemExitZcodeZKeyboardInterruptr   r   r   r   Z	Exceptionr   )Zsys_eZmain_es     r   runclir{     sn      3		"t$Q012 Vs2   " B0 AB0 -B0B0B0B++B0r   )%rm   r
   rf   rl   r   r   r   r   r   r   r   Zloggerr   r   r   r   r   r!   r"   r=   rG   rH   rI   rN   rR   rV   rY   rZ   r\   r]   rb   rj   rn   rr   ry   rz   r{   ) r   r   <module>r|      s    
 
   C C   ;-#/ /D$
N!$$&,.b.$		'0-`>{Fm`	r   