def start(self):
        """ Starts the monitor activity
        """
        rt = True
        self.remove_monitor_data()

        # Load all system from current_local
        logger.info("Checking for pending updates")
        result, systems = get_systems()
        if not result:
            logger.error("Can't retrieve the system info: %s" % str(systems))
            return False

        pending_updates = False
        for (system_id, system_ip) in systems:
            (success, info) = apimethod_get_update_info(system_id)
            if success:
                try:
                    sys_pending_updates = info['pending_updates']
                    pending_updates = pending_updates or sys_pending_updates
                    logger.info("Pending Updates for system %s (%s): %s" %
                                (system_id, system_ip, sys_pending_updates))
                    monitor_data = {"pending_updates": sys_pending_updates}
                    self.save_data(system_id, ComponentTypes.SYSTEM,
                                   self.get_json_message(monitor_data))
                except Exception as e:
                    logger.error("[MonitorPendingUpdates] Error: %s" % str(e))
                    rt = False
                    break
            else:
                logger.error("MonitorPendingUpdates: %s" % info)
                rt = False
                break

        if pending_updates:
            success, local_ip = get_system_ip_from_local()
            if not success:
                logger.error(
                    "[MonitorPendingUpdates] Unable to get local IP: %s" %
                    local_ip)
                return False

            success, is_pro = get_is_professional(local_ip)
            if success and is_pro:
                success, is_trial = system_is_trial('local')
                if success and is_trial:
                    logger.info(
                        "[MonitorPendingUpdates] Trial version. Skipping download of release info file"
                    )
                    return rt

            success, msg = ansible_download_release_info(local_ip)
            if not success:
                logger.error(
                    "[MonitorPendingUpdates] Unable to retrieve release info file: %s"
                    % msg)
                return False

        return rt
Beispiel #2
0
    def start(self):
        """ Starts the monitor activity
        """
        rt = True
        self.remove_monitor_data()

        # Load all system from current_local
        logger.info("Checking for pending updates")
        result, systems = get_systems()
        if not result:
            logger.error("Can't retrieve the system info: %s" % str(systems))
            return False

        pending_updates = False
        for (system_id, system_ip) in systems:
            (success, info) = apimethod_get_update_info(system_id)
            if success:
                try:
                    sys_pending_updates = info['pending_updates']
                    pending_updates = pending_updates or sys_pending_updates
                    logger.info("Pending Updates for system %s (%s): %s" % (system_id, system_ip, sys_pending_updates))
                    monitor_data = {"pending_updates": sys_pending_updates}
                    self.save_data(system_id, ComponentTypes.SYSTEM, self.get_json_message(monitor_data))
                except Exception as e:
                    logger.error("[MonitorPendingUpdates] Error: %s" % str(e))
                    rt = False
                    break
            else:
                logger.error("MonitorPendingUpdates: %s" % info)
                rt = False
                break

        if pending_updates:
            success, local_ip = get_system_ip_from_local()
            if not success:
                logger.error("[MonitorPendingUpdates] Unable to get local IP: %s" % local_ip)
                return False

            success, is_pro = get_is_professional(local_ip)
            if success and is_pro:
                success, is_trial = system_is_trial('local')
                if success and is_trial:
                    logger.info("[MonitorPendingUpdates] Trial version. Skipping download of release info file")
                    return rt

            success, msg = ansible_download_release_info(local_ip)
            if not success:
                logger.error("[MonitorPendingUpdates] Unable to retrieve release info file: %s" % msg)
                return False

        return rt
Beispiel #3
0
def apimethod_get_pending_packges(system_id, no_cache=False):
    """Retrieves the available updates for the given system_id
       and the release_info file
    Args:
      system_id(str): The system id of which we want to know
                      if it has available updates
    Returns:
      (success,data): success=True when the operation when ok,
                      otherwise success=False.
                      On success data will contain a json object
                      with the updates information.
    """
    success, data = apimethod_get_update_info(system_id, no_cache=no_cache)
    if not success:
        return success, data

    available_updates = data['available_updates']

    if available_updates:

        # Check for release info file
        success, local_ip = get_system_ip_from_local()
        if not success:
            error_msg = "[apimethod_get_pending_packges] " + \
                        "Unable to get local IP: %s" % local_ip
            api_log.error(error_msg)
            return False, available_updates

        success, is_pro = get_is_professional(local_ip)
        if success and is_pro:
            success, is_trial = system_is_trial(system_id='local')
            if success and is_trial:
                info_msg = "[apimethod_get_pending_packges] " + \
                           "Trial version. Skipping download release info file"
                api_log.info(info_msg)
                return True, available_updates

        success, msg = ansible_download_release_info(local_ip)
        if not success:
            error_msg = "[apimethod_get_pending_packges] " + \
                        "Unable to retrieve release info file: %s" % msg
            api_log.error(error_msg)

    return True, available_updates
Beispiel #4
0
def apimethod_get_pending_packges(system_id, no_cache=False):
    """Retrieves the available updates for the given system_id
       and the release_info file
    Args:
      system_id(str): The system id of which we want to know
                      if it has available updates
    Returns:
      (success,data): success=True when the operation when ok,
                      otherwise success=False.
                      On success data will contain a json object
                      with the updates information.
    """
    success, data = apimethod_get_update_info(system_id, no_cache=no_cache)
    if not success:
        return success, data

    available_updates = data['available_updates']

    if available_updates:

        # Check for release info file
        success, local_ip = get_system_ip_from_local()
        if not success:
            error_msg = "[apimethod_get_pending_packges] " + \
                        "Unable to get local IP: %s" % local_ip
            api_log.error(error_msg)
            return False, available_updates

        success, is_pro = get_is_professional(local_ip)
        if success and is_pro:
            success, is_trial = system_is_trial(system_id='local')
            if success and is_trial:
                info_msg = "[apimethod_get_pending_packges] " + \
                           "Trial version. Skipping download release info file"
                api_log.info(info_msg)
                return True, available_updates

        success, msg = ansible_download_release_info(local_ip)
        if not success:
            error_msg = "[apimethod_get_pending_packges] " + \
                        "Unable to retrieve release info file: %s" % msg
            api_log.error(error_msg)

    return True, available_updates