virtinst: Add DomainSnapshot object and some plumbing

Just for parsing domainsnapshot XML and performing some support checks
This commit is contained in:
Cole Robinson 2013-08-05 17:20:35 -04:00
parent 3b9c397d11
commit 9d11c7eae3
6 changed files with 131 additions and 0 deletions

View File

@ -0,0 +1,37 @@
<domainsnapshot>
<name>offline-root-child1</name>
<state>shutoff</state>
<description>offline desk</description>
<parent>
<name>offline-root</name>
</parent>
<creationTime>1375905916</creationTime>
<memory snapshot='no'/>
<disks>
<disk name='hda' snapshot='internal'/>
</disks>
<domain type='test'>
<name>test-internal-snapshots</name>
<uuid>12345678-1234-fddf-1234-12345678ffff</uuid>
<memory unit='KiB'>409600</memory>
<currentMemory unit='KiB'>409600</currentMemory>
<vcpu placement='static'>1</vcpu>
<bootloader>/tmp/bootfoo</bootloader>
<os>
<type arch='i686'>xen</type>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<disk type='file' device='disk'>
<source file='/dev/default-pool/test-clone-simple.img'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
</devices>
</domain>
<active>0</active>
</domainsnapshot>

View File

@ -0,0 +1,39 @@
<domainsnapshot>
<name>name-foo</name>
<state>somestate</state>
<description>foo
newline
indent</description>
<parent>
<name>newparent</name>
</parent>
<creationTime>1234</creationTime>
<memory snapshot="no"/>
<disks>
<disk name="hda" snapshot="internal"/>
</disks>
<domain type="test">
<name>test-internal-snapshots</name>
<uuid>12345678-1234-fddf-1234-12345678ffff</uuid>
<memory unit="KiB">409600</memory>
<currentMemory unit="KiB">409600</currentMemory>
<vcpu placement="static">1</vcpu>
<bootloader>/tmp/bootfoo</bootloader>
<os>
<type arch="i686">xen</type>
</os>
<clock offset="utc"/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<disk type="file" device="disk">
<source file="/dev/default-pool/test-clone-simple.img"/>
<target dev="hda" bus="ide"/>
<address type="drive" controller="0" bus="0" target="0" unit="0"/>
</disk>
<controller type="ide" index="0"/>
</devices>
</domain>
<active>0</active>
</domainsnapshot>

View File

@ -787,6 +787,20 @@ class XMLParseTest(unittest.TestCase):
self._alter_compare(guest.get_xml_config(), outfile) self._alter_compare(guest.get_xml_config(), outfile)
def testChangeSnapshot(self):
basename = "change-snapshot"
infile = "tests/xmlparse-xml/%s-in.xml" % basename
outfile = "tests/xmlparse-xml/%s-out.xml" % basename
snap = virtinst.DomainSnapshot(conn, parsexml=file(infile).read())
check = self._make_checker(snap)
check("name", "offline-root-child1", "name-foo")
check("state", "shutoff", "somestate")
check("description", "offline desk", "foo\nnewline\n indent")
check("parent", "offline-root", "newparent")
check("creationTime", 1375905916, 1234)
utils.diff_compare(snap.get_xml_config(), outfile)
def testzzzzCheckProps(self): def testzzzzCheckProps(self):
# pylint: disable=W0212 # pylint: disable=W0212

View File

@ -61,5 +61,6 @@ from virtinst.distroinstaller import DistroInstaller
from virtinst.guest import Guest from virtinst.guest import Guest
from virtinst.cloner import Cloner from virtinst.cloner import Cloner
from virtinst.snapshot import DomainSnapshot
from virtinst.connection import VirtualConnection from virtinst.connection import VirtualConnection

37
virtinst/snapshot.py Normal file
View File

@ -0,0 +1,37 @@
#
# Copyright 2013 Red Hat, Inc.
# Cole Robinson <crobinso@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
from virtinst.xmlbuilder import XMLBuilder, XMLProperty
class DomainSnapshot(XMLBuilder):
_XML_ROOT_XPATH = "/domainsnapshot"
_XML_PROP_ORDER = ["name", "description", "creationTime"]
name = XMLProperty(xpath="./name")
description = XMLProperty(xpath="./description")
state = XMLProperty(xpath="./state")
creationTime = XMLProperty(xpath="./creationTime", is_int=True)
parent = XMLProperty(xpath="./parent/name")
# Missing bits:
# <memory> @type and @file
# <disks> block which has a psuedo VM disk device
# <domain> block which tracks the snapshot guest XML
# <active> which should list active status for an internal snapshot

View File

@ -342,6 +342,9 @@ SUPPORT_DOMAIN_JOB_INFO = _make(function="virDomain.jobInfo", args=())
SUPPORT_DOMAIN_CONSOLE_STREAM = _make(version=9003) SUPPORT_DOMAIN_CONSOLE_STREAM = _make(version=9003)
SUPPORT_DOMAIN_SET_METADATA = _make(version=9010) SUPPORT_DOMAIN_SET_METADATA = _make(version=9010)
SUPPORT_DOMAIN_CPU_HOST_MODEL = _make(version=9010) SUPPORT_DOMAIN_CPU_HOST_MODEL = _make(version=9010)
SUPPORT_DOMAIN_LIST_SNAPSHOTS = _make(function="virDomain.listAllSnapshots",
args=())
# Pool checks # Pool checks
# This can't ever require a pool object for back compat reasons # This can't ever require a pool object for back compat reasons