示例#1
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()
示例#2
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()
示例#3
0
    # First, handle the options.
    _parse_options()

    vdsm_enabled = False
    server = None
    try:
        from virtualization import localvdsm

        if sys.version_info[0] == 3:
            status, msg = subprocess.getstatusoutput("/etc/init.d/vdsmd status")
        else:
            import commands
            status, msg = commands.getstatusoutput("/etc/init.d/vdsmd status")

        if status == 0:
            server = localvdsm.connect()
            vdsm_enabled = True
    except ImportError:
        pass

    # Crawl each of the domains on this host and obtain the new state.
    if vdsm_enabled:
        domain_list = poll_through_vdsm(server)
    elif libvirt:
        # If libvirt is present but not running, this program is useless.
        # Libvirt currently writes to stderr if you attempt to connect
        # and the daemon is not running. The libvirt python bindings provide
        # no way to change this behavior. Anything written to stderr or stdout
        # will cause cron to email root with the output. It is not our
        # job to nag the user every two minutes if libvirt is not running.
        # The only way to avoid this is to shell out to check if libvirt