Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit c945616

Browse files
committed
virt-clone: Add --print-xml option
1 parent b10662a commit c945616

6 files changed

Lines changed: 174 additions & 4 deletions

File tree

man/en/virt-clone.pod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ guest XML.
134134

135135
=over 2
136136

137+
=item --print-xml
138+
139+
Print the generated clone XML and exit without cloning.
140+
137141
=item -d, --debug
138142

139143
Print debugging information to the terminal when running the install process.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0"?>
2+
<domain type="xen" id="3">
3+
<name>test-for-clone1</name>
4+
<uuid>00000000-1111-2222-3333-444444444444</uuid>
5+
<memory>409600</memory>
6+
<currentMemory>204800</currentMemory>
7+
<vcpu>5</vcpu>
8+
<os>
9+
<type arch="i686">hvm</type>
10+
<loader>/usr/lib/xen/boot/hvmloader</loader>
11+
<boot dev="hd"/>
12+
</os>
13+
<features>
14+
<acpi/>
15+
<apic/>
16+
</features>
17+
<clock offset="utc"/>
18+
<on_poweroff>destroy</on_poweroff>
19+
<on_reboot>restart</on_reboot>
20+
<on_crash>restart</on_crash>
21+
<devices>
22+
<emulator>/usr/lib/xen/bin/qemu-dm</emulator>
23+
<disk type="block" device="disk">
24+
<source dev="/disk-pool/diskvol1-clone"/>
25+
<target dev="sda" bus="scsi"/>
26+
<address type="drive" controller="0" bus="0" unit="0"/>
27+
</disk>
28+
<disk type="block" device="cdrom">
29+
<target dev="sdb" bus="scsi"/>
30+
<readonly/>
31+
<address type="drive" controller="0" bus="0" unit="1"/>
32+
</disk>
33+
<disk type="block" device="disk">
34+
<source dev="/default-pool/collidevol1.img"/>
35+
<target dev="sdc" bus="scsi"/>
36+
<readonly/>
37+
<address type="drive" controller="0" bus="0" unit="2"/>
38+
</disk>
39+
<disk type="block" device="disk">
40+
<source dev="/default-pool/sharevol.img"/>
41+
<target dev="sdx" bus="scsi"/>
42+
<shareable/>
43+
<address type="drive" controller="3" bus="0" unit="2"/>
44+
</disk>
45+
<controller type="scsi" index="0"/>
46+
<controller type="scsi" index="1"/>
47+
<controller type="scsi" index="2"/>
48+
<controller type="scsi" index="3"/>
49+
<interface type="network">
50+
<mac address="00:11:22:33:44:55"/>
51+
<source network="default"/>
52+
<target dev="testnet0"/>
53+
<model type="e1000"/>
54+
</interface>
55+
<interface type="user">
56+
<mac address="00:11:22:33:44:55"/>
57+
<target dev="testnet1"/>
58+
</interface>
59+
<parallel type="file">
60+
<source path="/tmp/foo.log"/>
61+
<target port="0"/>
62+
</parallel>
63+
<memballoon model="xen"/>
64+
</devices>
65+
</domain>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0"?>
2+
<domain type="xen" id="2">
3+
<name>newvm</name>
4+
<uuid>00000000-1111-2222-3333-444444444444</uuid>
5+
<memory>409600</memory>
6+
<currentMemory>204800</currentMemory>
7+
<vcpu>5</vcpu>
8+
<os>
9+
<type arch="i686">hvm</type>
10+
<loader>/usr/lib/xen/boot/hvmloader</loader>
11+
<boot dev="hd"/>
12+
</os>
13+
<features>
14+
<acpi/>
15+
<apic/>
16+
</features>
17+
<clock offset="utc"/>
18+
<on_poweroff>destroy</on_poweroff>
19+
<on_reboot>restart</on_reboot>
20+
<on_crash>restart</on_crash>
21+
<devices>
22+
<emulator>/usr/lib/xen/bin/qemu-dm</emulator>
23+
<disk type="file" device="disk">
24+
<source file="/default-pool/newvm.img"/>
25+
<target dev="hda" bus="ide"/>
26+
<address type="drive" controller="0" bus="0" unit="0"/>
27+
</disk>
28+
<controller type="ide" index="0"/>
29+
<interface type="user">
30+
<mac address="00:11:22:33:44:55"/>
31+
<target dev="testnet0"/>
32+
</interface>
33+
<parallel type="file">
34+
<source path="/tmp/foo.log"/>
35+
<target port="0"/>
36+
</parallel>
37+
<memballoon model="xen"/>
38+
</devices>
39+
</domain>

