示例#1
0
    def __init__(self, name, *p, **k):

        # base
        BasicModule.__init__(self, name, *p, **k)

        # config
        self.path_tf = Config().get('dir', 'pathTf').strip()
        self.path_fluxd = Config().get('dir', 'pathFluxd').strip()
        self.host = Config().getExt(name, 'host').strip()
        self.port = int(Config().getExt(name, 'port').strip())
        self.secure = Config().getExt(name, 'secure').strip()
        self.username = Config().getExt(name, 'username').strip()
        self.password = Config().getExt(name, 'password').strip()
        self.maxReconnectTries = int(Config().get(name, 'maxReconnectTries').strip())
        
        # fluazu-daemon
        self._fluazud = FluAzuD(self.logger)
示例#2
0
class Fluazu(BasicModule):

    # lock
    InstanceLock = Lock()

    """ -------------------------------------------------------------------- """
    """ __init__                                                             """
    """ -------------------------------------------------------------------- """
    def __init__(self, name, *p, **k):

        # base
        BasicModule.__init__(self, name, *p, **k)

        # config
        self.path_tf = Config().get('dir', 'pathTf').strip()
        self.path_fluxd = Config().get('dir', 'pathFluxd').strip()
        self.host = Config().getExt(name, 'host').strip()
        self.port = int(Config().getExt(name, 'port').strip())
        self.secure = Config().getExt(name, 'secure').strip()
        self.username = Config().getExt(name, 'username').strip()
        self.password = Config().getExt(name, 'password').strip()
        self.maxReconnectTries = int(Config().get(name, 'maxReconnectTries').strip())
        
        # fluazu-daemon
        self._fluazud = FluAzuD(self.logger)

    """ -------------------------------------------------------------------- """
    """ status                                                               """
    """ -------------------------------------------------------------------- """
    def status(self):
        data = {}
        data['version'] = __version_str__
        fluazudStatus = self._fluazud.getStatus()
        for ke, va in fluazudStatus.iteritems():
            data[ke] = va
        for transfer in self._fluazud.transfers:
            data["Transfer %s" % transfer.name] = transfer.state
        for dName, dObj in self._fluazud.downloads.iteritems():
            data["Download %s" % dName] = dObj.__str__()
        return data

    """ -------------------------------------------------------------------- """
    """ command                                                              """
    """ -------------------------------------------------------------------- """
    @synchronized(InstanceLock)
    def command(self, cmd):

        # log
        self.logger.debug('command: %s' % cmd)

        # stop
        if cmd == 'stop':
            if self.running:
                self.running = False
                self._fluazud.stop()
                return 'initialize Module-shutdown...'
            else:
                return 'Module not running'

        # reloadConfig   
        elif cmd.startswith('reloadConfig'):

            # message
            msg = 'Config reloaded on-the-fly not supported, module-reload is needed'

            # info
            self.logger.info(msg)

            # return
            return msg

        # unknown
        return 'Command unknown: %s' % cmd

    """ -------------------------------------------------------------------- """
    """ getVersion                                                           """
    """ -------------------------------------------------------------------- """
    def getVersion(self):
        return __version_str__

    """ -------------------------------------------------------------------- """
    """ onStart                                                              """
    """ -------------------------------------------------------------------- """
    def onStart(self):

        # DEBUG
        self.logger.debug('onStart')
        
        # run fluazud
        self._fluazud.run(self.path_tf, self.path_fluxd, self.host, self.port, self.secure, self.username, self.password, self.maxReconnectTries)

    """ -------------------------------------------------------------------- """
    """ main                                                                 """
    """ -------------------------------------------------------------------- """
    def main(self):

        # main-loop
        while self.running and self._fluazud.isRunning():

            try:

                # call fluazud-main
                self._fluazud.main()

            except Exception, e:
                if self.running:
                    self.logger.error("Exception in Module-Thread (%s)" % (e))