| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use Sys::Virt; |
| 7 |
|
| 8 |
my $xml = <<EOF; |
| 9 |
<domain type='kvm'> |
| 10 |
<name>perl-demo</name> |
| 11 |
<memory>219200</memory> |
| 12 |
<currentMemory>219136</currentMemory> |
| 13 |
<vcpu>1</vcpu> |
| 14 |
<os> |
| 15 |
<type arch='i686'>hvm</type> |
| 16 |
<boot dev='network'/> |
| 17 |
</os> |
| 18 |
<features> |
| 19 |
<acpi/> |
| 20 |
</features> |
| 21 |
<clock offset='utc'/> |
| 22 |
<on_poweroff>destroy</on_poweroff> |
| 23 |
<on_reboot>restart</on_reboot> |
| 24 |
<on_crash>destroy</on_crash> |
| 25 |
<devices> |
| 26 |
<serial type='pty'> |
| 27 |
<target port='0'/> |
| 28 |
</serial> |
| 29 |
</devices> |
| 30 |
</domain> |
| 31 |
EOF |
| 32 |
|
| 33 |
|
| 34 |
my $conn = Sys::Virt->new(uri => "qemu:///session"); |
| 35 |
|
| 36 |
print "Starting a transient guest\n"; |
| 37 |
my $dom = $conn->create_domain($xml); |
| 38 |
|
| 39 |
print "Saving the guest\n"; |
| 40 |
|
| 41 |
my $curxml = $dom->get_xml_description(); |
| 42 |
|
| 43 |
$dom->save("perl-demo.img", $curxml, Sys::Virt::Domain::SAVE_BYPASS_CACHE); |
| 44 |
|
| 45 |
my $newxml = $conn->get_save_image_xml_description("perl-demo.img"); |
| 46 |
|
| 47 |
print $newxml; |
| 48 |
|
| 49 |
print "Restoring the guest\n"; |
| 50 |
$conn->restore_domain("perl-demo.img", $newxml, Sys::Virt::Domain::SAVE_BYPASS_CACHE); |
| 51 |
|
| 52 |
print "Destroying the guest\n"; |
| 53 |
$dom = $conn->get_domain_by_name("perl-demo"); |
| 54 |
$dom->destroy; |
| 55 |
|
| 56 |
unlink "perl-demo.img"; |