X-Git-Url: http://git.onelab.eu/?p=sfa-gui.git;a=blobdiff_plain;f=SfaData.py;h=b6d73317b05f0c8790caef57f67b9483168b17c0;hp=e1abfac28a0637ed852408a2a80829b922c90ff7;hb=e15ce3036c57ffce83734d8f9912acff5ce2e82a;hpb=7ce5cc20aaa8c2504abff63921268c0f6fa8a676 diff --git a/SfaData.py b/SfaData.py index e1abfac..b6d7331 100644 --- a/SfaData.py +++ b/SfaData.py @@ -1,11 +1,12 @@ import os -from subprocess import call +import re +from subprocess import * from sfa.util.rspecHelper import RSpec class SfaData: authority = "plc.princeton" user = "plc.princeton.acb" - slice = "plc.princeton.iias" + slice = "plc.princeton.sapan" def __init__(self): self.registry = None @@ -30,8 +31,26 @@ class SfaData: def setSlice(self, slice): SfaData.slice = slice - def getRecord(self): - pass + 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] + 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] + lines = text.split('\n') + for line in lines: + if line: + (hrn, kind) = line.split() + children.append((hrn, kind)) + + return children def getRSpec(self): slice = self.getSlice() @@ -44,29 +63,71 @@ class SfaData: f.close() return xml -class ViniData(SfaData): - def __init__(self): - SfaData.__init__(self) - self.registry = "http://www.planet-lab.org:12345" - self.slicemgr = "http://www.vini-veritas.net:12346" - - def getRSpec(self): - xml = SfaData.getRSpec(self) - return RSpec(xml) + def applyRSpec(self, xml): + slice = self.getSlice() + filename = os.path.expanduser("~/.sfi/" + slice + ".rspec") + 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]) 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 getRSpec(self): + def refreshRSpec(self): xml = SfaData.getRSpec(self) - return RSpec(xml) + self.rspec = RSpec(xml) + + def getRSpec(self): + if self.rspec is None: + self.refreshRSpec() + return self.rspec + + def applyRSpec(self): + xml = self.rspec.toxml() + SfaData.applyRSpec(self, xml) + +class PLEData(PlanetLabData): + def __init__(self): + PlanetLabData.__init__(self) + self.slicemgr = "http://www.planet-lab.eu:12346" + +class PLJData(PlanetLabData): + def __init__(self): + PlanetLabData.__init__(self) + self.slicemgr = "http://www.planet-lab.jp:12346" + +class ViniData(PlanetLabData): + def __init__(self): + PlanetLabData.__init__(self) + self.slicemgr = "http://www.vini-veritas.net:12346" + +class GpENIData(PlanetLabData): + def __init__(self): + PlanetLabData.__init__(self) + self.slicemgr = "http://198.248.241.100:12346" class OpenCirrusData(SfaData): def __init__(self): SfaData.__init__(self) - self.registry = "http://www.planet-lab.org:12345" - self.slicemgr = "http://www.planet-lab.org:12346" + self.registry = "http://198.55.37.29:12345" + self.slicemgr = "http://198.55.37.29:12346" + def refreshRSpec(self): + xml = SfaData.getRSpec(self) + self.rspec = xml + + def getRSpec(self): + if self.rspec is None: + self.refreshRSpec() + return self.rspec + + def applyRSpec(self): + xml = self.rspec + SfaData.applyRSpec(self, xml)