<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=UTF-8" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.18975">
<STYLE>@font-face {
        font-family: 宋体;
}
@font-face {
        font-family: Verdana;
}
@font-face {
        font-family: @宋体;
}
@page Section1 {size: 595.3pt 841.9pt; margin: 72.0pt 90.0pt 72.0pt 90.0pt; layout-grid: 15.6pt; }
P.MsoNormal {
        TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman"; FONT-SIZE: 10.5pt
}
LI.MsoNormal {
        TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman"; FONT-SIZE: 10.5pt
}
DIV.MsoNormal {
        TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman"; FONT-SIZE: 10.5pt
}
A:link {
        COLOR: blue; TEXT-DECORATION: underline
}
SPAN.MsoHyperlink {
        COLOR: blue; TEXT-DECORATION: underline
}
A:visited {
        COLOR: purple; TEXT-DECORATION: underline
}
SPAN.MsoHyperlinkFollowed {
        COLOR: purple; TEXT-DECORATION: underline
}
SPAN.EmailStyle17 {
        FONT-STYLE: normal; FONT-FAMILY: Verdana; COLOR: windowtext; FONT-WEIGHT: normal; TEXT-DECORATION: none; mso-style-type: personal-compose
}
DIV.Section1 {
        page: Section1
}
UNKNOWN {
        FONT-SIZE: 10pt
}
</STYLE>
</HEAD>
<BODY style="MARGIN: 10px; FONT-FAMILY: verdana; FONT-SIZE: 10pt">
<DIV><FONT color=#000080 size=2 face=Verdana>Hi Alex,</FONT></DIV>
<DIV><FONT color=#000080></FONT> </DIV>
<DIV><FONT color=#000080>Thanks for your flow chart. But I'm stuck in getting 
Storage Pool here.</FONT></DIV>
<DIV><FONT color=#000080>I try to get StoragePoolPtr by using something 
like</FONT></DIV>
<DIV> </DIV>
<DIV> int num = virConnectNumOfStoragePools( conn );</DIV>
<DIV> </DIV>
<DIV>it truns out num = 0;</DIV>
<DIV> </DIV>
<DIV>I think I missed something and missunderstand the Storage Pool & 
Storage Volume. So I refer to the <A 
href="http://libvirt.org/archstorage.html">http://libvirt.org/archstorage.html</A> and 
<A 
href="http://libvirt.org/guide/html/">http://libvirt.org/guide/html/</A> , 
but guide book about storage is in status "TBD".  So, is there some 
tutorial or guideline I can follow to get the Storage Ptr and then get the XML 
description and finally clone one?</DIV>
<DIV> </DIV>
<DIV>Thank you</DIV>
<DIV> </DIV>
<DIV>Regards</DIV>
<DIV><FONT color=#000080 size=2 face=Verdana></FONT> </DIV>
<DIV><FONT color=#000080 size=2 face=Verdana></FONT> </DIV>
<DIV><FONT color=#c0c0c0 size=2 face=Verdana>2010-11-14 </FONT></DIV><FONT 
color=#000080 size=2 face=Verdana>
<HR style="WIDTH: 100px" align=left color=#b5c4df SIZE=1>
</FONT>
<DIV><FONT color=#c0c0c0 size=2 face=Verdana>Lancer </FONT></DIV>
<HR color=#b5c4df SIZE=1>

