Ejemplo n.º 1
0
def save_result(agent_id, operation_id, error, data, uri, method,
                operation_type):
    try:
        operation = Operation(Default.User, None, uri, method)

        if not error:

            results = operation.update_operation_results(
                operation_id, agent_id, OperationCodes.ResultsReceived,
                operation_type, error)

        else:

            results = operation.update_operation_results(
                operation_id, agent_id,
                OperationCodes.ResultsReceivedWithErrors, operation_type,
                error)

        return results

    except Exception as e:

        print e

    return None
Ejemplo n.º 2
0
def save_operation(operation):

    _oper = (Operation(operation.username, operation.customer, operation.uri,
                       operation.method))

    oper_results = (
        _oper.create_operation(
            operation.operation_type,
            ra.PluginName,
            [operation.agent_id],  # Expecting a list of agent IDs.
            None  # No tag IDs.
        ))

    if oper_results['http_status'] == 200:
        operation_id = oper_results['data']['operation_id']

        _oper.add_agent_to_operation(operation.agent_id, operation_id)

        logger.info(
            '%s - %s operation created by user %s' %
            (operation.username, operation.operation_type, operation.username))

        return operation_id

    return None
Ejemplo n.º 3
0
    def __init__(self,
                 username,
                 uri,
                 method,
                 agent_id,
                 app_id,
                 operation_id,
                 reboot_required,
                 success,
                 data,
                 apps_to_delete,
                 apps_to_add,
                 error=None):

        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(agentid=self.agent_id)
        self.customer_name = self.agent_data['customer_name']
        self.date_now = mktime(datetime.now().timetuple())
        self.error = error
        self.reboot_required = reboot_required
        self.success = success
        self.data = data
        self.apps_to_delete = apps_to_delete
        self.apps_to_add = apps_to_add
        self.app_id = app_id
        self.oper_info = get_oper_info(operid=self.operation_id)
        self.operation = (Operation(self.username, self.customer_name,
                                    self.uri, self.method))
Ejemplo n.º 4
0
    def generic_operation(self,
                          oper_type,
                          oper_plugin,
                          agentids=None,
                          tag_id=None):

        operation = (Operation(self.username, self.customer_name, self.uri,
                               self.method))

        results = (operation.create_operation(oper_type, oper_plugin, agentids,
                                              tag_id))

        operation_id = results['data'].get('operation_id', None)
        if operation_id:
            for agent_id in agentids:
                operation_data = {
                    OperationKey.Operation: oper_type,
                    OperationKey.OperationId: operation_id,
                    OperationKey.Plugin: oper_plugin,
                    OperationPerAgentKey.AgentId: agent_id,
                }
                self._store_in_agent_queue(operation_data)
                operation.add_agent_to_operation(agent_id, operation_id)

        return (results)
Ejemplo n.º 5
0
def save_result(
    agent_id,
    operation_id,
    error,
    data,
    uri,
    method,
    operation_type
):
    try:
        operation = Operation(
            Default.User,
            None,
            uri,
            method
        )

        if not error:

            results = operation.update_operation_results(
                operation_id,
                agent_id,
                OperationCodes.ResultsReceived,
                operation_type,
                error
            )

        else:

            results = operation.update_operation_results(
                operation_id,
                agent_id,
                OperationCodes.ResultsReceivedWithErrors,
                operation_type,
                error
            )

        return results

    except Exception as e:

        print e

    return None
Ejemplo n.º 6
0
def process_queue_data(rqueue, queue_exists, agent_id, username, customer_name,
                       uri, method):
    if queue_exists:
        agent_queue = rqueue.get_all_objects_in_queue()
        for operation in agent_queue:
            if operation.get(OperationKey.OperationId):
                oper = (Operation(username, customer_name, uri, method))
                oper.update_operation_pickup_time(
                    operation[OperationKey.OperationId], agent_id, CHECKIN)

        return agent_queue

    else:
        return ([])
