X-Git-Url: http://git.onelab.eu/?p=sface.git;a=blobdiff_plain;f=sface%2Fsfiprocess.py;h=00f9df374e1e5c4d3c150d3b28dca48a83a494d6;hp=872fa5a2f02a279ba42d2a933d588f31db7b7d8a;hb=44743e4122a7a015518988f8b5ef07aca9a5f01e;hpb=8acaa8580500e0041b6f4ad9bc9d42eca5f99f97 diff --git a/sface/sfiprocess.py b/sface/sfiprocess.py index 872fa5a..00f9df3 100644 --- a/sface/sfiprocess.py +++ b/sface/sfiprocess.py @@ -1,6 +1,9 @@ import os +import json +import pickle import sys +import tempfile import time from PyQt4.QtCore import * @@ -12,7 +15,7 @@ def find_executable(exec_name): paths = os.getenv("PATH").split(':') for p in paths: exec_path = os.path.join(p, exec_name) - if os.path.exists(exec_path): + if os.path.exists(exec_path) and os.access(exec_path,os.X_OK): return exec_path return None @@ -34,6 +37,8 @@ class SfiProcess(QObject): # tracker. self.output = "" + self.do_raw = True # xxx should check version of sfa + self.connect(self.process, SIGNAL("readyReadStandardOutput()"), self.processStandardOutput) self.connect(self.process, SIGNAL("readyReadStandardError()"), @@ -49,6 +54,15 @@ class SfiProcess(QObject): # then to the users. self.args << QString('-D') + if self.do_raw: + self.raw_filename = tempfile.mktemp(suffix=".raw") + self.args << QString('-R') + self.args << QString(self.raw_filename) + self.args << QString('--rawformat') + self.args << QString('json') + else: + self.raw_filename = None + for arg in args: self.args << QString(arg) @@ -63,7 +77,15 @@ class SfiProcess(QObject): output = self.process.readAllStandardOutput() self.output = self.output + output if config.debug: - print output + try: + print output + except IOError, e: + if (e.errno == 4): + # XXX why is this happening?? + print "*** caught EINTR" + else: + raise + def processStandardError(self): print self.process.readAllStandardError() @@ -86,6 +108,22 @@ class SfiProcess(QObject): elif err == QProcess.UnknownError: print "UnknownError" + self.raw_data = None + if (self.raw_filename != None) and os.path.exists(self.raw_filename): + if hasattr(json, "loads"): + self.raw_data = json.loads(open(self.raw_filename,"r").read()) + else: + self.raw_data = json.read(open(self.raw_filename,"r").read()) + + os.remove(self.raw_filename) + + self.geni_code=None + self.geni_output=None + if (self.raw_data!=None) and (type(self.raw_data)==dict): + code = self.raw_data.get("code",{}) + self.geni_code = code.get("geni_code",None) + self.geni_output = self.raw_data.get("output","") + # extract any faults from the XMLRPC response(s) self.xmlrpcreader.responses = [] self.xmlrpcreader.store(self.output) @@ -93,6 +131,16 @@ class SfiProcess(QObject): self.responses = self.xmlrpcreader.responses self.faults = [x for x in self.responses if (x["kind"]=="fault")] + # if we got a nonzero + if (self.geni_code!=None) and (self.geni_code!=0): + x = {"kind": "bad_geni_code"} + x["faultCode"] = str(self.geni_code) + faultString = "Nonzero geni_code: " + str(self.geni_code) + if self.geni_output: + faultString = faultString + " output: " + str(self.geni_output) + x["faultString"] = faultString + self.faults.append(x) + self.trace_end() self.emit(SIGNAL("finished()")) @@ -174,7 +222,7 @@ class SfiProcess(QObject): def getAuthorityRecord(self): self.getRecord(config.getAuthority(), config.getAuthorityRecordFile()) - def applyRSpec(self, rspec): + def applyRSpec(self, rspec, aggAddr=None, aggPort=None, saveObtained=True): # that's what we pass, like in what we'd like to get requested = config.getSliceRSpecFile() + "_new" # that's what we actually receive @@ -182,9 +230,31 @@ class SfiProcess(QObject): obtained = config.getSliceRSpecFile() rspec.save(requested) args = ["-u", config.getUser(), "-a", config.getAuthority(), - "-r", config.getRegistry(), "-s", config.getSlicemgr(), "create", - "-o", obtained, - config.getSlice(), requested] + "-r", config.getRegistry(), "-s", config.getSlicemgr(), "create"] + + if saveObtained: + args = args + ["-o", obtained] + + if aggAddr: + args = args + ["-a", aggAddr, "-p", str(aggPort)] + + args = args + [config.getSlice(), requested] + + self.__init_command(args) + self.start() + + def deleteSlivers(self, slice=None, aggAddr=None, aggPort=None): + if not slice: + slice = config.getSlice() + + args = ["-u", config.getUser(), "-a", config.getAuthority(), + "-r", config.getRegistry(), "-s", config.getSlicemgr(), "delete"] + + if aggAddr: + args = args + ["-a", aggAddr, "-p", str(aggPort)] + + args = args + [slice] + self.__init_command(args) self.start() @@ -216,6 +286,29 @@ class SfiProcess(QObject): self.__init_command(args) self.start() + def sliverStatus(self, slice=None, filename=None): + if not slice: + slice = config.getSlice() + + if not filename: + filename = config.fullpath(slice+".sliverstatus") + + args = ["-u", config.getUser(), "-a", config.getAuthority(), + "-r", config.getRegistry(), "-s", config.getSlicemgr(), "status", + "-o", filename, "-F", "pickled", slice] + self.__init_command(args) + self.start() + + def getSliceMgrVersion(self, filename=None): + if not filename: + filename = config.fullpath("slicemgr.version") + + args = ["-u", config.getUser(), "-a", config.getAuthority(), + "-r", config.getRegistry(), "-s", config.getSlicemgr(), "version", + "-o", filename, "-F", "pickled",] + self.__init_command(args) + self.start() + def start(self): self.respones = [] self.faults = []