Пример #1
0
    def backup_xml(self):
        """
        Backup the guest's xmlfile.
        """
        # Since backup_xml() is not a function for testing,
        # we have to handle the exception here.
        try:
            xml_file = tempfile.mktemp(dir="/tmp")

            virsh.dumpxml(self.name, to_file=xml_file, uri=self.connect_uri)
            return xml_file
        except Exception, detail:
            if os.path.exists(xml_file):
                os.remove(xml_file)
            logging.error("Failed to backup xml file:\n%s", detail)
            return ""
Пример #2
0
    def backup_xml(self):
        """
        Backup the guest's xmlfile.
        """
        # Since backup_xml() is not a function for testing,
        # we have to handle the exception here.
        try:
            xml_file = tempfile.mktemp(dir="/tmp")

            virsh.dumpxml(self.name, to_file=xml_file, uri=self.connect_uri)
            return xml_file
        except Exception, detail:
            if os.path.exists(xml_file):
                os.remove(xml_file)
            logging.error("Failed to backup xml file:\n%s", detail)
            return ""
Пример #3
0
    def get_virsh_mac_address(self, nic_index=0):
        """
        Get the MAC of this VM domain.

        @param nic_index: Index of the NIC
        @raise VMMACAddressMissingError: If no MAC address is defined for the
                requested NIC
        """
        thexml = virsh.dumpxml(self.name, uri=self.connect_uri)
        dom = minidom.parseString(thexml)
        count = 0
        for node in dom.getElementsByTagName('interface'):
            source = node.childNodes[1]
            x = source.attributes["address"]
            if nic_index == count:
                return x.value
            count += 1
        raise virt_vm.VMMACAddressMissingError(nic_index)
Пример #4
0
    def get_virsh_mac_address(self, nic_index=0):
        """
        Get the MAC of this VM domain.

        @param nic_index: Index of the NIC
        @raise VMMACAddressMissingError: If no MAC address is defined for the
                requested NIC
        """
        thexml = virsh.dumpxml(self.name, uri=self.connect_uri)
        xtf = xml_utils.XMLTreeFile(thexml)
        interfaces = xtf.find("devices").findall("interface")
        # Range check
        try:
            mac = interfaces[nic_index].find("mac").get("address")
            if mac is not None:
                return mac
        except IndexError:
            pass  # Allow other exceptions through
        # IndexError (range check) or mac == None
        raise virt_vm.VMMACAddressMissingError(nic_index)
Пример #5
0
 def get_xml(self):
     """
     Return VM's xml file.
     """
     return virsh.dumpxml(self.name, uri=self.connect_uri)
Пример #6
0
 def get_xml(self):
     """
     Return VM's xml file.
     """
     return virsh.dumpxml(self.name, uri=self.connect_uri)