Пример #1
0
    def runthreads(self):
        """
        creates an object ProjectThreadMgr and enters main loop
        This method is intended to be called by the daemon.
        """
        self.log.debug('Start')

        try:
            self.log.info(
                'creating ProjectThreadMgr object and entering main loop')
            self.projectthreadmgr = ProjectThreadMgr(self)
            self.projectthreadmgr.mainLoop()
        except KeyboardInterrupt:
            self.log.info('Caught keyboard interrupt - exitting')
            sys.exit(0)
        except ImportError, errorMsg:
            self.log.error('Failed to import necessary python module: %s' %
                           errorMsg)
            sys.exit(0)
Пример #2
0
    def runthreads(self):
        """
        creates an object ProjectThreadMgr and enters main loop
        This method is intended to be called by the daemon.
        """
        self.log.debug('Start')

        try: 
            self.log.info('creating ProjectThreadMgr object and entering main loop')
            self.projectthreadmgr = ProjectThreadMgr(self)
            self.projectthreadmgr.mainLoop()
        except KeyboardInterrupt:
            self.log.info('Caught keyboard interrupt - exitting')
            sys.exit(0)
        except ImportError, errorMsg:
            self.log.error('Failed to import necessary python module: %s' % errorMsg)
            sys.exit(0)
Пример #3
0
class oasisd(object):
    '''
    class to be invoked by the OASIS daemon.
    Includes steps that regular users are not authorized to perform:
        -- run probes
        -- transfer files
        -- publish
    '''

    def __init__(self):

        # 
        #  !!! FIXME !!!
        #  
        # this class has some code in common with class oasisCLI()
        # maybe they both should inherit from a base class
        #

        self.probes_rc = 0  # ?? do we need it ??

        # FIXME
        # maybe parsing the input options should have be done already
        # in that case, the client /usr/bin/oasisd
        # would call a factory class, instead of directly class oasisd() 
        self._parseopts()

        self._setuplogging()

        try:
            self.oasisconf = self._getbasicconfig()
            self.projectsconf = self._getprojectconfig()
        except:
            self.log.critical('Configuration cannot be read. Aborting.')
            sys.exit(1)

        self.log.debug('Object oasisd created.')


    # --------------------------------------------------------------
    #      P R E L I M I N A R I E S
    # --------------------------------------------------------------

    def _parseopts(self):
        '''
        parsing the input options.
        These inputs are setup in /etc/sysconfig/oasisd.sysconfig
        '''

        opts, args = getopt.getopt(sys.argv[1:], '', ['conf=', 'loglevel=', 'logfile='])
        for o, a in opts:

            # FIXME 
            # ?? should they have default values in case they are not passed from sysconfig ??
            if o == '--conf':
                self.conffile = a

            if o == '--loglevel':
                if a == 'debug':
                    self.loglevel = logging.DEBUG
                elif a == 'info':
                    self.loglevel = logging.INFO
                elif a == 'warning':
                    self.loglevel = logging.WARNING

            if o == '--logfile':
                self.logfile = a
        

    def _setuplogging(self):
        
        self.log = logging.getLogger()

        # set the messages format
        if major == 2 and minor == 4:
            LOGFILE_FORMAT='%(asctime)s (UTC) - OASIS [ %(levelname)s ] %(name)s %(filename)s:%(lineno)d : %(message)s'
        else:
            LOGFILE_FORMAT='%(asctime)s (UTC) - OASIS [ %(levelname)s ] %(name)s %(filename)s:%(lineno)d %(funcName)s(): %(message)s'
        logfile_formatter = logging.Formatter(LOGFILE_FORMAT)
        logfile_formatter.converter = time.gmtime  # to convert timestamps to UTC
       
        logStream = logging.FileHandler(self.logfile)
        logStream.setFormatter(logfile_formatter)
        self.log.addHandler(logStream)
        self.log.setLevel(self.loglevel)  
        

    # --------------------------------------------------------------

    def _getbasicconfig(self):
        '''
        returns a ConfigParser object for oasis.conf
        '''
        self.log.debug('Start')
        oasisconf = SafeConfigParser()
        oasisconf.readfp(open(self.conffile))
        self.log.debug('Leaving with config object %s' %oasisconf)
        return oasisconf

    def _getprojectconfig(self):
        '''
        returns a ConfigParser object for oasisproject.conf
        '''
        self.log.debug('Start')
        oasisprojectsconffilename = self.oasisconf.get('OASIS', 'projectsconf')
        oasisprojectsconf = SafeConfigParser()
        oasisprojectsconf.readfp(open(oasisprojectsconffilename))
        self.log.debug('Leaving with config object %s' %oasisprojectsconf)
        return oasisprojectsconf


    # ===========================================================================

    def runthreads(self):
        """
        creates an object ProjectThreadMgr and enters main loop
        This method is intended to be called by the daemon.
        """
        self.log.debug('Start')

        try: 
            self.log.info('creating ProjectThreadMgr object and entering main loop')
            self.projectthreadmgr = ProjectThreadMgr(self)
            self.projectthreadmgr.mainLoop()
        except KeyboardInterrupt:
            self.log.info('Caught keyboard interrupt - exitting')
            sys.exit(0)
        except ImportError, errorMsg:
            self.log.error('Failed to import necessary python module: %s' % errorMsg)
            sys.exit(0)
        except:
