def _run(self): self.started = time.time() while True: task = self._getReadyTask() if task: assert task.status == Status.WAITING task.status = Status.RUNNING task.run() if task.status == Status.SUCCEEDED: self._taskDone(task) else: self.abort() self.finished = time.time() self._runOnFinished() if isinstance(task.result, Exception): raise fault.new("Task failed: %s" % task.result, code=fault.USER_ERROR) else: return else: if not self.isActive(): if not self.finished: self.finished = time.time() self._runOnFinished() return else: time.sleep(1)
def _runAction(self, action, attrs, direct): if action == "execute": fault.check("cmd" in attrs, "Command not given") try: return self.execute(attrs["cmd"]) except exceptions.CommandError, exc: raise fault.new(str(exc), fault.USER_ERROR)
def interfacesRename(self, name, properties): #@UnusedVariable, pylint: disable-msg=W0613 fault.check(self.state != State.STARTED, "Changes of running KVMs are not supported") iface = self.interfaceSetGet(name) newName = properties["name"] fault.check(re.match("eth(\d+)", newName), "Invalid interface name: %s" % name) try: if self.interfaceSetGet(newName): raise fault.new("Duplicate interface name: %s" % newName, fault.USER_ERROR) except Interface.DoesNotExist: #pylint: disable-msg=W0702 pass if self.state == State.PREPARED: connector = None connectionAttributes = None if iface.isConnected(): connector = iface.connection.connector connectionAttributes = iface.connection.upcast().toDict(None)["attrs"] connector.upcast().connectionsDelete(unicode(iface)) qm.deleteInterface(self.host, self.getVmid(), iface.name) iface.name = newName iface.save() if self.state == State.PREPARED: qm.addInterface(self.host, self.getVmid(), iface.name) if connector: connector.upcast().connectionsAdd(unicode(iface), connectionAttributes) self.save()
def downloadCaptureUri(host, name, onlyLatest=False): filename = "%s.pcap" % name path = host.getHostServer().randomFilename() if onlyLatest: print path latest = util.lines(host.execute("ls -t1 %s | head -n1" % _remoteDir(name)))[0] if latest: fileutil.copy(host, "%s/%s" % (_remoteDir(name), latest), path) else: host.execute("tcpslice -w %s %s/*" % (path, _remoteDir(name))) if not fileutil.existsFile(host, path) or not fileutil.fileSize(host, path): raise fault.new("No packages captured yet") return host.getHostServer().downloadGrant(path, filename=filename)
def interfacesAdd(self, name, properties): #@UnusedVariable, pylint: disable-msg=W0613 fault.check(self.state != State.STARTED, "Changes of running KVMs are not supported") fault.check(re.match("eth(\d+)", name), "Invalid interface name: %s" % name) iface = Interface() try: if self.interfaceSetGet(name): raise fault.new("Duplicate interface name: %s" % name) except Interface.DoesNotExist: #pylint: disable-msg=W0702 pass iface.name = name iface.device = self iface.init() if self.state == State.PREPARED: qm.addInterface(self.host, self.getVmid(), iface.name) iface.save() Device.interfaceSetAdd(self, iface)
def getStatus(task_id, details=False): try: return processes[task_id].dict(details) except KeyError: raise fault.new("No such task %s" % task_id, fault.USER_ERROR)
def checkUploadedImage(self, path): error = repy.check(self.host, path) if error: raise fault.new("Invalid/Unsafe code: %s, %s" % error, fault.USER_ERROR)
def checkUploadedImage(self, path): error = vzctl.checkImage(self.host, path) if error: raise fault.new("Invalid OpenVZ image: %s" % error, fault.USER_ERROR)
def ownerTuple(obj): for n, t in _ownerTypeMap().iteritems(): if isinstance(obj, t): return (n, obj.id) raise fault.new("Invalid resource owner type: %s" % obj)