Пример #1
0
def reload(sig, stackframe):
    if executor:
        # Ignore signal SIGHUP during reloading executor
        # See bug: https://bugzilla.redhat.com/show_bug.cgi?id=1506167
        signal.signal(signal.SIGHUP, lambda _sig, _stack: None)
        executor.reload()
        signal.signal(signal.SIGHUP, reload)
        raise ReloadRequest()
    exit(1, status="virt-who cannot reload, exiting")
Пример #2
0
def _main(executor):
    result = None
    try:
        result = executor.run()
    except ManagerFatalError:
        executor.stop_virts()
        executor.logger.exception("Fatal error:")
        if not executor.options.oneshot:
            executor.logger.info("Waiting for reload signal")
            # Wait indefinitely until we get reload or exit signal
            while True:
                report = executor.queue.get(block=True)
                if report == 'reload':
                    raise ReloadRequest()
                elif report == 'exit':
                    return 0

    if executor.options.print_:
        if not result:
            executor.logger.error("No hypervisor reports found")
            return 1
        hypervisors = []
        for config, report in result.items():
            if isinstance(report, DomainListReport):
                hypervisors.append({
                    'guests': [guest.toDict() for guest in report.guests]
                })
            elif isinstance(report, HostGuestAssociationReport):
                for hypervisor in report.association['hypervisors']:
                    h = OrderedDict((
                        ('uuid', hypervisor.hypervisorId),
                        ('guests', [guest.toDict() for guest in hypervisor.guestIds])
                    ))
                    if hypervisor.facts:
                        h['facts'] = hypervisor.facts
                    if hypervisor.name:
                        h['name'] = hypervisor.name
                    hypervisors.append(h)
        data = json.dumps({
            'hypervisors': hypervisors
        })
        executor.logger.debug("Associations found: %s", json.dumps({
            'hypervisors': hypervisors
        }, indent=4, sort_keys=True))
        print(data)
    return 0
Пример #3
0
def reload(signal, stackframe):
    if executor:
        executor.reload()
        raise ReloadRequest()
    exit(1, status="virt-who cannot reload, exiting")