5 from sfa.util.rspecHelper import RSpec
8 defaults = { 'SFI_AUTH' : None,
11 'SFI_REGISTRY' : "http://www.planet-lab.org:12345",
12 'SFI_SM' : "http://www.planet-lab.org:12346",
13 'SFAUI_VERBOSE' : False,
17 filename = os.path.expanduser("~/.sfi/sfi_config")
18 execfile(filename, SfaData.__dict__)
19 for (k,v) in SfaData.defaults.items():
20 if not hasattr(SfaData,k): setattr(SfaData,k,v)
21 if SfaData.SFAUI_VERBOSE:
22 print "After reading config from %s"%filename
23 for (k,v) in SfaData.defaults.items():
24 print "%-20s: %r"%(k,getattr(SfaData,k))
26 def getAuthority(self):
27 return SfaData.SFI_AUTH
30 return SfaData.SFI_USER
32 def setUser(self, user):
33 SfaData.SFI_USER = user
35 # Should probably get authority from user record instead...
37 SfaData.SFI_AUTH = '.'.join(a[:len(a)-1])
40 return SfaData.SFI_SLICE
42 def setSlice(self, slice):
43 SfaData.SFI_SLICE = slice
46 return SfaData.SFI_REGISTRY
51 def trace_command (self, command):
52 self._trace=time.time()
53 if self.SFAUI_VERBOSE:
54 print time.strftime('%M:%S'),'Invoking',' '.join(command)
56 if self.SFAUI_VERBOSE:
57 print time.strftime('%M:%S'),"[%.3f s]"%(time.time()-self._trace),'Done'
59 def getRecord(self, hrn):
60 command = ["sfi.py", "-u", self.getUser(), "-a", self.getAuthority(),
61 "-r", self.registry(), "-s", self.slicemgr(), "show", hrn]
62 self.trace_command(command)
63 text = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0]
67 def listChildren(self, hrn):
69 command=["sfi.py", "-u", self.getUser(), "-a", self.getAuthority(),
70 "-r", self.registry(), "-s", self.slicemgr(), "list", hrn]
71 self.trace_command(command)
72 text = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0]
74 lines = text.split('\n')
77 (hrn, kind) = line.split()
78 children.append((hrn, kind))
83 slice = self.getSlice()
84 # Write RSpec to file for testing.
85 filename = os.path.expanduser("~/.sfi/" + slice + ".rspec")
90 command=["sfi.py", "-u", self.getUser(), "-a", self.getAuthority(),
91 "-r", self.registry(), "-s", self.slicemgr(), "resources",
92 "-o", filename, slice]
93 self.trace_command(command)
94 subprocess.call(command)
96 f = open(filename, "r")
101 def applyRSpec(self, xml):
102 slice = self.getSlice()
103 filename = os.path.expanduser("~/.sfi/" + slice + ".rspec")
104 f = open(filename, "w")
107 command=["sfi.py", "-u", self.getUser(), "-a", self.getAuthority(),
108 "-r", self.registry(), "-s", self.slicemgr(), "create", slice, filename]
109 self.trace_command(command)
110 subprocess.call(command)
113 class PlanetLabData(SfaData):
115 SfaData.__init__(self)
118 def refreshRSpec(self):
119 xml = SfaData.getRSpec(self)
120 self.rspec = RSpec(xml)
123 if self.rspec is None:
127 def applyRSpec(self):
128 xml = self.rspec.toxml()
129 SfaData.applyRSpec(self, xml)
131 class PLEData(PlanetLabData):
133 PlanetLabData.__init__(self)
134 self.SFI_SM = "http://www.planet-lab.eu:12346"
136 class PLJData(PlanetLabData):
138 PlanetLabData.__init__(self)
139 self.SFI_SM = "http://www.planet-lab.jp:12346"
141 class ViniData(PlanetLabData):
143 PlanetLabData.__init__(self)
144 self.SFI_SM = "http://www.vini-veritas.net:12346"
146 class GpENIData(PlanetLabData):
148 PlanetLabData.__init__(self)
149 self.SFI_SM = "http://198.248.241.100:12346"
151 class OpenCirrusData(SfaData):
153 SfaData.__init__(self)
154 self.SFI_REGISTRY = "http://198.55.37.29:12345"
155 self.SFI_SM = "http://198.55.37.29:12346"
157 def refreshRSpec(self):
158 xml = SfaData.getRSpec(self)
162 if self.rspec is None:
166 def applyRSpec(self):
168 SfaData.applyRSpec(self, xml)