Esempio n. 1
0
class KickstartLogNotifyHandler(BatchNotifyHandler):
    def __init__(self, ks_session_id):
        self.__ks_session_id = ks_session_id
        self.__plan = None

    def batch_began(self):
        self.__plan = Plan()

    def log_message_discovered(self, log_message):
        self.__plan.add(
            EventType.EXISTS, TargetType.LOG_MSG, {
                PropertyType.ID: self.__ks_session_id,
                PropertyType.MESSAGE: log_message
            })

    def batch_ended(self):
        self.__plan.execute()
Esempio n. 2
0
class KickstartLogNotifyHandler(BatchNotifyHandler):
    def __init__(self, ks_session_id):
        self.__ks_session_id = ks_session_id
        self.__plan = None

    def batch_began(self):
        self.__plan = Plan()

    def log_message_discovered(self, log_message):
        self.__plan.add(
            EventType.EXISTS,
            TargetType.LOG_MSG,
            {PropertyType.ID: self.__ks_session_id, PropertyType.MESSAGE: log_message},
        )

    def batch_ended(self):
        self.__plan.execute()
Esempio n. 3
0
def refresh(fail_on_error=False):
    """
    Refreshes the virtualization info for this host and any subdomains on the
    server.
    """
    if _is_host_domain(fail_on_error):
        domain_identity = IdentityType.HOST
        my_uuid = _fetch_host_uuid()
    else:
        # Not a host.  No-op.
        return

    # Now that we've gathered some preliminary information, create a plan of
    # actions that we will eventually pass to the server.
    plan = Plan()

    # First, declare our own existence.
    plan.add(EventType.EXISTS, TargetType.SYSTEM, {
        PropertyType.IDENTITY: domain_identity,
        PropertyType.UUID: my_uuid
    })

    # Now, crawl each of the domains on this host.
    if vdsm_enabled:
        server = localvdsm.connect()
        domains = poller.poll_through_vdsm(server)
    else:
        domains = poller.poll_hypervisor()

        if not len(domains) and libvirt.openReadOnly(None).getType() == 'Xen':
            # On a KVM/QEMU host, libvirt reports no domain entry for host itself
            # On a Xen host, either there were no domains or xend might not be
            # running. Don't proceed further.
            return
    domain_list = domains.values()
    domain_uuids = domains.keys()

    if not vdsm_enabled:
        # We need this only for libvirt
        domain_dir = DomainDirectory()
        domain_dir.save_unknown_domain_configs(domain_uuids)

    plan.add(EventType.CRAWL_BEGAN, TargetType.SYSTEM)
    for domain_properties in domain_list:
        plan.add(EventType.EXISTS, TargetType.DOMAIN, domain_properties)
    plan.add(EventType.CRAWL_ENDED, TargetType.SYSTEM)

    # Finally, execute the actions queued up in the plan.
    plan.execute()
Esempio n. 4
0
 def batch_began(self):
     self.__plan = Plan()
Esempio n. 5
0
def refresh(fail_on_error=False):
    """
    Refreshes the virtualization info for this host and any subdomains on the
    server.
    """
    if _is_host_domain(fail_on_error):
        domain_identity = IdentityType.HOST
        my_uuid = _fetch_host_uuid()
    else:
        # Not a host.  No-op.
        return

    # Now that we've gathered some preliminary information, create a plan of
    # actions that we will eventually pass to the server.
    plan = Plan()

    # First, declare our own existence.
    plan.add(
        EventType.EXISTS,
        TargetType.SYSTEM,
        { PropertyType.IDENTITY : domain_identity,
          PropertyType.UUID     : my_uuid          })

    # Now, crawl each of the domains on this host.
    if vdsm_enabled:
        server = localvdsm.connect()
        domains = poller.poll_through_vdsm(server)
    else:
        domains = poller.poll_hypervisor()

        if not len(domains) and libvirt.openReadOnly(None).getType() == 'Xen':
           # On a KVM/QEMU host, libvirt reports no domain entry for host itself
           # On a Xen host, either there were no domains or xend might not be
           # running. Don't proceed further.
           return
    domain_list = list(domains.values())
    domain_uuids = list(domains.keys())

    if not vdsm_enabled:
        # We need this only for libvirt
        domain_dir = DomainDirectory()
        domain_dir.save_unknown_domain_configs(domain_uuids)

    plan.add(EventType.CRAWL_BEGAN, TargetType.SYSTEM)
    for domain_properties in domain_list:
        plan.add(EventType.EXISTS, TargetType.DOMAIN, domain_properties)
    plan.add(EventType.CRAWL_ENDED, TargetType.SYSTEM)

    # Finally, execute the actions queued up in the plan.
    plan.execute()
Esempio n. 6
0
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
    about every 1.5 hours).  This will cause the full state to be re-uploaded
    and put things back in sync, if necessary.
    """
    # Now, if anything changed, send the appropriate notification for it.
    if poller_state.is_changed():
        added    = poller_state.get_added()
        removed  = poller_state.get_removed()
        modified = poller_state.get_modified()

        plan = Plan()

        # Declare virtualization host first
        plan.add(EventType.EXISTS,
                 TargetType.SYSTEM,
                 { PropertyType.IDENTITY : IdentityType.HOST,
                   PropertyType.UUID     : '0000000000000000' })

        for (uuid, data) in added.items():
            plan.add(EventType.EXISTS, TargetType.DOMAIN, data)

        for (uuid, data) in modified.items():
            plan.add(EventType.EXISTS, TargetType.DOMAIN, data)

        for (uuid, data) in removed.items():
            plan.add(EventType.REMOVED, TargetType.DOMAIN, data)

        plan.execute()
Esempio n. 7
0
 def batch_began(self):
     self.__plan = Plan()