def _update_completed_time_on_agents(self, operation_id, agent_id): """Update the completed time for the agent operation. Args: operation_id (str): the operation id. agent_id (str): the agent id. Basic Usage: >>> from vFense.operations.agent_operations import AgentOperation >>> username = '******' >>> customer_name = 'default' >>> oper = AgentOperation(username, customer_name) >>> operation_id = '5dc03727-de89-460d-b2a7-7f766c83d2f1' >>> agent_id = '38c1c67e-436f-4652-8cae-f1a2ac2dd4a2' >>> oper._update_completed_time_on_agents(operation_id, agent_id) Returns: Boolean """ completed = False data = {OperationPerAgentKey.CompletedTime: self.db_time} status_code, count, errors, generated_ids = ( update_operation_per_agent(operation_id, agent_id, data) ) if status_code == DbCodes.Replaced or status_code == DbCodes.Unchanged: completed = True return completed
def update_operation_results( self, operation_id, agent_id, status, operation, errors=None, ): """Update the results for an operation. Args: operation_id (str): The operation id. agent_id (str): The agent id. status (int): The operation status code. operation (str): The operation type. Kwargs: errors (str): The error message, default is None. Basic Usage: >>> from vFense.operations.agent_operations import AgentOperation >>> username = '******' >>> customer_name = 'default' >>> oper = AgentOperation(username, customer_name) >>> operation_id = '5dc03727-de89-460d-b2a7-7f766c83d2f1' >>> agent_id = '38c1c67e-436f-4652-8cae-f1a2ac2dd4a2' >>> status_code = 6006 >>> operation = 'install_os_apps' >>> oper.update_operation_results( operation_id, agent_id, status_code, operation ) Returns: Boolean """ completed = False operation_data = ( { OperationPerAgentKey.Status: status, OperationPerAgentKey.CompletedTime: self.db_time, OperationPerAgentKey.Errors: errors } ) status_code, count, errors, generated_ids = ( update_operation_per_agent(operation_id, agent_id, operation_data) ) if status_code == DbCodes.Replaced or status_code == DbCodes.Unchanged: self._update_agent_stats(operation_id, agent_id) self._update_operation_status_code(operation_id) completed = True return completed
def _update_app_stats(self, operation_id, agent_id, app_id): """Update the total counts based on the status code. Args: operation_id (str): The operation id. agent_id (str): The agent id. app_id (str): The application id. Basic Usage: >>> from vFense.operations.agent_operations import AgentOperation >>> username = '******' >>> customer_name = 'default' >>> oper = AgentOperation(username, customer_name) >>> operation_id = '5dc03727-de89-460d-b2a7-7f766c83d2f1' >>> agent_id = '38c1c67e-436f-4652-8cae-f1a2ac2dd4a2' >>> app_id = '70d462913faad1ecaa85eda4c448a607164fe39414c8be44405e7ab4f7f8467c' >>> oper._update_app_stats( operation_id, agent_id, app_id, ) Returns: Boolean """ completed = False pending_count, completed_count, failed_count = ( group_operations_per_app_by_results( operation_id, agent_id ) ) operation_data = { OperationPerAgentKey.AppsCompletedCount: completed_count, OperationPerAgentKey.AppsFailedCount: failed_count, OperationPerAgentKey.AppsPendingCount: pending_count, } status_code, count, errors, generated_ids = ( update_operation_per_agent(operation_id, agent_id, operation_data) ) if status_code == DbCodes.Replaced or status_code == DbCodes.Unchanged: self._update_agent_stats_by_app_stats( operation_id, agent_id, completed_count, failed_count, pending_count ) completed = True return completed
def update_operation_expire_time(self, operation_id, agent_id): """Expire the operation for agent id Args: operation_id (str): the operation id. agent_id (str): the agent id. Basic Usage: >>> from vFense.operations.agent_operations import AgentOperation >>> username = '******' >>> customer_name = 'default' >>> oper = AgentOperation(username, customer_name) >>> operation_id = '5dc03727-de89-460d-b2a7-7f766c83d2f1' >>> agent_id = '38c1c67e-436f-4652-8cae-f1a2ac2dd4a2' >>> oper.update_operation_expire_time(operation_id, agent_id) Returns: Boolean """ completed = False operation_data = ( { OperationPerAgentKey.Status: ( OperationPerAgentCodes.OperationExpired ), OperationPerAgentKey.ExpiredTime: self.db_time, OperationPerAgentKey.CompletedTime: self.db_time, OperationPerAgentKey.Errors: OperationErrors.EXPIRED, } ) status_code, count, errors, generated_ids = ( update_operation_per_agent(operation_id, agent_id, operation_data) ) if status_code == DbCodes.Replaced or status_code == DbCodes.Unchanged: status_code, count, errors, generated_ids = ( update_agent_operation_expire_time( operation_id, self.db_time ) ) completed = True return completed
def _update_app_stats(self, operation_id, agent_id, app_id): """Update the total counts based on the status code. Args: operation_id (str): The operation id. agent_id (str): The agent id. app_id (str): The application id. Basic Usage: >>> from vFense.operations.agent_operations import AgentOperation >>> username = '******' >>> customer_name = 'default' >>> oper = AgentOperation(username, customer_name) >>> operation_id = '5dc03727-de89-460d-b2a7-7f766c83d2f1' >>> agent_id = '38c1c67e-436f-4652-8cae-f1a2ac2dd4a2' >>> app_id = '70d462913faad1ecaa85eda4c448a607164fe39414c8be44405e7ab4f7f8467c' >>> oper._update_app_stats( operation_id, agent_id, app_id, ) Returns: Boolean """ completed = False pending_count, completed_count, failed_count = ( group_operations_per_app_by_results(operation_id, agent_id)) operation_data = { OperationPerAgentKey.AppsCompletedCount: completed_count, OperationPerAgentKey.AppsFailedCount: failed_count, OperationPerAgentKey.AppsPendingCount: pending_count, } status_code, count, errors, generated_ids = ( update_operation_per_agent(operation_id, agent_id, operation_data)) if status_code == DbCodes.Replaced or status_code == DbCodes.Unchanged: self._update_agent_stats_by_app_stats(operation_id, agent_id, completed_count, failed_count, pending_count) completed = True return completed