<DIV><FONT size=2 face=Verdana><STRONG>发件人:</STRONG> ajia </FONT></DIV>
<DIV><FONT size=2 face=Verdana><STRONG>发送时间:</STRONG> 2010-11-12  10:40:27 
</FONT></DIV>
<DIV><FONT size=2 face=Verdana><STRONG>收件人:</STRONG> 黄亮 </FONT></DIV>
<DIV><FONT size=2 face=Verdana><STRONG>抄送:</STRONG> libvir-list </FONT></DIV>
<DIV><FONT size=2 face=Verdana><STRONG>主题:</STRONG> Re: [libvirt] Is there an 
API for clone? </FONT></DIV>
<DIV><FONT size=2 face=Verdana></FONT> </DIV>
<DIV><FONT size=2 face=Verdana>On 11/12/2010 02:07 AM, 黄亮 wrote: 
<BLOCKQUOTE cite=mid:201011121007066565474@163.com type="cite">
  <META name=GENERATOR content="MSHTML 8.00.6001.18975">
  <STYLE>@font-face {
        font-family: 宋体;
}
@font-face {
        font-family: Verdana;
}
@font-face {
        font-family: @宋体;
}
@page Section1 {size: 595.3pt 841.9pt; margin: 72.0pt 90.0pt 72.0pt 90.0pt; layout-grid: 15.6pt; }
P.MsoNormal {
        TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman"; FONT-SIZE: 10.5pt
}
LI.MsoNormal {
        TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman"; FONT-SIZE: 10.5pt
}
DIV.MsoNormal {
        TEXT-JUSTIFY: inter-ideograph; TEXT-ALIGN: justify; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman"; FONT-SIZE: 10.5pt
}
A:link {
        COLOR: blue; TEXT-DECORATION: underline
}
SPAN.MsoHyperlink {
        COLOR: blue; TEXT-DECORATION: underline
}
A:visited {
        COLOR: purple; TEXT-DECORATION: underline
}
SPAN.MsoHyperlinkFollowed {
        COLOR: purple; TEXT-DECORATION: underline
}
SPAN.EmailStyle17 {
        FONT-STYLE: normal; FONT-FAMILY: Verdana; COLOR: windowtext; FONT-WEIGHT: normal; TEXT-DECORATION: none; mso-style-type: personal-compose
}
DIV.Section1 {
        page: Section1
}
UNKNOWN {
        FONT-SIZE: 10pt
}
BLOCKQUOTE {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; MARGIN-LEFT: 2em
}
OL {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
UL {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
</STYLE>

  <DIV><FONT color=#000080 size=2 face=Verdana>Hi Alex</FONT></DIV>
  <DIV> </DIV>
  <DIV><FONT color=#000080>Thank you for your reply.</FONT></DIV>
  <DIV><FONT color=#000080>I just wanna make sure I'm not misunderstanding, 
  virStorageVolGetXMLDesc & virStorageVolCreateXMLFrom together can do the 
  clone process, am I right?</FONT></DIV></BLOCKQUOTE>In fact, libvirt will call a 
group of APIs to complete vol-clone operation, you can track the whole calling 
process, it  looks like 
this:<BR>                                              
virsh vol-clone <vol-key> 
<newname><BR>                                                                           
|<BR>                                                                          
V<BR>                                                             
virConnectOpenAuth<BR>                                                                           
|<BR>                                                                          
V<BR>                                                        
virStorageVolLookupByKey<BR>                                                                           
|<BR>                                                                          
V<BR>                                                       
virStoragePoolLookupByVolume  ('default' is default 
pool)<BR>                                                                           
|<BR>                    
                      
                      
          V<BR>          
                      
                    
   
virStorageVolGetXMLDesc<BR>                                                                           
|<BR>                                                                          
V<BR>                                                     
virStorageVolCreateXMLFrom<BR>                                                                           
|<BR>                                                                          
V<BR>                    
                      
                 
virStorageVolGetName (twice)<BR>              
                      
                      
                 |<BR>    
                      
                      
                      
    V<BR>            
                
                
                
  virStorageVolFree    (twice) <BR>    
                
                
                
                
       
|<BR>                                                                          
V<BR>                                                             
virStoragePoolFree<BR>                                                                           
|<BR>                                                                          
V<BR>                                                               
virConnectClose<BR>                                                    
<BR>                      
                      
                
                                       
<BR>  Alex<BR>
<BLOCKQUOTE cite=mid:201011121007066565474@163.com type="cite">
  <DIV> </DIV>
  <DIV><FONT color=#000080>Regards</FONT></DIV>
  <DIV> </DIV>
  <DIV> </DIV>
  <DIV><FONT color=#c0c0c0 size=2 face=Verdana>2010-11-12 </FONT></DIV><FONT 
  color=#000080 size=2 face=Verdana>
  <HR style="WIDTH: 100px" align=left color=#b5c4df SIZE=1>
  </FONT>
  <DIV><FONT color=#c0c0c0 size=2 face=Verdana>Lancer </FONT></DIV>
  <HR color=#b5c4df SIZE=1>

  <DIV><FONT size=2 face=Verdana><STRONG>发件人:</STRONG> Alex Jia </FONT></DIV>
  <DIV><FONT size=2 face=Verdana><STRONG>发送时间:</STRONG> 2010-11-10  
  13:28:21 </FONT></DIV>
  <DIV><FONT size=2 face=Verdana><STRONG>收件人:</STRONG> 黄亮 </FONT></DIV>
  <DIV><FONT size=2 face=Verdana><STRONG>抄送:</STRONG> libvir-list </FONT></DIV>
  <DIV><FONT size=2 face=Verdana><STRONG>主题:</STRONG> Re: [libvirt] Is there an 
  API for clone? </FONT></DIV>
  <DIV></DIV>
  <DIV><FONT size=2 face=Verdana>
  <DIV>Hi lancer,</DIV>
  <DIV>As Osier said, libvirt hasn't a independent API for cloning an</DIV>
  <DIV>existing guest, instead of using virStorageVolGetXMLDesc API to </DIV>
  <DIV>get a guest volume xml description and then calling  </DIV>
  <DIV>virStorageVolCreateXMLFrom API to clone a new volume.</DIV>
  <DIV>For python-virtinst component, you may use virt-clone to implement</DIV>
  <DIV>this, for libvirt component, you may directly use python binding</DIV>
  <DIV>API or virsh tool 'vol-clone' to implement it.</DIV>
  <DIV>I hope it's helpful for you.</DIV>
  <DIV>- Alex</DIV>
  <DIV>----- Original Message -----</DIV>
  <DIV>From: "黄亮" <A class=moz-txt-link-rfc2396E 
  href="mailto:lancerhuang@163.com"><lancerhuang@163.com></A></DIV>
  <DIV>To: "libvir-list" <A class=moz-txt-link-rfc2396E 
  href="mailto:libvir-list@redhat.com"><libvir-list@redhat.com></A></DIV>
  <DIV>Sent: Wednesday, November 10, 2010 9:30:28 AM GMT +08:00 Beijing / Chongqing / Hong Kong / Urumqi</DIV>
  <DIV>Subject: [libvirt] Is there an API for clone?</DIV>
  <DIV>Hi, guys </DIV>
  <DIV>I know there is a command "virt-clone", but I couldn't find the equivalent API here : <A 
  class=moz-txt-link-freetext 
  href="http://libvirt.org/html/libvirt-libvirt.html">http://libvirt.org/html/libvirt-libvirt.html</A> </DIV>
  <DIV>So, is there an API to clone an existing VM or not? </DIV>
  <DIV>Thank you! </DIV>
  <DIV>Regards </DIV>
  <DIV>2010-11-10 </DIV>
  <DIV>Lancer </DIV>
  <DIV>--</DIV>
  <DIV>libvir-list mailing list</DIV>
  <DIV><A class=moz-txt-link-abbreviated 
  href="mailto:libvir-list@redhat.com">libvir-list@redhat.com</A></DIV>
  <DIV><A class=moz-txt-link-freetext 
  href="https://www.redhat.com/mailman/listinfo/libvir-list">https://www.redhat.com/mailman/listinfo/libvir-list</A></DIV>
  <DIV>__________ Information from ESET Smart Security, version of virus signature database 5605 (20101109) __________</DIV>
  <DIV>The message was checked by ESET Smart Security.</DIV>
  <DIV><A class=moz-txt-link-freetext 
  href="http://www.eset.com">http://www.eset.com</A></DIV></FONT></DIV></BLOCKQUOTE><BR><BR><BR>__________ 
Information from ESET Smart Security, version of virus signature database 5612 
(20101111) __________<BR><BR>The message was checked by ESET Smart 
Security.<BR><BR><A 
href="http://www.eset.com">http://www.eset.com</A><BR></FONT></DIV></BODY></HTML>