Exemplo n.º 1
0
def _audit_nfvi_hypervisors_callback(timer_id):
    """
    Audit Hypervisors
    """
    global _main_audit_inprogress
    global _nfvi_hypervisors_to_audit

    response = (yield)
    DLOG.verbose("Audit-Hypervisors callback, response=%s." % response)

    trigger_recovery = False
    if response['completed']:
        hypervisor_table = tables.tables_get_hypervisor_table()
        deletable_hypervisors = list(hypervisor_table)

        for nfvi_hypervisor in response['result-data']:
            hypervisor = hypervisor_table.get(nfvi_hypervisor.uuid, None)
            if hypervisor is None:
                hypervisor = objects.Hypervisor(nfvi_hypervisor)
                hypervisor_table[nfvi_hypervisor.uuid] = hypervisor
                trigger_recovery = True
            else:
                deletable_hypervisors.remove(nfvi_hypervisor.uuid)

            if nfvi_hypervisor.uuid not in _nfvi_hypervisors_to_audit:
                _nfvi_hypervisors_to_audit[nfvi_hypervisor.uuid] \
                    = nfvi_hypervisor.uuid

            prev_state = hypervisor.oper_state
            hypervisor.nfvi_hypervisor_update(nfvi_hypervisor)

            if (hypervisor.oper_state != prev_state
                    and nfvi.objects.v1.HYPERVISOR_OPER_STATE.ENABLED
                    == hypervisor.oper_state):
                trigger_recovery = True

        for hypervisor_id in deletable_hypervisors:
            del hypervisor_table[hypervisor_id]
            if hypervisor_id in _nfvi_hypervisors_to_audit:
                del _nfvi_hypervisors_to_audit[hypervisor_id]

    else:
        DLOG.error("Audit-Hypervisors callback, not completed, responses=%s." %
                   response)

    _main_audit_inprogress = False
    timers.timers_reschedule_timer(timer_id, 2)  # 2 seconds later

    if trigger_recovery:
        # Hypervisor is now available, there is potential to recover instances.
        DLOG.info("Recover-Instances-Audit triggered by hypervisor audit.")
        instance_director = directors.get_instance_director()
        instance_director.recover_instances()
Exemplo n.º 2
0
def _audit_nfvi_hypervisor_callback():
    """
    Audit Hypervisor
    """
    response = (yield)
    DLOG.verbose("Audit-Hypervisor callback, response=%s." % response)

    if response['completed']:
        nfvi_hypervisor = response['result-data']
        hypervisor_table = tables.tables_get_hypervisor_table()
        hypervisor = hypervisor_table.get(nfvi_hypervisor.uuid, None)
        if hypervisor is None:
            hypervisor = objects.Hypervisor(nfvi_hypervisor)
            hypervisor_table[hypervisor.uuid] = hypervisor
        hypervisor.nfvi_hypervisor_update(nfvi_hypervisor)

    else:
        DLOG.error("Audit-Hypervisor callback, not completed, response=%s." %
                   response)
Exemplo n.º 3
0
def database_hypervisor_get_list():
    """
    Fetch all the hypervisor objects from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.Hypervisor)

    hypervisor_objs = list()
    for hypervisor in query.all():
        nfvi_hypervisor_data = json.loads(hypervisor.nfvi_hypervisor_data)
        nfvi_hypervisor = nfvi.objects.v1.Hypervisor(
            nfvi_hypervisor_data['uuid'], nfvi_hypervisor_data['admin_state'],
            nfvi_hypervisor_data['oper_state'],
            nfvi_hypervisor_data['host_name'])

        vcpus_used = nfvi_hypervisor_data.get('vcpus_used', None)
        if vcpus_used is not None:
            nfvi_hypervisor.update_stats(nfvi_hypervisor_data['vcpus_used'],
                                         nfvi_hypervisor_data['vcpus_max'],
                                         nfvi_hypervisor_data['mem_used_mb'],
                                         nfvi_hypervisor_data['mem_free_mb'],
                                         nfvi_hypervisor_data['mem_max_mb'],
                                         nfvi_hypervisor_data['disk_used_gb'],
                                         nfvi_hypervisor_data['disk_max_gb'],
                                         nfvi_hypervisor_data['running_vms'])

        hypervisor_obj = objects.Hypervisor(nfvi_hypervisor)
        hypervisor_obj.vcpus_used = hypervisor.vcpus_used
        hypervisor_obj.vcpus_max = hypervisor.vcpus_max
        hypervisor_obj.mem_used_mb = hypervisor.mem_used_mb
        hypervisor_obj.mem_free_mb = hypervisor.mem_free_mb
        hypervisor_obj.mem_max_mb = hypervisor.mem_max_mb
        hypervisor_obj.disk_used_gb = hypervisor.disk_used_gb
        hypervisor_obj.disk_max_gb = hypervisor.disk_max_gb
        hypervisor_obj.running_instances = hypervisor.running_instances
        hypervisor_objs.append(hypervisor_obj)
    return hypervisor_objs