Пример #4
0
class oasisd(object):
    '''
    class to be invoked by the OASIS daemon.
    Includes steps that regular users are not authorized to perform:
        -- run probes
        -- transfer files
        -- publish
    '''
    def __init__(self):

        #
        #  !!! FIXME !!!
        #
        # this class has some code in common with class oasisCLI()
        # maybe they both should inherit from a base class
        #

        self.probes_rc = 0  # ?? do we need it ??

        # FIXME
        # maybe parsing the input options should have be done already
        # in that case, the client /usr/bin/oasisd
        # would call a factory class, instead of directly class oasisd()
        self._parseopts()

        self._setuplogging()

        try:
            self.oasisconf = self._getbasicconfig()
            self.projectsconf = self._getprojectconfig()
        except:
            self.log.critical('Configuration cannot be read. Aborting.')
            sys.exit(1)

        self.log.debug('Object oasisd created.')

    # --------------------------------------------------------------
    #      P R E L I M I N A R I E S
    # --------------------------------------------------------------

    def _parseopts(self):
        '''
        parsing the input options.
        These inputs are setup in /etc/sysconfig/oasisd.sysconfig
        '''

        opts, args = getopt.getopt(sys.argv[1:], '',
                                   ['conf=', 'loglevel=', 'logfile='])
        for o, a in opts:

            # FIXME
            # ?? should they have default values in case they are not passed from sysconfig ??
            if o == '--conf':
                self.conffile = a

            if o == '--loglevel':
                if a == 'debug':
                    self.loglevel = logging.DEBUG
                elif a == 'info':
                    self.loglevel = logging.INFO
                elif a == 'warning':
                    self.loglevel = logging.WARNING

            if o == '--logfile':
                self.logfile = a

    def _setuplogging(self):

        self.log = logging.getLogger()

        # set the messages format
        if major == 2 and minor == 4:
            LOGFILE_FORMAT = '%(asctime)s (UTC) - OASIS [ %(levelname)s ] %(name)s %(filename)s:%(lineno)d : %(message)s'
        else:
            LOGFILE_FORMAT = '%(asctime)s (UTC) - OASIS [ %(levelname)s ] %(name)s %(filename)s:%(lineno)d %(funcName)s(): %(message)s'
        logfile_formatter = logging.Formatter(LOGFILE_FORMAT)
        logfile_formatter.converter = time.gmtime  # to convert timestamps to UTC

        logStream = logging.FileHandler(self.logfile)
        logStream.setFormatter(logfile_formatter)
        self.log.addHandler(logStream)
        self.log.setLevel(self.loglevel)

    # --------------------------------------------------------------

    def _getbasicconfig(self):
        '''
        returns a ConfigParser object for oasis.conf
        '''
        self.log.debug('Start')
        oasisconf = SafeConfigParser()
        oasisconf.readfp(open(self.conffile))
        self.log.debug('Leaving with config object %s' % oasisconf)
        return oasisconf

    def _getprojectconfig(self):
        '''
        returns a ConfigParser object for oasisproject.conf
        '''
        self.log.debug('Start')
        oasisprojectsconffilename = self.oasisconf.get('OASIS', 'projectsconf')
        oasisprojectsconf = SafeConfigParser()
        oasisprojectsconf.readfp(open(oasisprojectsconffilename))
        self.log.debug('Leaving with config object %s' % oasisprojectsconf)
        return oasisprojectsconf

    # ===========================================================================

    def runthreads(self):
        """
        creates an object ProjectThreadMgr and enters main loop
        This method is intended to be called by the daemon.
        """
        self.log.debug('Start')

        try:
            self.log.info(
                'creating ProjectThreadMgr object and entering main loop')
            self.projectthreadmgr = ProjectThreadMgr(self)
            self.projectthreadmgr.mainLoop()
        except KeyboardInterrupt:
            self.log.info('Caught keyboard interrupt - exitting')
            sys.exit(0)
        except ImportError, errorMsg:
            self.log.error('Failed to import necessary python module: %s' %
                           errorMsg)
            sys.exit(0)
        except: