Exemple #1
0
def poll_state(uuid):
    """
    Polls just the state of the guest with the provided UUID.  This state is
    returned.
    """
    conn = libvirt.openReadOnly(None)
    if not conn:
        raise VirtualizationException("Failed to open connection to hypervisor.")

    # Attempt to connect to the domain.  Since there is technically no
    # "stopped" state, we will assume that if we cannot connect the domain is
    # not running.  Unfortunately, we can't really determine if the domain
    # actually exists.
    domain = None
    try:
        domain = conn.lookupByUUIDString(hyphenize_uuid(uuid))
    except libvirt.libvirtError:
        # Can't find domain.  Return stopped state.
        return State(None)

    # Now that we have the domain, lookup the state.
    domain_info = domain.info()
    return State(VIRT_STATE_NAME_MAP[domain_info[0]])
Exemple #2
0
              "Failed to open connection to hypervisor."

    # Attempt to connect to the domain.  Since there is technically no
    # "stopped" state, we will assume that if we cannot connect the domain is
    # not running.  Unfortunately, we can't really determine if the domain
    # actually exists.
    domain = None
    try:
        domain = conn.lookupByUUIDString(hyphenize_uuid(uuid))
    except libvirt.libvirtError, lve:
        # Can't find domain.  Return stopped state.
        return State(None)

    # Now that we have the domain, lookup the state.
    domain_info = domain.info()
    return State(VIRT_STATE_NAME_MAP[domain_info[0]])


###############################################################################
# Helper Functions
###############################################################################


def _send_notifications(poller_state):
    """
    This function will send notifications based on vm state change to the
    server.  To reduce the possibility of spamming the server but still
    maintain an element of consistency, it will compare the previous poll state
    against the current poll state and only send notifications if something has
    changed.  In the event that the cache might have gotten into an
    inconsistent state, the cache will be removed after every 50 polls (this is