def init_state(config):
    """ Initialize a dict for storing the state of the data collector.

    :param config: A config dictionary.
     :type config: dict(str: *)

    :return: A dict containing the initial state of the data collector.
     :rtype: dict
    """
    vir_connection = libvirt.openReadOnly(None)
    if vir_connection is None:
        message = 'Failed to open a connection to the hypervisor'
        log.critical(message)
        raise OSError(message)

    hostname = vir_connection.getHostname()
    host_cpu_mhz, host_ram = get_host_characteristics(vir_connection)
    physical_cpus = common.physical_cpu_count(vir_connection)
    host_cpu_usable_by_vms = float(config['host_cpu_usable_by_vms'])

    db = init_db(config['sql_connection'])
    db.update_host(hostname,
                   int(host_cpu_mhz * host_cpu_usable_by_vms),
                   physical_cpus,
                   host_ram)

    return {'previous_time': 0.,
            'previous_cpu_time': dict(),
            'previous_cpu_mhz': dict(),
            'previous_host_cpu_time_total': 0.,
            'previous_host_cpu_time_busy': 0.,
            'previous_overload': -1,
            'vir_connection': vir_connection,
            'hostname': hostname,
            'host_cpu_overload_threshold':
                float(config['host_cpu_overload_threshold']) * \
                host_cpu_usable_by_vms,
            'physical_cpus': physical_cpus,
            'physical_cpu_mhz': host_cpu_mhz,
            'physical_core_mhz': host_cpu_mhz / physical_cpus,
            'db': db}
Example #2
0
def init_state(config):
    """ Initialize a dict for storing the state of the data collector.

    :param config: A config dictionary.
     :type config: dict(str: *)

    :return: A dict containing the initial state of the data collector.
     :rtype: dict
    """
    vir_connection = libvirt.openReadOnly(None)
    if vir_connection is None:
        message = 'Failed to open a connection to the hypervisor'
        log.critical(message)
        raise OSError(message)

    hostname = vir_connection.getHostname()
    host_cpu_mhz, host_ram = get_host_characteristics(vir_connection)
    physical_cpus = common.physical_cpu_count(vir_connection)
    host_cpu_usable_by_vms = float(config['host_cpu_usable_by_vms'])

    db = init_db(config['sql_connection'])
    db.update_host(hostname,
                   int(host_cpu_mhz * host_cpu_usable_by_vms),
                   physical_cpus,
                   host_ram)

    return {'previous_time': 0.,
            'previous_cpu_time': dict(),
            'previous_cpu_mhz': dict(),
            'previous_host_cpu_time_total': 0.,
            'previous_host_cpu_time_busy': 0.,
            'previous_overload': -1,
            'vir_connection': vir_connection,
            'hostname': hostname,
            'host_cpu_overload_threshold':
                float(config['host_cpu_overload_threshold']) * \
                host_cpu_usable_by_vms,
            'physical_cpus': physical_cpus,
            'physical_cpu_mhz': host_cpu_mhz,
            'physical_core_mhz': host_cpu_mhz / physical_cpus,
            'db': db}
Example #3
0
def init_state(config):
    """ Initialize a dict for storing the state of the data collector.

    :param config: A config dictionary.
     :type config: dict(str: *)

    :return: A dict containing the initial state of the data collector.
     :rtype: dict
    """
    vir_connection = libvirt.openReadOnly(None)
    if vir_connection is None:
        message = "Failed to open a connection to the hypervisor"
        log.critical(message)
        raise OSError(message)

    hostname = vir_connection.getHostname()
    host_cpu_mhz, host_ram = get_host_characteristics(vir_connection)
    physical_cpus = common.physical_cpu_count(vir_connection)
    host_cpu_usable_by_vms = float(config["host_cpu_usable_by_vms"])

    db = init_db(config["sql_connection"])
    db.update_host(hostname, int(host_cpu_mhz * host_cpu_usable_by_vms), physical_cpus, host_ram)

    return {
        "previous_time": 0.0,
        "previous_cpu_time": dict(),
        "previous_cpu_mhz": dict(),
        "previous_host_cpu_time_total": 0.0,
        "previous_host_cpu_time_busy": 0.0,
        "previous_overload": -1,
        "vir_connection": vir_connection,
        "hostname": hostname,
        "host_cpu_overload_threshold": float(config["host_cpu_overload_threshold"]) * host_cpu_usable_by_vms,
        "physical_cpus": physical_cpus,
        "physical_cpu_mhz": host_cpu_mhz,
        "physical_core_mhz": host_cpu_mhz / physical_cpus,
        "db": db,
    }
Example #4
0
 def physical_cpu_count(x=int_(min=0, max=8)):
     with MockTransaction:
         connection = libvirt.virConnect()
         expect(connection).getInfo().and_return([0, 0, x]).once()
         assert common.physical_cpu_count(connection) == x
 def physical_cpu_count(x=int_(min=0, max=8)):
     with MockTransaction:
         connection = libvirt.virConnect()
         expect(connection).getInfo().and_return([0, 0, x]).once()
         assert common.physical_cpu_count(connection) == x