示例#1
0
    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
示例#2
0
文件: results.py 项目: vFense/vFense
    def __init__(self,
                 username,
                 agent_id,
                 operation_id,
                 success,
                 error=None,
                 status_code=None,
                 uri=None,
                 method=None):
        """
        Args:
            username (str): The name of the user who made this api call
            agent_id (str): 36 character UUID of the agent.
            operation_id (str): 36 character UUID of the operation.
            success (str): true or false.

        Kwargs:
            error (str): The error message, if the operation failed.
            status_code (int): The exact status of this operation.
            uri (str): The uri which was called for the results.
            method (str): The method used to call this api.

        Basic Usage:
            >>> from vFense.operations.results import OperationResults
            >>> username = '******'
            >>> operation_id = '8fed3dc7-33d4-4278-9bd4-398a68bf7f22'
            >>> agent_id = 'db6bf07-c5da-4494-93bb-109db205ca64'
            >>> success = 'true'
            >>> results = OperationResults(
                    username, agent_id, operation_id, success
                )
        """

        self.agent_id = agent_id
        self.operation_id = operation_id
        self.username = username
        self.uri = uri
        self.method = method
        self.agent_data = get_agent_info(self.agent_id)
        self.operation_data = get_agent_operation(self.operation_id)
        self.customer_name = self.agent_data[AgentKey.CustomerName]
        self.date_now = DbTime.time_now()
        self.begining_of_time = DbTime.begining_of_time()
        self.error = error
        self.success = success
        self.status_code = status_code
        self.operation = (AgentOperation(
            self.username,
            self.customer_name,
        ))
示例#3
0
    def __init__(
            self, username, agent_id, operation_id,
            success, error=None, status_code=None,
            uri=None, method=None
        ):
        """
        Args:
            username (str): The name of the user who made this api call
            agent_id (str): 36 character UUID of the agent.
            operation_id (str): 36 character UUID of the operation.
            success (str): true or false.

        Kwargs:
            error (str): The error message, if the operation failed.
            status_code (int): The exact status of this operation.
            uri (str): The uri which was called for the results.
            method (str): The method used to call this api.

        Basic Usage:
            >>> from vFense.operations.results import OperationResults
            >>> username = '******'
            >>> operation_id = '8fed3dc7-33d4-4278-9bd4-398a68bf7f22'
            >>> agent_id = 'db6bf07-c5da-4494-93bb-109db205ca64'
            >>> success = 'true'
            >>> results = OperationResults(
                    username, agent_id, operation_id, success
                )
        """

        self.agent_id = agent_id
        self.operation_id = operation_id
        self.username = username
        self.uri = uri
        self.method = method
        self.agent_data = get_agent_info(self.agent_id)
        self.operation_data = get_agent_operation(self.operation_id)
        self.customer_name = self.agent_data[AgentKey.CustomerName]
        self.date_now = DbTime.time_now()
        self.begining_of_time = DbTime.begining_of_time()
        self.error = error
        self.success = success
        self.status_code = status_code
        self.operation = (
            AgentOperation(
                self.username, self.customer_name,
            )
        )
示例#4
0
    def create_operation(
            self, operation, plugin, agent_ids,
            tag_id, cpu_throttle=None, net_throttle=None,
            restart=None, performed_on=vFenseObjects.AGENT,
        ):
        """Create the base operation. Here is where the
            operation_id is generated. 
        Args:
            operation (str): The operation (install_os_apps, reboot, etc..).
            plugin (str): The plugin this operation is from (rv, core, ra, erc..).
            agent_ids (list): List of agent ids, this operation is being performed on.
            tag_id (str): The tag id, that this operation is being performed on.

        Kwargs:
            cpu_throttle (str): The default is normal, do not throttle.
            net_throttle (int): The default is 0, do not throttle.
            restart (str): The default is none, do not restart.
            performed_on (str): The default is agent.

        Basic Usage:
            >>> from vFense.operations.agent_operations import AgentOperation
            >>> username = '******'
            >>> customer_name = 'default'
            >>> oper = AgentOperation(username, customer_name)
            >>> operation = 'reboot'
            >>> plugin = 'core'
            >>> agent_ids = ['38c1c67e-436f-4652-8cae-f1a2ac2dd4a2']
            >>> tag_id = None
            >>> performed_on = 'agent'
            >>> oper.create_operation(operation, plugin, agent_ids, tag_id)

        Returns:
            String The 36 character UUID of the operation that was created.
            6c0209d5-b350-48b7-808a-158ddacb6940
        """

        number_of_agents = len(agent_ids)
        keys_to_insert = (
            {
                AgentOperationKey.Plugin: plugin,
                AgentOperationKey.Operation: operation,
                AgentOperationKey.OperationStatus: (
                    AgentOperationCodes.ResultsIncomplete
                ),
                AgentOperationKey.CustomerName: self.customer_name,
                AgentOperationKey.CreatedBy: self.username,
                AgentOperationKey.ActionPerformedOn: performed_on,
                AgentOperationKey.TagId: tag_id,
                AgentOperationKey.AgentIds: agent_ids,
                AgentOperationKey.AgentsTotalCount: number_of_agents,
                AgentOperationKey.AgentsExpiredCount: self.INIT_COUNT,
                AgentOperationKey.AgentsPendingResultsCount: self.INIT_COUNT,
                AgentOperationKey.AgentsPendingPickUpCount: number_of_agents,
                AgentOperationKey.AgentsFailedCount: self.INIT_COUNT,
                AgentOperationKey.AgentsCompletedCount: self.INIT_COUNT,
                AgentOperationKey.AgentsCompletedWithErrorsCount: (
                    self.INIT_COUNT
                ),
                AgentOperationKey.CreatedTime: self.db_time,
                AgentOperationKey.UpdatedTime: self.db_time,
                AgentOperationKey.CompletedTime: DbTime.begining_of_time(),
                AgentOperationKey.Restart: restart,
                AgentOperationKey.CpuThrottle: cpu_throttle,
                AgentOperationKey.NetThrottle: net_throttle,
            }
        )
        status_code, count, errors, generated_ids = (
            insert_into_agent_operations(keys_to_insert)
        )
        if status_code == DbCodes.Inserted:
            operation_id = generated_ids[0]

        else:
            operation_id = None

        return operation_id
示例#5
0
    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
示例#6
0
    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