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

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

    :return: A dictionary containing the initial state of the local manager.
     :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)

    physical_cpu_mhz_total = int(
        common.physical_cpu_mhz_total(vir_connection) *
        float(config['host_cpu_usable_by_vms']))
    return {'previous_time': 0.,
            'vir_connection': vir_connection,
            'db': init_db(config['sql_connection']),
            'physical_cpu_mhz_total': physical_cpu_mhz_total,
            'hostname': vir_connection.getHostname(),
            'hashed_username': sha1(config['os_admin_user']).hexdigest(),
            'hashed_password': sha1(config['os_admin_password']).hexdigest()}
Exemple #2
0
def init_state(config):
    """ Initialize a dict for storing the state of the local manager.

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

    :return: A dictionary containing the initial state of the local manager.
     :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)

    physical_cpu_mhz_total = int(
        common.physical_cpu_mhz_total(vir_connection) *
        float(config['host_cpu_usable_by_vms']))
    return {'previous_time': 0.,
            'vir_connection': vir_connection,
            'db': init_db(config['sql_connection']),
            'physical_cpu_mhz_total': physical_cpu_mhz_total,
            'hostname': vir_connection.getHostname(),
            'hashed_username': sha1(config['os_admin_user']).hexdigest(),
            'hashed_password': sha1(config['os_admin_password']).hexdigest()}
Exemple #3
0
 def physical_cpu_mhz_total(x=int_(min=0, max=8), y=int_(min=0, max=8)):
     with MockTransaction:
         connection = libvirt.virConnect()
         expect(common).physical_cpu_count(connection). \
             and_return(x).once()
         expect(common).physical_cpu_mhz(connection). \
             and_return(y).once()
         assert common.physical_cpu_mhz_total(connection) == x * y
 def physical_cpu_mhz_total(x=int_(min=0, max=8), y=int_(min=0, max=8)):
     with MockTransaction:
         connection = libvirt.virConnect()
         expect(common).physical_cpu_count(connection). \
             and_return(x).once()
         expect(common).physical_cpu_mhz(connection). \
             and_return(y).once()
         assert common.physical_cpu_mhz_total(connection) == x * y