11 CONFIG_FILE="/tmp/source/configuration"
12 SESSION_FILE="/etc/planetlab/session"
14 def read_config_file(filename):
15 ## NOTE: text copied from BootManager.py
16 # TODO: unify this code to make it common. i.e. use ConfigParser module
18 vars_file= file(filename,'r')
20 for line in vars_file:
21 # if its a comment or a whitespace line, ignore
22 if line[:1] == "#" or string.strip(line) == "":
25 parts= string.split(line,"=")
27 print "Invalid line in vars file: %s" % line
31 name= string.strip(parts[0])
32 value= string.strip(parts[1])
37 print "Unable to read configuration vars."
42 sys.path = ['/etc/planetlab'] + sys.path
44 api_server_url = "https://" + plc_config.PLC_API_HOST + plc_config.PLC_API_PATH
47 vars = read_config_file(filename)
48 api_server_url = vars['BOOT_API_SERVER']
52 def __init__(self, username=None, password=None, **kwargs):
53 if 'session' in kwargs:
54 self.auth= { 'AuthMethod' : 'session',
55 'session' : kwargs['session'] }
57 if username==None and password==None:
58 self.auth = {'AuthMethod': "anonymous"}
60 self.auth = {'Username' : username,
61 'AuthMethod' : 'password',
62 'AuthString' : password}
64 def __init__(self, auth, url):
67 self.api = xmlrpclib.Server(self.url, verbose=False, allow_none=True)
69 def __getattr__(self, name):
70 method = getattr(self.api, name)
72 raise AssertionError("method does not exist")
74 return lambda *params : method(self.auth.auth, *params)
77 return self.api.__repr__()
81 f=open(SESSION_FILE,'r')
82 session_str=f.read().strip()
83 api = PLC(Auth(session=session_str), api_server_url)
84 # NOTE: should we rely on bootmanager for this functionality?
96 # TODO: remove from output
97 print "reporting status: ", os.popen("uptime").read().strip()
99 # NOTE: alternately, check other stuff in the environment to infer
101 # is BootManager running?
102 # what is the boot_state at PLC?
103 # does /vservers exist?
104 # what about /tmp/source?
105 # is BootManager in /tmp/source?
106 # is /tmp/mnt/sysimg mounted?
107 # how long have we been running? if we were in safeboot and
108 # still running, we're likely in failboot now.
109 # length of runtime increases the certainty of inferred state.
111 if env == "bootmanager":
112 # if bm not running, and plc bootstate = boot, then
113 #api.ReportRunlevel({'run_level' : 'failboot'})
114 #api.ReportRunlevel({'run_level' : 'reinstall'})
115 # if bm not running, and plc bootstate = safeboot, then
116 api.ReportRunlevel({'run_level' : 'safeboot'})
117 elif env == "production":
118 api.ReportRunlevel({'run_level' : 'boot'})
120 api.ReportRunlevel({'run_level' : 'failboot'})
123 traceback.print_exc()
125 # TODO: change to a configurable value
129 if __name__ == "__main__":