示例#1
0
文件: Guest.py 项目: jaxxer/aivm
	def create(self):
		conn = libvirt.open(DC.get("virsh", "connect"))
		
		try:
			storagePool = conn.storagePoolLookupByName(self.pool)
			storagePool.refresh(0)
		except:
			Logging.errorExit("There is no '%s' libvirt storage pool." % self.pool)
		
		path = os.path.basename(self.path)
		size = Units(self.size).convertTo("B")
		
		diskXML = """
		<volume>
			<name>%s</name>
			<capacity>%i</capacity>
			<allocation>0</allocation>
			<target>
				<format type='raw'/>
			</target>
		</volume>
		"""
		diskXML = diskXML % (path, size)
		
		try:
			storage = storagePool.createXML(diskXML, 0)
		except Exception as e:
			Logging.errorExit("%s (name: %s)" % (str(e), path))
		
		return storage
示例#2
0
    def parseImageFile(self, guest):
        def checkTreeinfo(url):
            url = ("%s/%s" % (url, ".treeinfo")) if url[-1] != "/" else (
                "%s%s" % (url, ".treeinfo"))

            try:
                httpRequest = urllib2.urlopen(url)
                return True

            except:
                return False

        path = self.parseTextElement(guest, "image-file")

        if path and path.startswith("http://"):
            if checkTreeinfo(path):
                return Location.HttpDir(path)

            elif path.endswith(".iso"):
                return Location.HttpIso(path)

        elif path and path.endswith(".iso"):
            return Location.LocalIso(path)
        else:
            Logging.errorExit("Image file of all guests must be set.")
示例#3
0
    def create(self):
        conn = libvirt.open(DC.get("virsh", "connect"))

        try:
            storagePool = conn.storagePoolLookupByName(self.pool)
            storagePool.refresh(0)
        except:
            Logging.errorExit("There is no '%s' libvirt storage pool." %
                              self.pool)

        path = os.path.basename(self.path)
        size = Units(self.size).convertTo("B")

        diskXML = """
		<volume>
			<name>%s</name>
			<capacity>%i</capacity>
			<allocation>0</allocation>
			<target>
				<format type='raw'/>
			</target>
		</volume>
		"""
        diskXML = diskXML % (path, size)

        try:
            storage = storagePool.createXML(diskXML, 0)
        except Exception as e:
            Logging.errorExit("%s (name: %s)" % (str(e), path))

        return storage
示例#4
0
    def parseImageFile(self, guest):
        def checkTreeinfo(url):
            url = ("%s/%s" % (url, ".treeinfo")) if url[-1] != "/" else ("%s%s" % (url, ".treeinfo"))

            try:
                httpRequest = urllib2.urlopen(url)
                return True

            except:
                return False

        path = self.parseTextElement(guest, "image-file")

        if path and path.startswith("http://"):
            if checkTreeinfo(path):
                return Location.HttpDir(path)

            elif path.endswith(".iso"):
                return Location.HttpIso(path)

        elif path and path.endswith(".iso"):
            return Location.LocalIso(path)
        else:
            Logging.errorExit("Image file of all guests must be set.")