X-Git-Url: http://git.onelab.eu/?p=sface.git;a=blobdiff_plain;f=sface%2Fsfirenew.py;fp=sface%2Fsfirenew.py;h=863b253a799bd17aabacc5169de1411f212f71ee;hp=0000000000000000000000000000000000000000;hb=a30b55dc5d556c92155aada00a46c91450887f71;hpb=95e0d8d2ac7bc562d011faba71d8c0276cd31264 diff --git a/sface/sfirenew.py b/sface/sfirenew.py new file mode 100644 index 0000000..863b253 --- /dev/null +++ b/sface/sfirenew.py @@ -0,0 +1,65 @@ +import calendar +import datetime +import os +import re +import sys +import time + +from PyQt4.QtCore import * +from sface.config import config +from sface.sfiprocess import SfiProcess + +class SfiRenewer(QObject): + def __init__(self, hrn, newExpiration, parent=None): + QObject.__init__(self, parent) + self.hrn = hrn + self.newExpiration = newExpiration + + self.renewProcess = SfiProcess(self) + self.connect(self.renewProcess, SIGNAL('finished()'), self.finishedGetRecord) + self.renewProcess.getRecord(hrn=config.getSlice(), filename="/tmp/slicerecord") + + def finishedGetRecord(self): + f = open("/tmp/slicerecord", "r") + data = f.read() + f.close() + + # find the expiration time + exp = re.compile('expires="[^"]*"') + if exp.search(data)==None: + # didn't find it + self.emitFinished("failure", "failed to find expiration in slice record") + return + + # change the expiration time + delta = 24*60*60 # always extend the slice by one extra day to cover slop for time zone differences + data = exp.sub('expires="' + str(calendar.timegm(self.newExpiration.timetuple())+delta) + '"', data) + + open("/tmp/slicerecord", "w").write(data) + + self.disconnect(self.renewProcess, SIGNAL('finished()'), self.finishedGetRecord) + self.connect(self.renewProcess, SIGNAL('finished()'), self.finishedUpdateRecord) + + self.renewProcess.updateRecord("/tmp/slicerecord") + + def finishedUpdateRecord(self): + # we have to force sfi.py to download an updated slice credential + sliceCredName = os.path.expanduser("~/.sfi/slice_" + self.hrn.split(".")[-1] + ".cred") + if os.path.exists(sliceCredName): + os.remove(sliceCredName) + + open("/tmp/expiration", "w").write(self.newExpiration.strftime("%Y-%m-%dT%H:%M:%SZ")) + + # call renewSlivers on the aggregate + self.disconnect(self.renewProcess, SIGNAL('finished()'), self.finishedUpdateRecord) + self.connect(self.renewProcess, SIGNAL('finished()'), self.finishedRenewSlivers) + self.renewProcess.renewSlivers(self.newExpiration.strftime("%Y-%m-%dT%H:%M:%SZ")) + + def finishedRenewSlivers(self): + self.emitFinished("success") + + def emitFinished(self, status, statusMsg=None): + self.status = status + self.statusMsg = statusMsg + self.emit(SIGNAL("finished()")) +