On 08/31/2012 03:13 AM, Alex Jia wrote:
On 08/30/2012 09:38 PM, Tang Chen wrote:
Hi Chris,
I saw libvirt_xml.py and the classes in it. And I'm not sure if I
understand this file correctly.
I think we can put all the xml related work in libvirt testing into
this file.
And I think class LibvirtXML is used to represent a vm's xml.
So I add a function check_interface() into it. This function is used
to check if there is an interface
in the xml which is exactly the same as the parameters describe.
If you want to verify if libvirt's XML configration is valid, you may
use 'virt-xml-validate' tool to do this:
virt-xml-validate XML-FILE [SCHEMA-NAME] - validate libvirt XML files
against a schema
Neat, this would be cool to put into LibvirtXMLBase class as 'validate'
method. Then we can override it in sub-classes so caller doesn't need
to specify SCHEMA-NAME.
It could also be called from __init__() and/or write(), optionally, to
double-check the XML before committing.
If you want to generate libvirt's XML configration, we have ever done
this in internal auto project, the basic idea is to create a XML
construction function for each XML element block such as '<devices> ....
</devices>', '<emulator> ... </emulator>', '<interface xxxxx> ...
</interface>', '<disk xxxxx> ... </disk>', etc. it's very flexible and
easy to reuse, you may use different XML construction function to
generate different libvirt's XML configuration, and also call them to
generate a guest XML configuration.
def emulator_xml(xxxx):
# check emulator based on currently hypervisor then construct
<emulator> ... </emulator>
def iface_xml(xxxx):
# to construct <interface> ... </interface>
def disk_xml(xxxx):
# .....
def devices_xml(xxxx):
......
emu_xml = emulator_xml(xxxx)
iface_xml = iface_xml(xxxx)
disk_xml = disk_xml(xxxx)
# if you want attach 2 disk then you may call disk_xml() 2 times
with different parameters.
# of course, you may use virsh attach-disk or attach-device to do
this later.
......
def guest_xml(xxxx):
......
devices_xml = devices_xml(xxxx)
......
Regards,
Alex
Yep, though since these classes are both ElementTree and files at the
same time, we can follow this model within the __init__ methods for the
various classes. For example:
class VMDiskXML(LibvirtXMLBase):
def __init__(self, type, device, driver, source file, ...):
"""Create VMDiskXML block from parameters"""
Constructors can also accept other libvirt_xml module class instances as
input. Though I think we should stay away from using these classes as
containers. It will be more flexible if they store into their own XML.
Then getter methods (for nested blocks) can produce other instances
dynamical (i.e. parsing the the XML each time) instead of using instance
attributes.
--
Chris Evich, RHCA, RHCE, RHCDS, RHCSS
Quality Assurance Engineer
e-mail: cevich + `@' + redhat.com o: 1-888-RED-HAT1 x44214
_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel