def __init__( self, username, agent_id, operation_id, success, error=None, status_code=None, uri=None, method=None ): super(PatchingOperationResults, self).__init__( username, agent_id, operation_id, success, error, status_code, uri, method ) self.operation = ( PatchingOperation( self.username, self.customer_name, ) )
def install_apps(self, oper_type, appids, cpu_throttle=CPUThrottleValues.NORMAL, net_throttle=0, restart=RebootValues.NONE, agentids=None, tag_id=None): """This method creates the operation and stores it into the agent queue. Args: oper_type (str): The operation type, etc.. install_os_apps, uninstall appids (list): List of the application ids, that you want to install. Kwargs: cpu_throttle (str): Throttle how much cpu to use while installing the applications. default = normal net_throttle (int): Throttle how much bandwidth is being used, while the agent is downloading the applications. default = 0 (unlimited) restart (str): Choose if you want to restart the system after the application is installed. Examples (none, needed, forced) default = 'none' (do not reboot) agentids (str): List of agent ids. default = None tag_id (str): 36 character UUID of the agent. default = None """ oper_plugin = vFensePlugins.RV_PLUGIN results = { ApiResultKeys.DATA: [], ApiResultKeys.USERNAME: self.username, ApiResultKeys.URI: self.uri, ApiResultKeys.HTTP_METHOD: self.method } performed_on = vFenseObjects.AGENT if tag_id: performed_on = vFenseObjects.TAG if not agentids: agentids = get_agent_ids_from_tag(tag_id) else: agentids += get_agent_ids_from_tag(tag_id) operation = (PatchingOperation( self.username, self.customer_name, )) operation_id = (operation.create_operation(oper_type, oper_plugin, agentids, tag_id, cpu_throttle, net_throttle, restart, performed_on=performed_on)) if operation_id: msg = 'operation created' status_code = GenericCodes.ObjectCreated vfense_status_code = AgentOperationCodes.Created results[ApiResultKeys.GENERATED_IDS] = [operation_id] results[ApiResultKeys.GENERIC_STATUS_CODE] = status_code results[ApiResultKeys.VFENSE_STATUS_CODE] = vfense_status_code results[ApiResultKeys.MESSAGE] = msg for agent_id in agentids: valid_appids = (return_valid_appids_for_agent( appids, agent_id, collection=self.CurrentAppsPerAgentCollection)) pkg_data = [] for app_id in valid_appids: update_app_status_by_agentid_and_appid( agent_id, app_id, CommonAppKeys.PENDING, self.CurrentAppsPerAgentCollection) pkg_data.append(self._get_apps_data(app_id, agent_id)) operation_data = { AgentOperationKey.Operation: oper_type, AgentOperationKey.OperationId: operation_id, AgentOperationKey.Plugin: oper_plugin, AgentOperationKey.Restart: restart, CommonFileKeys.PKG_FILEDATA: pkg_data, OperationPerAgentKey.AgentId: agent_id, AgentOperationKey.CpuThrottle: cpu_throttle, AgentOperationKey.NetThrottle: net_throttle, } self._store_in_agent_queue(operation_data) operation.add_agent_to_install_operation( agent_id, operation_id, pkg_data) else: msg = 'operation failed to create' status_code = GenericFailureCodes.FailedToCreateObject vfense_status_code = ( AgentOperationFailureCodes.FailedToCreateOperation) results[ApiResultKeys.GENERATED_IDS] = [operation_id], results[ApiResultKeys.GENERIC_STATUS_CODE] = status_code results[ApiResultKeys.VFENSE_STATUS_CODE] = vfense_status_code results[ApiResultKeys.MESSAGE] = msg return results