Exemplo n.º 1
0
Arquivo: qm.py Projeto: m3z/ToMaTo
def checkImage(host, path):
	assert host
	assert fileutil.existsFile(host, path)
	try:
		res = host.execute("qemu-img info -f qcow2 %s" % util.escape(path))
	except exceptions.CommandError, err:
		return err.errorMessage
Exemplo n.º 2
0
def useImage(host, vmid, image, move=False):
	assert fileutil.existsFile(host, image), "Image file does not exist"
	try:
		host.execute("qemu-img check -f qcow2 %s; echo $?" % util.escape(image))
	except exceptions.CommandError, exc:
		#Error 1: Leaked clusters, "This means waste of disk space, but no harm to data."
		if not exc.errorCode in [1]:
			raise  
Exemplo n.º 3
0
	def uploadToHost(self, host):
		if not self.isEnabled():
			return
		if host.clusterState() == ClusterState.NODE:
			return
		dst = self.getPath()
		url = self.getDownloadUrl()
		if url:
			fileutil.mkdir(host, os.path.dirname(dst))
			host.execute("curl -o %(filename)s -sfSR -z %(filename)s %(url)s" % {"url": util.escape(url), "filename": util.escape(dst)})
Exemplo n.º 4
0
def _qm(host, vmid, cmd, params=[], maxWait=30, unlock=True):
	waitStep = 1
	while True:
		try:
			return host.execute("qm %s %d %s" % (util.escape(cmd), vmid, " ".join(map(util.escape, params))))
		except exceptions.CommandError, exc:
			if not (exc.errorCode == 4 and "lock" in exc.errorMessage and "timeout" in exc.errorMessage):
				raise
			if maxWait > 0:
				time.sleep(waitStep)
				#print "wait %s" % waitStep
				waitStep *= 2
				maxWait -= waitStep
			else:
				if not unlock:
					raise
				unlock = False
				#print "unlock"
				fileutil.delete(host, "/var/lock/qemu-server/lock-%d.conf" % vmid)
Exemplo n.º 5
0
def _monitor(host, vmid, cmd, timeout=60):
	assert getState(host, vmid) == generic.State.STARTED, "VM must be running to access monitor"
	return host.execute("echo -e %(cmd)s'\n' | socat - unix-connect:/var/run/qemu-server/%(vmid)d.mon; timeout %(timeout)d socat -u unix-connect:/var/run/qemu-server/%(vmid)d.mon - 2>&1 | dd count=0 2>/dev/null; echo" % {"cmd": util.escape(cmd), "vmid": vmid, "timeout": timeout})
Exemplo n.º 6
0
def startVnc(host, vmid, port, password):
	assert getState(host, vmid) == generic.State.STARTED, "VM must be running to start vnc"
	assert process.portFree(host, port)
	host.execute("tcpserver -qHRl 0 0 %d qm vncproxy %d %s & echo $! > %s" % ( port, vmid, util.escape(password), _vncPidfile(vmid) ))
	assert not process.portFree(host, port)
Exemplo n.º 7
0
Arquivo: qm.py Projeto: m3z/ToMaTo
def _qm(host, vmid, cmd, params=[]):
	return host.execute("qm %s %d %s" % (util.escape(cmd), vmid, " ".join(map(util.escape, params))))