Exemple #1
0
    def createSnapshot(self, domain=None, xmlDesc=None):
        retval = False

        if domain is not None:
            parent_snapshot_name = self.getCurrentSnapshotName(domain)

            if xmlDesc is None:
                xml = "<domainsnapshot/>"

            else: # validate xml file
                try:
                    doc = XMLParse(xmlDesc)
                    name = XMLXpath(doc, '/domainsnapshot/name/text()')
                    if name is not None:
                        xml = xmlDesc
                except:
                    pass
            try:
                xml
                guest = self.kvc.search_guests(domain)[0]
                snapshot = libvirtmod.virDomainSnapshotCreateXML(guest._o,xml,0)
                if snapshot is not False:
                    retval = libvirtmod.virDomainSnapshotGetXMLDesc(snapshot, 0)
            except:
                pass

        if retval is not False:
            kvg_guest = self.kvc.search_kvg_guests(domain)[0]
            id = self.getCurrentSnapshotName(domain)
            kvg_guest.set_current_snapshot(id)

            # ここにsnapshotのxmlファイルに親のsnapshotの情報を書き込む処理
            try:
                xml_path = self.getSnapshotXMLPath(id)

                # <parent/>が設定されてない場合
                # かつ、snapshot実行前に<currentSnapshot/>が設定されていた場合
                if self.getParentName(id) is None and parent_snapshot_name is not None:
                    if os.path.exists(xml_path):
                        doc = XMLParse(xml_path)
                        parent = doc.createElement("parent")
                        name   = doc.createElement("name")
                        txt = doc.createTextNode(str(parent_snapshot_name))
                        name.appendChild(txt)
                        parent.appendChild(name)
                        doc.childNodes[0].appendChild(parent)
                        xmlDesc = self.generateXML(doc)

                        ConfigFile(xml_path).write(xmlDesc)

                if os.path.exists(xml_path):
                    if os.getuid() == 0:
                        r_chgrp(xml_path,KARESANSUI_GROUP)
                        r_chmod(xml_path,"g+rw")
                        r_chmod(xml_path,"o-rwx")
            except:
                pass

        return retval
Exemple #2
0
    def getCurrentSnapshotXMLDesc(self,domain=None):
        retval = False

        if domain is not None:
            has_current = self.hasCurrentSnapshot(domain)
            if has_current is True:
                guest = self.kvc.search_guests(domain)[0]
                snapshot = libvirtmod.virDomainSnapshotCurrent(guest._o,0)
                if snapshot is not False:
                    retval = libvirtmod.virDomainSnapshotGetXMLDesc(snapshot, 0)

        return retval
Exemple #3
0
    def getCurrentSnapshotXMLDesc(self, domain=None):
        retval = False

        if domain is not None:
            has_current = self.hasCurrentSnapshot(domain)
            if has_current is True:
                guest = self.kvc.search_guests(domain)[0]
                snapshot = libvirtmod.virDomainSnapshotCurrent(guest._o, 0)
                if snapshot is not False:
                    retval = libvirtmod.virDomainSnapshotGetXMLDesc(
                        snapshot, 0)

        return retval
Exemple #4
0
    def getXMLDesc(self, name, domain=None, flag=True):
        retval = None

        snapshot = self.lookupByName(name, domain=domain)
        if snapshot is not False:

            if flag is True:
                xml_path = self.getSnapshotXMLPath(name, domain=domain)
                if os.path.exists(xml_path):
                    retval = open(xml_path).read()

            if retval is None:
                retval = libvirtmod.virDomainSnapshotGetXMLDesc(snapshot, 0)
                if retval is False:
                    retval = None

        return retval
Exemple #5
0
    def getXMLDesc(self,name,domain=None,flag=True):
        retval = None

        snapshot = self.lookupByName(name,domain=domain)
        if snapshot is not False:

            if flag is True:
                xml_path = self.getSnapshotXMLPath(name,domain=domain)
                if os.path.exists(xml_path):
                    retval = open(xml_path).read()

            if retval is None:
                retval = libvirtmod.virDomainSnapshotGetXMLDesc(snapshot, 0)
                if retval is False:
                    retval = None

        return retval
Exemple #6
0
    def createSnapshot(self, domain=None, xmlDesc=None):
        retval = False

        if domain is not None:
            parent_snapshot_name = self.getCurrentSnapshotName(domain)

            if xmlDesc is None:
                xml = "<domainsnapshot/>"

            else:  # validate xml file
                try:
                    doc = XMLParse(xmlDesc)
                    name = XMLXpath(doc, '/domainsnapshot/name/text()')
                    if name is not None:
                        xml = xmlDesc
                except:
                    pass
            try:
                xml
                guest = self.kvc.search_guests(domain)[0]
                snapshot = libvirtmod.virDomainSnapshotCreateXML(
                    guest._o, xml, 0)
                if snapshot is not False:
                    retval = libvirtmod.virDomainSnapshotGetXMLDesc(
                        snapshot, 0)
            except:
                pass

        if retval is not False:
            kvg_guest = self.kvc.search_kvg_guests(domain)[0]
            id = self.getCurrentSnapshotName(domain)
            kvg_guest.set_current_snapshot(id)

            # ここにsnapshotのxmlファイルに親のsnapshotの情報を書き込む処理
            try:
                xml_path = self.getSnapshotXMLPath(id)

                # <parent/>が設定されてない場合
                # かつ、snapshot実行前に<currentSnapshot/>が設定されていた場合
                if self.getParentName(
                        id) is None and parent_snapshot_name is not None:
                    if os.path.exists(xml_path):
                        doc = XMLParse(xml_path)
                        parent = doc.createElement("parent")
                        name = doc.createElement("name")
                        txt = doc.createTextNode(str(parent_snapshot_name))
                        name.appendChild(txt)
                        parent.appendChild(name)
                        doc.childNodes[0].appendChild(parent)
                        xmlDesc = self.generateXML(doc)

                        ConfigFile(xml_path).write(xmlDesc)

                if os.path.exists(xml_path):
                    if os.getuid() == 0:
                        r_chgrp(xml_path, KARESANSUI_GROUP)
                        r_chmod(xml_path, "g+rw")
                        r_chmod(xml_path, "o-rwx")
            except:
                pass

        return retval