def add_agent_to_operation(self, agent_id, operation_id): """Add an operation for an agent Args: agent_id (str): the agent id. operation_id (str): the operation 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.add_agent_to_operation( agent_id, operation_id ) Returns: 36 character UUID of the operation that was created for the agent. """ data_to_insert = { OperationPerAgentKey.AgentId: agent_id, OperationPerAgentKey.OperationId: operation_id, OperationPerAgentKey.CustomerName: self.customer_name, OperationPerAgentKey.Status: OperationPerAgentCodes.PendingPickUp, OperationPerAgentKey.PickedUpTime: DbTime.begining_of_time(), OperationPerAgentKey.ExpiredTime: DbTime.begining_of_time(), OperationPerAgentKey.CompletedTime: DbTime.begining_of_time(), OperationPerAgentKey.Errors: None } status_code, count, errors, generated_ids = ( insert_agent_into_agent_operations(data_to_insert) ) if status_code == DbCodes.Inserted: operation_id = generated_ids[0] else: operation_id = None return operation_id
def add_agent_to_install_operation(self, agent_id, operation_id, applications): """Add an install operation for an agent Args: agent_id (str): the agent id. operation_id (str): the operation id. applications (list): List of application dictionairies. 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' >>> applications = [ { 'app_id': '70d462913faad1ecaa85eda4c448a607164fe39414c8be44405e7ab4f7f8467c', 'app_name': 'linux-firmware' } ] >>> oper.add_agent_to_install_operation( agent_id, operation_id, applications ) Returns: Boolean """ completed = False operation_data = { OperationPerAgentKey.AgentId: agent_id, OperationPerAgentKey.OperationId: operation_id, OperationPerAgentKey.CustomerName: self.customer_name, OperationPerAgentKey.Status: OperationPerAgentCodes.PendingPickUp, OperationPerAgentKey.PickedUpTime: DbTime.begining_of_time(), OperationPerAgentKey.ExpiredTime: DbTime.begining_of_time(), OperationPerAgentKey.CompletedTime: DbTime.begining_of_time(), OperationPerAgentKey.AppsTotalCount: len(applications), OperationPerAgentKey.AppsPendingCount: len(applications), OperationPerAgentKey.AppsFailedCount: self.INIT_COUNT, OperationPerAgentKey.AppsCompletedCount: self.INIT_COUNT, OperationPerAgentKey.Errors: None } status_code, count, errors, generated_ids = ( insert_agent_into_agent_operations(operation_data)) if status_code == DbCodes.Inserted: apps = [] for app in applications: apps.append({ OperationPerAppKey.AgentId: agent_id, OperationPerAppKey.OperationId: operation_id, OperationPerAppKey.CustomerName: self.customer_name, OperationPerAppKey.Results: (AgentOperationCodes.ResultsPending), OperationPerAppKey.ResultsReceivedTime: (DbTime.begining_of_time()), OperationPerAppKey.AppId: app[OperationPerAppKey.AppId], OperationPerAppKey.AppName: (app[OperationPerAppKey.AppName]), OperationPerAppKey.AppVersion: (app[OperationPerAppKey.AppVersion]), OperationPerAppKey.AppsRemoved: [], OperationPerAppKey.Errors: None }) status_code, count, errors, generated_ids = ( insert_app_into_agent_operations(apps)) if status_code == DbCodes.Inserted: completed = True return completed
def add_agent_to_install_operation( self, agent_id, operation_id, applications ): """Add an install operation for an agent Args: agent_id (str): the agent id. operation_id (str): the operation id. applications (list): List of application dictionairies. 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' >>> applications = [ { 'app_id': '70d462913faad1ecaa85eda4c448a607164fe39414c8be44405e7ab4f7f8467c', 'app_name': 'linux-firmware' } ] >>> oper.add_agent_to_install_operation( agent_id, operation_id, applications ) Returns: Boolean """ completed = False operation_data = { OperationPerAgentKey.AgentId: agent_id, OperationPerAgentKey.OperationId: operation_id, OperationPerAgentKey.CustomerName: self.customer_name, OperationPerAgentKey.Status: OperationPerAgentCodes.PendingPickUp, OperationPerAgentKey.PickedUpTime: DbTime.begining_of_time(), OperationPerAgentKey.ExpiredTime: DbTime.begining_of_time(), OperationPerAgentKey.CompletedTime: DbTime.begining_of_time(), OperationPerAgentKey.AppsTotalCount: len(applications), OperationPerAgentKey.AppsPendingCount: len(applications), OperationPerAgentKey.AppsFailedCount: self.INIT_COUNT, OperationPerAgentKey.AppsCompletedCount: self.INIT_COUNT, OperationPerAgentKey.Errors: None } status_code, count, errors, generated_ids = ( insert_agent_into_agent_operations(operation_data) ) if status_code == DbCodes.Inserted: apps = [] for app in applications: apps.append( { OperationPerAppKey.AgentId: agent_id, OperationPerAppKey.OperationId: operation_id, OperationPerAppKey.CustomerName: self.customer_name, OperationPerAppKey.Results: ( AgentOperationCodes.ResultsPending ), OperationPerAppKey.ResultsReceivedTime: ( DbTime.begining_of_time() ), OperationPerAppKey.AppId: app[OperationPerAppKey.AppId], OperationPerAppKey.AppName: ( app[OperationPerAppKey.AppName] ), OperationPerAppKey.AppVersion: ( app[OperationPerAppKey.AppVersion] ), OperationPerAppKey.AppsRemoved: [], OperationPerAppKey.Errors: None } ) status_code, count, errors, generated_ids = ( insert_app_into_agent_operations(apps) ) if status_code == DbCodes.Inserted: completed = True return completed