コード例 #1
0
    def startup_op(self, operation):
        operation = self._initial_data(operation)
        operation.raw_result = self._initial_formatter(operation)
        operation.urn_response = CoreUrn.get_startup_urn()
        operation.request_method = RequestMethod.PUT

        self.add_to_result_queue(operation)
コード例 #2
0
    def startup_op(self, operation):
        operation = self._initial_data(operation)
        operation.raw_result = self._initial_formatter(operation)
        operation.urn_response = CoreUrn.get_startup_urn()
        operation.request_method = RequestMethod.PUT

        self.add_to_result_queue(operation)
コード例 #3
0
    def login(self):

        try:

            logger.debug('Logging into server')

            self.http_session = requests.session()

            url = os.path.join(self._server_url, CoreUrn.get_login_urn())
            headers = {'content-type': 'application/json'}
            payload = {
                'name': settings.Username,
                'password': settings.Password
            }

            response = self.http_session.post(url,
                                              data=json.dumps(payload),
                                              headers=headers,
                                              verify=False,
                                              timeout=30)

            logger.debug("Login status code: %s " % response.status_code)
            logger.debug("Login server text: %s " % response.text)

            if response.status_code == 200:

                return True

        except Exception as e:

            logger.error("Agent was unable to login.")
            logger.exception(e)

        return False
コード例 #4
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)
コード例 #5
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)
コード例 #6
0
    def new_agent_op(self, operation):
        operation = self._initial_data(operation)
        operation.raw_result = self._initial_formatter(operation)
        operation.urn_response = CoreUrn.get_new_agent_urn()
        operation.request_method = RequestMethod.POST

        try:
            modified_json = json.loads(operation.raw_result)

            # Removing unnecessary keys from JSON
            del modified_json[OperationKey.OperationId]
            del modified_json[OperationKey.AgentId]

            operation.raw_result = json.dumps(modified_json)
        except Exception as e:
            logger.error("Failed to modify new agent operation JSON.")
            logger.exception(e)

        self.add_to_result_queue(operation)
コード例 #7
0
    def new_agent_op(self, operation):
        operation = self._initial_data(operation)
        operation.raw_result = self._initial_formatter(operation)
        operation.urn_response = CoreUrn.get_new_agent_urn()
        operation.request_method = RequestMethod.POST

        try:
            modified_json = json.loads(operation.raw_result)

            # Removing unnecessary keys from JSON
            del modified_json[OperationKey.OperationId]
            del modified_json[OperationKey.AgentId]

            operation.raw_result = json.dumps(modified_json)
        except Exception as e:
            logger.error("Failed to modify new agent operation JSON.")
            logger.exception(e)

        self.add_to_result_queue(operation)
コード例 #8
0
    def _agent_checkin(self):
        """
        Checks in to the server to retrieve all pending operations.
        @return: Nothing
        """
        if allow_checkin:
            root = {}
            root[OperationKey.Operation] = OperationValue.CheckIn
            root[OperationKey.OperationId] = ''
            root[OperationKey.AgentId] = settings.AgentId

            success = self.send_message(json.dumps(root),
                                        CoreUrn.get_checkin_urn(),
                                        RequestMethod.GET)

            if not success:
                logger.error(
                    "Could not check-in to server. See logs for details.")

        else:
            logger.info("Checkin set to false.")
コード例 #9
0
    def _agent_checkin(self):
        """
        Checks in to the server to retrieve all pending operations.
        @return: Nothing
        """
        if allow_checkin:
            root = {}
            root[OperationKey.Operation] = OperationValue.CheckIn
            root[OperationKey.OperationId] = ''
            root[OperationKey.AgentId] = settings.AgentId

            success = self.send_message(
                json.dumps(root), CoreUrn.get_checkin_urn(), RequestMethod.GET
            )

            if not success:
                logger.error(
                    "Could not check-in to server. See logs for details."
                )

        else:
            logger.info("Checkin set to false.")
コード例 #10
0
    def login(self):

        try:

            logger.debug('Logging into server')

            self.http_session = requests.session()

            url = os.path.join(self._server_url, CoreUrn.get_login_urn())
            headers = {'content-type': 'application/json'}
            payload = {
                'name': settings.Username,
                'password': settings.Password
            }

            response = self.http_session.post(
                url,
                data=json.dumps(payload),
                headers=headers,
                verify=False,
                timeout=30
            )

            logger.debug("Login status code: %s " % response.status_code)
            logger.debug("Login server text: %s " % response.text)

            if response.status_code == 200:

                return True

        except Exception as e:

            logger.error("Agent was unable to login.")
            logger.exception(e)

        return False