tests/clitest.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,13 @@
746746
"--auto-clone"
747747
# Auto flag, actual VM, without state skip
748748
"-o test-for-clone --auto-clone",
749-
]
749+
],
750+
751+
"compare" : [
752+
("-o test-for-clone --auto-clone --clone-running", "clone-auto1"),
753+
("-o test-clone-simple --name newvm --auto-clone --clone-running",
754+
"clone-auto2"),
755+
],
750756
}, # category "misc"
751757

752758
"remote" : {
@@ -1015,6 +1021,10 @@ def run_tests(do_app, do_category):
10151021
if not cmdstr.count("--print"):
10161022
cmdstr += " --print"
10171023

1024+
elif app == "virt-clone":
1025+
if not cmdstr.count("--print-xml"):
1026+
cmdstr += " --print-xml"
1027+
10181028
if not cmdstr.count(fakeuri):
10191029
cmdstr += " --connect %s" % fakeuri
10201030

tests/testdriver.xml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,39 @@
2929
</devices>
3030
</domain>
3131

32+
<domain type='xen'>
33+
<name>test-clone-simple</name>
34+
<currentMemory>204800</currentMemory>
35+
<memory>409600</memory>
36+
<uuid>12345678-1234-FFFF-1234-12345678FFFF</uuid>
37+
<os>
38+
<type arch='i686'>hvm</type>
39+
<loader>/usr/lib/xen/boot/hvmloader</loader>
40+
<boot dev='hd'/>
41+
</os>
42+
<features>
43+
<acpi/><apic/>
44+
</features>
45+
<clock offset="utc"/>
46+
<on_poweroff>destroy</on_poweroff>
47+
<on_reboot>restart</on_reboot>
48+
<on_crash>restart</on_crash>
49+
<vcpu>5</vcpu>
50+
<devices>
51+
<emulator>/usr/lib/xen/bin/qemu-dm</emulator>
52+
<disk type='file' device='disk'>
53+
<source file='/default-pool/test-clone-simple.img'/>
54+
<target dev='hda' bus='ide'/>
55+
</disk>
56+
<interface type='user'>
57+
<mac address='11:11:11:11:11:11'/>
58+
</interface>
59+
<parallel type='file'>
60+
<source path='/tmp/foo.log'/>
61+
</parallel>
62+
</devices>
63+
</domain>
64+
3265
<domain type='xen'>
3366
<name>test-for-clone</name>
3467
<currentMemory>204800</currentMemory>
@@ -185,6 +218,18 @@
185218
</permissions>
186219
</target>
187220
</volume>
221+
<volume>
222+
<name>test-clone-simple.img</name>
223+
<capacity>1000000</capacity>
224+
<allocation>50000</allocation>
225+
<target>
226+
<permissions>
227+
<mode>0700</mode>
228+
<owner>10736</owner>
229+
<group>10736</group>
230+
</permissions>
231+
</target>
232+
</volume>
188233
<volume>
189234
<name>collidevol1.img</name>
190235
<capacity>1000000</capacity>

virt-clone

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ def parse_args():
181181
parser.add_option_group(netg)
182182

183183
misc = OptionGroup(parser, _("Miscellaneous Options"))
184+
misc.add_option("", "--print-xml", action="store_true", dest="xmlonly",
185+
help=_("Print the generated domain XML rather than define "
186+
"and clone the guest."))
184187
misc.add_option("-d", "--debug", action="store_true", dest="debug",
185188
help=_("Print debugging information"))
186189
misc.add_option("", "--prompt", action="store_true", dest="prompt",
@@ -205,6 +208,7 @@ def main():
205208
cli.earlyLogging()
206209
options, parseargs = parse_args()
207210

211+
options.quiet = options.quiet or options.xmlonly
208212
cli.setupLogging("virt-clone", options.debug, options.quiet)
209213
if parseargs:
210214
fail(_("Unknown argument '%s'") % parseargs[0])
@@ -240,9 +244,12 @@ def main():
240244
# setup design object
241245
design.setup()
242246

243-
# start cloning
244-
meter = progress.TextMeter()
245-
clmgr.start_duplicate(design, meter)
247+
if options.xmlonly:
248+
print_stdout(design.clone_xml, do_force=True)
249+
else:
250+
# start cloning
251+
meter = progress.TextMeter()
252+
clmgr.start_duplicate(design, meter)
246253

247254
print_stdout("")
248255
print_stdout(_("Clone '%s' created successfully.") % design.clone_name)

0 commit comments

Comments
 (0)