Ejemplo n.º 7
0
    def __init__(self,
                 username,
                 uri,
                 method,
                 agent_id,
                 operation_id,
                 success,
                 error=None):

        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(agentid=self.agent_id)
        self.customer_name = self.agent_data['customer_name']
        self.date_now = mktime(datetime.now().timetuple())
        self.error = error
        self.success = success
        self.operation = (Operation(self.username, self.customer_name,
                                    self.uri, self.method))
Ejemplo n.º 8
0
    def install_apps(self,
                     oper_type,
                     oper_plugin,
                     appids,
                     cpu_throttle='normal',
                     net_throttle=0,
                     restart=None,
                     agentids=None,
                     tag_id=None):

        if oper_type == INSTALL_OS_APPS or oper_type == UNINSTALL:
            CurrentAppsCollection = AppsCollection
            CurrentAppsKey = AppsKey
            CurrentAppsPerAgentCollection = AppsPerAgentCollection
            CurrentAppsPerAgentKey = AppsPerAgentKey

        elif oper_type == INSTALL_CUSTOM_APPS:
            CurrentAppsCollection = CustomAppsCollection
            CurrentAppsKey = CustomAppsKey
            CurrentAppsPerAgentCollection = CustomAppsPerAgentCollection
            CurrentAppsPerAgentKey = CustomAppsPerAgentKey

        elif oper_type == INSTALL_SUPPORTED_APPS:
            CurrentAppsCollection = SupportedAppsCollection
            CurrentAppsKey = SupportedAppsKey
            CurrentAppsPerAgentCollection = SupportedAppsPerAgentCollection
            CurrentAppsPerAgentKey = SupportedAppsPerAgentKey

        elif oper_type == INSTALL_AGENT_APPS:
            CurrentAppsCollection = AgentAppsCollection
            CurrentAppsKey = AgentAppsKey
            CurrentAppsPerAgentCollection = AgentAppsPerAgentCollection
            CurrentAppsPerAgentKey = AgentAppsPerAgentKey

        if tag_id:
            if not agentids:
                agentids = get_agent_ids_from_tag(tag_id)
            else:
                agentids += get_agent_ids_from_tag(tag_id)

        operation = (Operation(self.username, self.customer_name, self.uri,
                               self.method))

        results = (operation.create_operation(oper_type, oper_plugin, agentids,
                                              tag_id, cpu_throttle,
                                              net_throttle, restart))
        operation_id = results['data'].get('operation_id', None)
        if operation_id:
            for agent_id in agentids:
                valid_appids = (self._return_valid_app_ids_for_agent(
                    agent_id, appids, table=CurrentAppsPerAgentCollection))

                pkg_data = []
                for app_id in valid_appids:
                    data_to_update = ({CurrentAppsPerAgentKey.Status: PENDING})
                    if oper_type == INSTALL_OS_APPS or oper_type == UNINSTALL:
                        update_os_app_per_agent(agent_id, app_id,
                                                data_to_update)

                    elif oper_type == INSTALL_CUSTOM_APPS:
                        update_custom_app_per_agent(agent_id, app_id,
                                                    data_to_update)

                    elif oper_type == INSTALL_SUPPORTED_APPS:
                        update_supported_app_per_agent(agent_id, app_id,
                                                       data_to_update)

                    elif oper_type == INSTALL_AGENT_APPS:
                        update_agent_app_per_agent(agent_id, app_id,
                                                   data_to_update)

                    pkg_data.append(
                        self._get_apps_data(app_id, agent_id, oper_type,
                                            CurrentAppsCollection,
                                            CurrentAppsKey.AppId))

                operation_data = {
                    OperationKey.Operation: oper_type,
                    OperationKey.OperationId: operation_id,
                    OperationKey.Plugin: oper_plugin,
                    OperationKey.Restart: restart,
                    PKG_FILEDATA: pkg_data,
                    OperationPerAgentKey.AgentId: agent_id,
                    OperationKey.CpuThrottle: cpu_throttle,
                    OperationKey.NetThrottle: net_throttle,
                }
                self._store_in_agent_queue(operation_data)
                operation.add_agent_to_install_operation(
                    agent_id, operation_id, pkg_data)

        return (results)