def start(): """The database dumper daemon. When it starts up, it populates the database with the last dumped database. It proceeds to handle dump requests forever.""" def run(): global dump_requested while True: db_lock.acquire() while not dump_requested: db_cond.wait() db_pickle = cPickle.dumps(db, cPickle.HIGHEST_PROTOCOL) dump_requested = False db_lock.release() try: tools.write_file(DB_FILE, lambda f: f.write(db_pickle)) logger.log_database(db) except: logger.log_exc("database.start: failed to pickle/dump") global db try: f = open(DB_FILE) try: db = cPickle.load(f) finally: f.close() except IOError: logger.log ("database: Could not load %s -- starting from a fresh database"%DB_FILE) db = Database() except: logger.log_exc("database: failed in start") db = Database() logger.log('database.start') tools.as_daemon_thread(run)
def start(): """Start two XMLRPC interfaces: one bound to localhost, the other bound to a Unix domain socket.""" logger.log('api.start') serv1 = APIServer_INET(('127.0.0.1', API_SERVER_PORT), requestHandler=APIRequestHandler, logRequests=0) tools.as_daemon_thread(serv1.serve_forever) try: os.unlink(UNIX_ADDR) except OSError, e: if e.errno != errno.ENOENT: raise
def start(): """The database dumper daemon. When it starts up, it populates the database with the last dumped database. It proceeds to handle dump requests forever.""" def run(): global dump_requested while True: db_lock.acquire() while not dump_requested: db_cond.wait() db_pickle = cPickle.dumps(db, cPickle.HIGHEST_PROTOCOL) dump_requested = False db_lock.release() try: tools.write_file(DB_FILE, lambda f: f.write(db_pickle)) logger.log_database(db) except: logger.log_exc("database.start: failed to pickle/dump") global db try: f = open(DB_FILE) try: db = cPickle.load(f) finally: f.close() except IOError: logger.log( "database: Could not load %s -- starting from a fresh database" % DB_FILE) db = Database() except: logger.log_exc("database: failed in start") db = Database() logger.log('database.start') tools.as_daemon_thread(run)
#check auth logger.log("nodemanager: Checking Auth.") while plc.check_authentication() != True: try: plc.update_session() logger.log("nodemanager: Authentication Failure. Retrying") except Exception,e: logger.log("nodemanager: Retry Failed. (%r); Waiting.."%e) time.sleep(iperiod) logger.log("nodemanager: Authentication Succeeded!") while True: # Main nodemanager Loop logger.log('nodemanager: mainloop - calling GetSlivers - period=%d random=%d'%(iperiod,irandom)) self.GetSlivers(config, plc) delay=iperiod + random.randrange(0,irandom) logger.log('nodemanager: mainloop - sleeping for %d s'%delay) time.sleep(delay) except: logger.log_exc("nodemanager: failed in run") def run(): logger.log("======================================== Entering nodemanager.py") NodeManager().run() if __name__ == '__main__': run() else: # This is for debugging purposes. Open a copy of Python and import nodemanager tools.as_daemon_thread(run)
108, '%s: Permission denied.' % caller_name) if result == None: result = 1 return result class APIServer_INET(SocketServer.ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer): allow_reuse_address = True class APIServer_UNIX(APIServer_INET): address_family = socket.AF_UNIX def start(): """Start two XMLRPC interfaces: one bound to localhost, the other bound to a Unix domain socket.""" logger.log('api.start') serv1 = APIServer_INET(('127.0.0.1', API_SERVER_PORT), requestHandler=APIRequestHandler, logRequests=0) tools.as_daemon_thread(serv1.serve_forever) try: os.unlink(UNIX_ADDR) except OSError, e: if e.errno != errno.ENOENT: raise serv2 = APIServer_UNIX(UNIX_ADDR, requestHandler=APIRequestHandler, logRequests=0) tools.as_daemon_thread(serv2.serve_forever) os.chmod(UNIX_ADDR, 0666)
while True: # Main nodemanager Loop work_beg = time.time() logger.log( 'nodemanager: mainloop - calling GetSlivers - period=%d random=%d' % (iperiod, irandom)) self.GetSlivers(config, plc) delay = iperiod + random.randrange(0, irandom) work_end = time.time() work_duration = int(work_end - work_beg) logger.log( 'nodemanager: mainloop has worked for %s s - sleeping for %d s' % (work_duration, delay)) time.sleep(delay) except: logger.log_exc("nodemanager: failed in run") def run(): logger.log( "======================================== Entering nodemanager.py") NodeManager().run() if __name__ == '__main__': run() else: # This is for debugging purposes. Open a copy of Python and import nodemanager tools.as_daemon_thread(run)
# only work on slivers or self. Sanity check. if not (target_rec and target_rec['type'].startswith('sliver.')): raise xmlrpclib.Fault(102, \ 'Invalid argument: the first argument must be a sliver name.') # only manipulate slivers who delegate you authority if caller_name in (target_name, target_rec['delegations']): try: result = method(target_rec, *args[1:]) except Exception, err: raise xmlrpclib.Fault(104, 'Error in call: %s' %err) else: raise xmlrpclib.Fault(108, '%s: Permission denied.' % caller_name) if result == None: result = 1 return result class APIServer_INET(SocketServer.ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer): allow_reuse_address = True class APIServer_UNIX(APIServer_INET): address_family = socket.AF_UNIX def start(): """Start two XMLRPC interfaces: one bound to localhost, the other bound to a Unix domain socket.""" logger.log('api.start') serv1 = APIServer_INET(('127.0.0.1', API_SERVER_PORT), requestHandler=APIRequestHandler, logRequests=0) tools.as_daemon_thread(serv1.serve_forever) try: os.unlink(UNIX_ADDR) except OSError, e: if e.errno != errno.ENOENT: raise serv2 = APIServer_UNIX(UNIX_ADDR, requestHandler=APIRequestHandler, logRequests=0) tools.as_daemon_thread(serv2.serve_forever) os.chmod(UNIX_ADDR, 0666)
def start(*args): tools.as_daemon_thread(run)