16 from config import Config
17 from plcapi import PLCAPI
21 savedargv = sys.argv[:]
23 parser = optparse.OptionParser()
24 parser.add_option('-d', '--daemon', action='store_true', dest='daemon', default=False, help='run daemonized')
25 parser.add_option('-s', '--startup', action='store_true', dest='startup', default=False, help='run all sliver startup scripts')
26 parser.add_option('-f', '--config', action='store', dest='config', default='/etc/planetlab/plc_config', help='PLC configuration file')
27 parser.add_option('-k', '--session', action='store', dest='session', default='/etc/planetlab/session', help='API session key (or file)')
28 parser.add_option('-p', '--period', action='store', dest='period', default=600, help='Polling interval (sec)')
29 (options, args) = parser.parse_args()
34 data = plc.GetSlivers()
35 for module in modules:
36 callback = getattr(module, 'GetSlivers')
41 if options.daemon: tools.daemon()
43 # Load /etc/planetlab/plc_config
44 config = Config(options.config)
47 other_pid = tools.pid_file()
49 print """There might be another instance of the node manager running as pid %d. If this is not the case, please remove the pid file %s""" % (other_pid, tools.PID_FILE)
52 print "Warning while writing PID file:", err
54 # Load and start modules
55 for module in ['proper', 'conf_files', 'sm', 'bwmon']:
57 m = __import__(module)
58 m.start(options, config)
60 except ImportError, err:
61 print "Warning while loading module %s:" % module, err
63 # Load /etc/planetlab/session
64 if os.path.exists(options.session):
65 session = file(options.session).read().strip()
67 session = options.session
69 # Initialize XML-RPC client
70 plc = PLCAPI(config.plc_api_uri, config.cacert, session, timeout=options.period/2)
73 # Set i2 ip list for nodes in I2 nodegroup.
74 try: net.GetSlivers(plc, data)
75 except: logger.log_exc()
78 except: logger.log_exc()
79 time.sleep(options.period + random.randrange(0,301))
80 except: logger.log_exc()
83 if __name__ == '__main__':
84 stacklim = 512*1024 # 0.5 MiB
85 curlim = resource.getrlimit(resource.RLIMIT_STACK)[0] # soft limit
87 resource.setrlimit(resource.RLIMIT_STACK, (stacklim, stacklim))
88 # for some reason, doesn't take effect properly without the exec()
89 python = '/usr/bin/python'
90 os.execv(python, [python] + savedargv)
93 # This is for debugging purposes. Open a copy of Python and import nm
94 tools.as_daemon_thread(run)