X-Git-Url: http://git.onelab.eu/?p=sfa-gui.git;a=blobdiff_plain;f=SfaData.py;h=aea1ba497924d41d0946859a4472396d9289e0fe;hp=953179c047c8b58bcc1949cd6e4da54b8462d419;hb=refs%2Fheads%2Fmarcoy-dev;hpb=1d432dd802ffdf4fd7960bf105e8e06251f402c5 diff --git a/SfaData.py b/SfaData.py index 953179c..aea1ba4 100644 --- a/SfaData.py +++ b/SfaData.py @@ -1,20 +1,29 @@ import os import re -from subprocess import * +import time +import subprocess from sfa.util.rspecHelper import RSpec class SfaData: + defaults = { 'SFI_AUTH' : None, + 'SFI_USER' : None, + 'SFI_SLICE' : None, + 'SFI_REGISTRY' : "http://www.planet-lab.org:12345", + 'SFI_SM' : "http://www.planet-lab.org:12346", + 'SFAUI_VERBOSE' : False, + } + def __init__(self): - self.registry = None - self.slicemgr = None - filename = os.path.expanduser("~/.sfi/sfi_config") - execfile(filename, SfaData.__dict__) - if not hasattr(SfaData, 'SFI_AUTH'): - SfaData.SFI_AUTH = None - if not hasattr(SfaData, 'SFI_USER'): - SfaData.SFI_USER = None - if not hasattr(SfaData, 'SFI_SLICE'): - SfaData.SFI_SLICE = None + self.filename = os.path.expanduser("~/.sfi/sfi_config") + execfile(self.filename, SfaData.__dict__) + for (k,v) in SfaData.defaults.items(): + if not hasattr(SfaData,k): setattr(SfaData,k,v) + + def show(self,classname): + if SfaData.SFAUI_VERBOSE: + print "instance of %s after reading config from %s"%(classname,self.filename) + for (k,v) in SfaData.defaults.items(): + print "%-20s: %r"%(k,getattr(SfaData,k)) def getAuthority(self): return SfaData.SFI_AUTH @@ -35,25 +44,41 @@ class SfaData: def setSlice(self, slice): SfaData.SFI_SLICE = slice + def registry(self): + return SfaData.SFI_REGISTRY + + def slicemgr(self): + return SfaData.SFI_SM + + def trace_command (self, command): + self._trace=time.time() + if self.SFAUI_VERBOSE: + print time.strftime('%M:%S'),'Invoking',' '.join(command) + def trace_end (self): + if self.SFAUI_VERBOSE: + print time.strftime('%M:%S'),"[%.3f s]"%(time.time()-self._trace),'Done' + def getRecord(self, hrn): - text = Popen(["sfi.py", "-u", self.getUser(), "-a", - self.getAuthority(), "-r", self.registry, - "-s", self.slicemgr, "show", hrn], - stdout=PIPE).communicate()[0] + command = ["sfi.py", "-u", self.getUser(), "-a", self.getAuthority(), + "-r", self.registry(), "-s", self.slicemgr(), "show", hrn] + self.trace_command(command) + text = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0] + self.trace_end() return text def listChildren(self, hrn): children = [] - text = Popen(["sfi.py", "-u", self.getUser(), "-a", - self.getAuthority(), "-r", self.registry, - "-s", self.slicemgr, "list", hrn], - stdout=PIPE).communicate()[0] + command=["sfi.py", "-u", self.getUser(), "-a", self.getAuthority(), + "-r", self.registry(), "-s", self.slicemgr(), "list", hrn] + self.trace_command(command) + text = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0] + self.trace_end() lines = text.split('\n') for line in lines: if line: (hrn, kind) = line.split() children.append((hrn, kind)) - + return children def getRSpec(self): @@ -64,9 +89,12 @@ class SfaData: os.remove(filename) except: pass - call(["sfi.py", "-u", self.getUser(), "-a", self.getAuthority(), - "-r", self.registry, "-s", self.slicemgr, "resources", - "-o", slice, slice]) + command=["sfi.py", "-u", self.getUser(), "-a", self.getAuthority(), + "-r", self.registry(), "-s", self.slicemgr(), "resources", + "-o", filename, slice] + self.trace_command(command) + subprocess.call(command) + self.trace_end() f = open(filename, "r") xml = f.read() f.close() @@ -78,15 +106,15 @@ class SfaData: f = open(filename, "w") f.write(xml) f.close() - call(["sfi.py", "-u", self.getUser(), "-a", self.getAuthority(), - "-r", self.registry, "-s", self.slicemgr, "create", - slice, filename]) + command=["sfi.py", "-u", self.getUser(), "-a", self.getAuthority(), + "-r", self.registry(), "-s", self.slicemgr(), "create", slice, filename] + self.trace_command(command) + subprocess.call(command) + self.trace_end() class PlanetLabData(SfaData): def __init__(self): SfaData.__init__(self) - self.registry = "http://www.planet-lab.org:12345" - self.slicemgr = "http://www.planet-lab.org:12346" self.rspec = None def refreshRSpec(self): @@ -105,28 +133,34 @@ class PlanetLabData(SfaData): class PLEData(PlanetLabData): def __init__(self): PlanetLabData.__init__(self) - self.slicemgr = "http://www.planet-lab.eu:12346" + SfaData.SFI_REGISTRY = "http://www.planet-lab.eu:12345" + SfaData.SFI_SM = "http://www.planet-lab.eu:12346" + self.show("PlanetLabData") class PLJData(PlanetLabData): def __init__(self): PlanetLabData.__init__(self) - self.slicemgr = "http://www.planet-lab.jp:12346" + SfaData.SFI_SM = "http://www.planet-lab.jp:12346" + self.show("PLJData") class ViniData(PlanetLabData): def __init__(self): PlanetLabData.__init__(self) - self.slicemgr = "http://www.vini-veritas.net:12346" + SfaData.SFI_SM = "http://www.vini-veritas.net:12346" + self.show("ViniData") class GpENIData(PlanetLabData): def __init__(self): PlanetLabData.__init__(self) - self.slicemgr = "http://198.248.241.100:12346" + SfaData.SFI_SM = "http://198.248.241.100:12346" + self.show("GpENIData") class OpenCirrusData(SfaData): def __init__(self): SfaData.__init__(self) - self.registry = "http://198.55.37.29:12345" - self.slicemgr = "http://198.55.37.29:12346" + self.SFI_REGISTRY = "http://198.55.37.29:12345" + SfaData.SFI_SM = "http://198.55.37.29:12346" + self.show("OpenCirrusData") def refreshRSpec(self): xml = SfaData.getRSpec(self)