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.

The function is not completed. This mail is just for some comments.
Please tell me if I am wrong.

Thanks. :)


Signed-off-by: Tang Chen <[email protected]>
---
client/virt/libvirt_xml.py | 57 +++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 56 insertions(+), 1 deletions(-)

diff --git a/client/virt/libvirt_xml.py b/client/virt/libvirt_xml.py
index cb577c6..02781ca 100644
--- a/client/virt/libvirt_xml.py
+++ b/client/virt/libvirt_xml.py
@@ -12,4 +12,59 @@ class LibvirtXMLVMNameError(LibvirtXMLError):


 class LibvirtXML(xml_utils.XMLTreeFile):
-    pass
+    """
+    A class representing a vm's xml file.
+    """
+
+    # vm's name
+    vmname = None
+
+    def __init__(self, xml):
+        """
+        Initialize an object representing a vm's xml configuration.
+        It can be initialized from a xml file or a string retuened
+        by virsh dumpxml.
+        And also, it attracts the vm's name from the xml.
+
+        param: xml: A filename or string containing XML
+        """
+
+        super(LibvirtXML, self).__init__(xml)
+        self.vmname = self.findtext("name")
+
+
+    def check_interface(self, type=None, mac=None,
+                        source=None, model=None):
+        """
+        Check if vm has a coincident interface
+        """
+        type_real = None
+        mac_real = None
+        model_real = None
+        source_real = None
+
+        interface = self.find("devices/interface")
+        if interface != None:
+            type_real = interface.attrib.get("type")
+
+        mac_attr = self.find("devices/interface/mac")
+        if mac_attr != None:
+            mac_real = mac_attr.attrib.get("address")
+
+        source_attr = self.find("devices/interface/source")
+        if source_attr != None:
+            source_real = source_attr.attrib.get(type_real)
+
+        model_attr = self.find("devices/interface/model")
+        if model_attr != None:
+            model_real = model_attr.attrib.get("type")
+
+        logging.debug("type: %s" % type_real)
+        logging.debug("mac: %s" % mac_real)
+        logging.debug("source: %s" % source_real)
+        logging.debug("model: %s" % model_real)
+
+        if type_real != type or mac_real != mac or \
+            source_real != source or model_real != model:
+            return False
+        return True
--
1.7.1


_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel

Reply via email to