Esempio n. 1
0
    def set_autostart_interval(self, interval_time):
        """Update the autostart interval for the node"""
        self._get_registered_object('auth').assert_permission(PERMISSIONS.MANAGE_NODE)
        ArgumentValidator.validate_integer(interval_time)
        interval_time = int(interval_time)

        def update_config(config):
            config['autostart_interval'] = interval_time
        self._get_registered_object('mcvirt_config')().update_config(update_config,
                                                                     'Update autostart interval')

        if self._is_cluster_master:

            def remote_update(node):
                autostart_watchdog = node.get_connection('autostart_watchdog')
                autostart_watchdog.set_autostart_interval(interval_time)
            cluster = self._get_registered_object('cluster')
            cluster.run_remote_command(remote_update)

        # If the timer has been set to 0, disable the timer
        if interval_time == 0:
            self.repeat = False
            self.timer.cancel()
            self.timer = None
        else:
            # Otherwise update the running timer
            if self.timer is None:
                self.repeat = True
                self.repeat_run()
Esempio n. 2
0
    def get_logs(self, start_log=None, back=0, newer=False):
        """Return a dict containing log information"""
        if start_log is not None:
            ArgumentValidator.validate_integer(start_log)
        ArgumentValidator.validate_integer(back)
        ArgumentValidator.validate_boolean(newer)

        if start_log is None:
            start_log = len(Logger.LOGS) - 1

        if start_log < 0:
            start_log = 0
        if start_log > (len(Logger.LOGS) - 1):
            start_log = len(Logger.LOGS) - 1

        if back:
            start = 0 if (start_log - back) < 0 else (len(Logger.LOGS) - back)
            finish = start_log + 1
        elif newer:
            start = start_log + 1
            # Length would provide an indicy out of the range,
            # since len(['a']) = 1, but ['a'][1] == error
            # However, this is made up for the fact that range(0, 2) = [0, 1]
            finish = len(Logger.LOGS)
        else:
            # Start at the current log, to return it
            # Finish at current log + 1 as range(1, 2) = [1]
            start = start_log
            finish = start_log + 1

        return_logs = {}
        for itx in range(start, finish):
            if itx < 0:
                continue
            if len(Logger.LOGS) < itx:
                break
            log = Logger.LOGS[itx]
            return_logs[itx] = {
                'start_date':
                str(log.start_time),
                'status':
                log.status['status'],
                'status_name':
                log.status['name'],
                'user':
                log.user,
                'method':
                log.method_name,
                'object_name':
                log.object_name,
                'object_type':
                log.object_type,
                'description':
                '%s %s %s' % (log.method_name.capitalize(), log.object_name,
                              log.object_type),
                'exception_message':
                log.exception_message
            }
        return return_logs
Esempio n. 3
0
    def get_logs(self, start_log=None, back=0, newer=False):
        """Return a dict containing log information"""
        if start_log is not None:
            ArgumentValidator.validate_integer(start_log)
        ArgumentValidator.validate_integer(back)
        ArgumentValidator.validate_boolean(newer)

        if start_log is None:
            start_log = len(Logger.LOGS) - 1

        if start_log < 0:
            start_log = 0
        if start_log > (len(Logger.LOGS) - 1):
            start_log = len(Logger.LOGS) - 1

        if back:
            start = 0 if (start_log - back) < 0 else (len(Logger.LOGS) - back)
            finish = start_log + 1
        elif newer:
            start = start_log + 1
            # Length would provide an indicy out of the range,
            # since len(['a']) = 1, but ['a'][1] == error
            # However, this is made up for the fact that range(0, 2) = [0, 1]
            finish = len(Logger.LOGS)
        else:
            # Start at the current log, to return it
            # Finish at current log + 1 as range(1, 2) = [1]
            start = start_log
            finish = start_log + 1

        return_logs = {}
        for itx in range(start, finish):
            if itx < 0:
                continue
            if len(Logger.LOGS) < itx:
                break
            log = Logger.LOGS[itx]
            return_logs[itx] = {
                'start_date': str(log.start_time),
                'status': log.status['status'],
                'status_name': log.status['name'],
                'user': log.user,
                'method': log.method_name,
                'object_name': log.object_name,
                'object_type': log.object_type,
                'description': '%s %s %s' % (log.method_name.capitalize(),
                                             log.object_name,
                                             log.object_type),
                'exception_message': log.exception_message
            }
        return return_logs