예제 #1
0
    def verify_updates(self):
        """ Mark any update records as outdated in case user updated manually.
        """
        try:
            cur_build_num = int(get_build_number())

            updates = self.db.query(Update).filter(Update.state == 'READY')
            for update in updates:
                if cur_build_num >= int(update.latest_build):
                    LOGGER.debug('Marking build={0} as OUTDATED; cur_build={1}'.format(
                        update.latest_build, cur_build_num))
                    update.state = 'OUTDATED'

            transaction.commit()

        except Exception as e:
            LOGGER.exception(e)
예제 #2
0
def get_global_settings(request):
    # JSON feed that is responsible for the local_chassis
    # network information in the administration area.

    do_reload = request.params.get('reload', 0)

    # Try cache first
    #if not do_reload and 'global_settings' in request.session:
    #    return request.session['global_settings']

    items = {}

    # Get some utils for getting the global settings back to the UI
    global_start = time.time()
    ixiacrlogger.debug('Start: get_global_settings')
    try:
        (result, obj, err) = admin_helper('get-network-config', {})
        network_config = obj

        items.update({'host': network_config['address'],
                      'netmask': network_config['netmask'],
                      'gateway': network_config['gateway'],
                      'hostname': network_config['hostname'],
                      'mac_address': ''})
        build_number = get_build_number()
        items.update(dict({'build_number': build_number or "Unknown"}))

        # Check for updates
        #updater = Updater(db)
        #available_updates, newest_build = updater.get_update_info()
        items['updates'] = {'available_updates': 'true', 'newest_build': '1.00.0002'}

        stop = time.time()

        ixiacrlogger.debug('End: get_global_settings completed at %.3f seconds' %
                         float(stop - global_start))

        request.session['global_settings'] = items
        return items

    except Exception, e:
        ixiacrlogger.exception('Exception: get_global_settings -- ' + format(e))
        return {"result": "FAILURE", "messages": [{"is_error": True,
                                                   "header": "Failed",
                                                   "content": "FAILED: {0}"
                                                   .format(e)}]}
예제 #3
0
    def check_updates(self, force_offline_check=False):
        offline = False

        if not force_offline_check:
            LOGGER.info('Checking network for updates...')
            (result, obj, err) = admin_helper('list-updates', {'offline': 0})
            if result == 'FAILURE':
                LOGGER.error('Network updated failed. err={0}'.format(err))
                return
        else:
            LOGGER.info('Checking offline for updates...')
            (result, obj, err) = admin_helper('list-updates', {'offline': 1})

            if result == 'FAILURE':
                LOGGER.error('Offline update failed. err={0}'.format(err))
                return
            else:
                offline = True

        packages = obj.get('packages', None)
        available = len(packages)

        if available > 0:
            latest = max([int(v[1].split('-')[1]) for v in packages])

            # Load from database most recent version
            # Is that version same as 'latest'
            #    YES-> do nothing
            #     NO-> update database and proceed with download

            cur_build = get_build_number()

            # If we have updates, we must call download_updates()
            LOGGER.info('Updates are available: current_build: {0} newest_build: {1}'.format(cur_build, latest))

            # Mark any 'unapplied' updates as outdated
            # This leaves applied updates in the history
            updates = self.db.query(Update).order_by(Update.id.desc()).all()
            for pos, update in enumerate(updates):
                if update.state in ['AVAILABLE', 'DOWNLOADING', 'READY']:
                    LOGGER.debug('Marking update state=OUTDATED; id={0}; latest_build={1}; prev_state={2}'.format(
                        update.id, update.latest_build, update.state))
                    update.state = 'OUTDATED'

                if pos >= MAX_UPDATE_HISTORY:
                    LOGGER.debug('Removing old update record; id={0}'.format(update.id))
                    self.db.delete(update)

            # Look for an update matching the current found update build or create it
            terms = [Update.latest_build == str(latest)]
            cur_update = self.db.query(Update).filter(and_(*terms)).first()
            if not cur_update:
                cur_update = Update()
                cur_update.latest_build = latest
                self.db.add(cur_update)

            # Update status to downloading, since we called list-updates
            cur_update.offline = offline
            cur_update.available_updates = available
            cur_update.details = json.dumps({'packages': packages})
            if not cur_update.offline:
                cur_update.state = 'DOWNLOADING'
                cur_update.download_started = datetime.now()
                cur_update.download_finished = None

                self.db.flush()

                self.download_updates()

                self.db.add(cur_update)
                cur_update.download_finished = datetime.now()

                duration = (cur_update.download_finished - cur_update.download_started).seconds
                LOGGER.info('Download completed; secs={0}'.format(duration))

            # Updates are now ready to be applied by admin
            cur_update.state = 'READY'
            transaction.commit()

        else:
            LOGGER.info('Updates are not available')