
    W'Fg!                     n    S SK r S SKrSSKJr  SSKJrJrJr  SSKJr  S r	S r
S rS	 rS
 rSS jrS rg)    N   )cli)failprint_stdoutprint_stderr)Clonerc                     U R                   nS nU R                  (       a&  [        U R                  5      R                  5       nX4$ U(       d  [	        [        S5      5        X4$ )NzNAn original machine name is required, use '--original src_name' and try again.)src_nameoriginal_xmlopenreadr   _)optionsr
   src_xmls      -/usr/share/virt-manager/virtinst/virtclone.py_process_srcr      sa    HGw++,113  Q 8 9 	:    c                    U R                   nU(       a	  US   S:X  a  g U H$  n[        R                  " UR                  U5        M&     UR                  R
                  R                  S S   H  nUR                  S5      Ul        M     g )Nr   RANDOM)	new_macr   validate_macconn	new_guestdevices	interfacepopmacaddr)r   clonernew_macsmacifaces        r   _process_macsr"      sl    Hx{h.c*  !!))33A6 Q 7r   c                 V   U R                   =(       d    / S S  nUR                  5       nU H{  nUR                  R                  5       nS nU(       a  UR	                  S5      nOU R
                  (       a    g Uc  S nUR                  X`R                  5        UR                  5         M}     g )Nr   )	new_diskfileget_nonshare_diskinfosdiskget_source_pathr   
auto_cloneset_new_pathsparseraise_error)r   r   newpaths	diskinfosdiskinfoorigpathnewpaths          r   _process_disksr1   %   s    $$*A.H--/I==002ll1oGGg~~6 r   c                     U R                  5        HZ  nUR                  5         UR                  (       d  M&  UR                  5       (       + n[        R
                  " UR                  US9  M\     g )N)warn_overwrite)get_diskinfosr+   new_diskis_preserve_requestedr   validate_disk)r   r.   r3   s      r   _validate_disksr8   7   sW    ((*  %;;==(++-	/ +r   c            	         [        S5      n [        R                  " SU 5      n[        R                  " U5        UR	                  [        S5      5      nUR                  SSS[        S5      S9  UR                  S	[        S
5      S9  UR                  SS[        S5      S9  UR                  SSS[        S5      S9  UR                  SSS[        R                  S9  UR                  SS[        S5      S9  UR	                  [        S5      5      nUR                  SSSS[        S5      S9  UR                  S S!S[        S"5      S9  UR                  S#S[        S$5      S9  UR                  S%S&S'S([        S)5      S*9  UR                  S+S,SS-[        S.5      S/9  UR                  S0S1[        S25      S9  UR	                  [        S35      5      nUR                  S4S5S6S[        S75      S9  UR	                  [        S85      5      nUR                  S9SS:S-[        R                  S*9  [        R                  " US(S(S(S;9  [        R                  " U5        UR                  5       $ )<Na  Duplicate a virtual machine, changing all the unique host side configuration like MAC address, name, etc. 

The VM contents are NOT altered: virt-clone does not change anything _inside_ the guest OS, it only duplicates disks and does host side changes. So things like changing passwords, changing static IP address, etc are outside the scope of this tool. For these types of changes, please see virt-sysprep(1).z%(prog)s --original [NAME] ...zGeneral Optionsz-oz
--originalr
   z$Name of the original guest to clone.)desthelpz--original-xmlz&XML file to use as the original guest.)r;   z--auto-clone
store_truezQAuto generate clone name and storage paths from the original guest configuration.)actionr;   z-nz--namenew_namezName for the new guestz-uz--uuidnew_uuidz	--reflinkzuse btrfs COW lightweight copyzStorage Configurationz-fz--filer$   appendz3New file to use as the disk image for the new guest)r:   r=   r;   z--force-copytargetzQForce to copy devices (eg, if 'hdc' is a readonly cdrom device, --force-copy=hdc)z--skip-copyzSkip copy of the device target. (eg, if 'vda' is a disk you don't want to copy and use the same path in the new VM, use --skip-copy=vda)z--nonsparsestore_falser*   Tz3Do not use a sparse file for the clone's disk image)r=   r:   defaultr;   z--preserve-datapreserveFzDo not clone storage contents to specified file paths, their contents will be left untouched. This requires specifying existing paths for every cloneable disk image.)r:   r=   rC   r;   z--nvram	new_nvramz)New file to use as storage for nvram VARSzNetworking Configurationz-mz--macr   zNNew fixed MAC address for the clone guest. Default is a randomly generated MACzMiscellaneous Optionsz--__test-nodry
test_nodry)promptreplaceprintxml)r   r   setupParseradd_connect_optionadd_argument_groupadd_argumentargparseSUPPRESSadd_misc_optionsautocomplete
parse_args)descparsergengstognetgmiscs         r   rR   rR   B   s    M ND __=tDF6"$$Q'8%9:DdLzAB  D&CD  Fn\ @ A  B 	dH:34  6dH:H<M<MNk,34  6 $$Q'>%?@DdH>( ' (  ) 	n8H F G  H 	mH A B  C 	mM  ( )  * 	'j 1 2  3 	ikHI  K $$Q'A%BCDdG)H A B  C $$Q'>%?@D 	&|,#(*;*;  = dD4HVr   c                    [         R                  " 5         [        5       nUR                  =(       d    UR                  Ul        [         R
                  " SUR                  UR                  5        [         R                  " U5        [         R                  " UR                  5        [         R                  " UR                  5        [         R                  " UR                  U S9n UR                  c#  UR                  SL a  [!        [#        S5      5        [%        U5      u  p#['        XU5      nUR)                  [+        UR,                  5      5        UR/                  [+        UR0                  5      5        UR3                  [+        UR4                  5      5        UR6                  b  UR9                  UR6                  5        UR:                  (       a  UR=                  UR:                  5        UR>                  =(       d    / nUR@                  =(       d    / nURC                  5        HY  nURD                  R>                  U;   a  URG                  5         URD                  R>                  U;   d  MI  URI                  5         M[     URJ                  (       aR  URM                  5        H  nURO                  5         M     URP                  (       a  URP                  RO                  5         URR                  (       a  URU                  URR                  5        O%UR                  (       d  [!        [#        S5      5        [W        X5        [Y        X5        UR[                  5         []        U5        SnUR                  (       a.  UR^                  n[a        URb                  Re                  5       SS9  U(       aZ  URg                  [         Rh                  " 5       5        [a        S5        [a        [#        S	5      URb                  Rj                  -  5        g
)Nz
virt-clone)r   FzVEither --auto-clone or --file is required, use '--auto-clone or --file' and try again.zXA name is required for the new virtual machine, use '--name NEW_VM_NAME' to specify one.T)do_force z Clone '%s' created successfully.r   )6r   earlyLoggingrR   quietxmlonlysetupLoggingdebugconvert_old_forceparse_checkcheck
set_promptrG   getConnectionconnectr$   r(   r   r   r   r   set_replaceboolrH   set_reflinkreflink
set_sparser*   r?   set_clone_uuidrE   set_nvram_pathrA   	skip_copyr4   r&   set_clone_requestedset_share_requestedrD   r%   set_preserve_requestednvram_diskinfor>   set_clone_namer"   r1   preparer8   rF   r   r   get_xmlstart_duplicate	get_metername)	r   r   r
   r   r   force_targetsskip_targetsr.   runs	            r   mainr|      s   lGMM4W__GM\7=='--@'"OOGMM"NN7>>"W__48D$e#Q > ? 	@ %W-HDG,F
tGOO,-
tGOO,-
d7>>*+#g../g//0NN(bM$$*L((*===0((*==</((*	 + 557H++- 8  !!88:g../Q 8 9 	: '"7#
NNF
C  V%%--/$?
s}}/RQ9:V=M=M=R=RRSr   c                  (    [         R                  " [        5       5        g ! [         a*  n [         R                  " U R                  5         S n A g S n A f[
         a    [        [        S5      5         g [         a  n[        U5         S nAg S nAff = f)Nz$Installation aborted at user request)
sysexitr|   
SystemExitcodeKeyboardInterruptr   r   	Exceptionr   )sys_emain_es     r   runclir      sa      @Q=>? Vs&   ! 
B A!B3	B<BB)N)rN   r~   r[   r   r   r   r   r   r   r   r"   r1   r8   rR   r|   r    r   r   <module>r      s@     
  1 1 	($/@FAHr   