Beispiel #1
0
    def __init__(self, portnumber, baseworkingdir, logdir, masterhostname, masterportnumber, plugindir='plugins', cores=None, verbose=False) :
        DaemonBase.__init__(self, baseworkingdir, logdir, herzogdefaults.KINSKI_LOG_FILENAME, verbose)

        self.resource = Resource()
        self.workers = {}
        self.masterurl = "http://%s:%d" % (masterhostname, masterportnumber)
        random.seed()

        self.resource.portnumber = portnumber # <hack>
        if cores != None :
            self.resource.cpucores = cores

        plugins.init_plugins(plugindir)
        
        self.server = SimpleXMLRPCServer((self.resource.hostname, portnumber))
        
        self.server.register_function(self.list_resources,  'list_resources')
        self.server.register_function(self.fragment_prep,   'fragment_prep' )
        self.server.register_function(self.fragment_start,  'fragment_start')
        self.server.register_function(self.fragment_stop,   'fragment_stop' )
        self.server.register_function(self.fragment_list,   'fragment_list' )
        self.server.register_introspection_functions()

        self.log.debug("initialised @ http://%s:%d" % (self.resource.hostname, portnumber))
Beispiel #2
0
class Kinski(DaemonBase) :
    
    version = 0.1

    def __init__(self, portnumber, baseworkingdir, logdir, masterhostname, masterportnumber, plugindir='plugins', cores=None, verbose=False) :
        DaemonBase.__init__(self, baseworkingdir, logdir, herzogdefaults.KINSKI_LOG_FILENAME, verbose)

        self.resource = Resource()
        self.workers = {}
        self.masterurl = "http://%s:%d" % (masterhostname, masterportnumber)
        random.seed()

        self.resource.portnumber = portnumber # <hack>
        if cores != None :
            self.resource.cpucores = cores

        plugins.init_plugins(plugindir)
        
        self.server = SimpleXMLRPCServer((self.resource.hostname, portnumber))
        
        self.server.register_function(self.list_resources,  'list_resources')
        self.server.register_function(self.fragment_prep,   'fragment_prep' )
        self.server.register_function(self.fragment_start,  'fragment_start')
        self.server.register_function(self.fragment_stop,   'fragment_stop' )
        self.server.register_function(self.fragment_list,   'fragment_list' )
        self.server.register_introspection_functions()

        self.log.debug("initialised @ http://%s:%d" % (self.resource.hostname, portnumber))

    def __fragmentisrunning(self,fragmentkey) :
        return fragmentkey in self.workers

    def __startfragment(self, fragment) :
        wt = WorkerThread(fragment, self.fragment_done)
        wt.start()

        self.workers[ fragment.key() ] = wt

    def __stopfragment(self, fragmentkey) :
        f = self.workers[fragmentkey]
        f.kill()

        del self.workers[fragmentkey]

    def __listfragments(self) :
        return map(lambda x : x.gettuple(), self.workers.keys())

    @log_functioncall
    def list_resources(self) :
        self.resource.update()
        return self.resource

    @log_functioncall
    def fragment_prep(self, project) :
        chars = string.letters + string.digits + '-'

        if False in map(lambda x : x in chars, project) :
            return (False, "%s is not a suitable project name, please limit to the following characters: %s" % (project, chars))

        projectdirectory = self.workingdirectory + os.sep + project

        try :
            path = Fragment.mk_tmp_directory(projectdirectory)
            
            return (True, path)

        except FragmentInitialisationError, fie :
            return (False, str(fie))