Example #1
0
    def _shutdown_result(self, success, operation_id, message=''):
        root = {}
        root[OperationKey.Operation] = OperationValue.Shutdown
        root[OperationKey.OperationId] = operation_id
        root[OperationKey.Success] = success
        root[OperationKey.Message] = message

        operation = SofOperation()
        operation.raw_result = json.dumps(root)
        operation.urn_response = CoreUrn.get_shutdown_urn()
        operation.request_method = RequestMethod.PUT

        self.add_to_result_queue(operation)
Example #2
0
    def _shutdown_result(self, success, operation_id, message=''):
        root = {}
        root[OperationKey.Operation] = OperationValue.Shutdown
        root[OperationKey.OperationId] = operation_id
        root[OperationKey.Success] = success
        root[OperationKey.Message] = message

        operation = SofOperation()
        operation.raw_result = json.dumps(root)
        operation.urn_response = CoreUrn.get_shutdown_urn()
        operation.request_method = RequestMethod.PUT

        self.add_to_result_queue(operation)
Example #3
0
    def _restart_if_needed(self, operation_restart, restart_needed):
        restart = False

        if operation_restart == RvOperationValue.ForcedRestart:
            restart = True

        elif (operation_restart == RvOperationValue.OptionalRestart
              and restart_needed):
            restart = True

        if restart:
            restart_op = SofOperation()
            restart_op.type = OperationValue.Reboot
            self._register_operation(restart_op)
Example #4
0
    def _restart_if_needed(self, operation_restart, restart_needed):
        restart = False

        if operation_restart == RvOperationValue.ForcedRestart:
            restart = True

        elif (operation_restart == RvOperationValue.OptionalRestart and
              restart_needed):
            restart = True

        if restart:
            restart_op = SofOperation()
            restart_op.type = OperationValue.Reboot
            self._register_operation(restart_op)
Example #5
0
    def initial_data_sender(self):

        logger.info("Sending initial data.")

        operation = SofOperation()

        if settings.AgentId != "":
            self._check_for_reboot()
            self._check_for_shutdown()

            operation.type = OperationValue.Startup

        else:
            operation.type = OperationValue.NewAgent

        self.process_operation(operation.to_json())
Example #6
0
    def initial_data_sender(self):

        logger.info("Sending initial data.")

        operation = SofOperation()

        if settings.AgentId != "":
            self._check_for_reboot()
            self._check_for_shutdown()

            operation.type = OperationValue.Startup

        else:
            operation.type = OperationValue.NewAgent

        self.process_operation(operation.to_json())
Example #7
0
def confirm_operation(data):
    operation = SofOperation(data)

    root = {}
    root['operation'] = 'received'
    root['operation_id'] = operation.id
    root['agent_id'] = settings.AgentId

    return json.dumps(root)
Example #8
0
    def server_response_processor(self, message):

        if message:

            for op in message.get('data', []):

                # Loading operation for server in order for the queue
                # dump to know if an operation is savable to file.

                try:

                    operation = SofOperation(json.dumps(op))
                    self.add_to_operation_queue(operation)

                except Exception as e:
                    logger.debug(
                        "Failed to create operation from: {0}".format(op))
                    logger.exception(e)

        self._save_uptime()
Example #9
0
    def process_operation(self, operation):

        try:

            if not isinstance(operation, SofOperation):
                operation = SofOperation(operation)

            logger.info("Process the following operation: {0}".format(
                operation.__dict__))

            self._sqlite.add_operation(operation, datetime.datetime.now())

            operation_methods = {
                OperationValue.SystemInfo: self.system_info_op,
                OperationValue.NewAgent: self.new_agent_op,
                OperationValue.Startup: self.startup_op,
                OperationValue.NewAgentId: self.new_agent_id_op,
                OperationValue.Reboot: self.reboot_op,
                OperationValue.Shutdown: self.shutdown_op
            }

            if operation.type in operation_methods:

                # Call method
                operation_methods[operation.type](operation)

            elif operation.plugin in self._plugins:
                self.plugin_op(operation)

            else:

                raise Exception('Operation/Plugin {0} was not found.'.format(
                    operation.__dict__))

        except Exception as e:

            logger.error("Error while processing operation: {0}".format(
                operation.__dict__))
            logger.exception(e)
            self._major_failure(operation, e)