def _get_domain_ips_and_macs( domain: libvirt.virDomain) -> Tuple[List[str], List[str]]: interfaces_sources = [ # getting all DHCP leases IPs libvirt.VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE, # getting static IPs via ARP libvirt.VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP, ] interfaces = {} for addresses_source in interfaces_sources: try: interfaces.update( **domain.interfaceAddresses(addresses_source)) except libvirt.libvirtError: log.exception( "Got an error while updating domain's network addresses") ips = [] macs = [] log.debug(f"Host {domain.name()} interfaces are {interfaces}") if interfaces: for (_, val) in interfaces.items(): if val["addrs"]: for addr in val["addrs"]: ips.append(addr["addr"]) macs.append(val["hwaddr"]) if ips: log.info("Host %s ips are %s", domain.name(), ips) if macs: log.info("Host %s macs are %s", domain.name(), macs) return ips, macs
def myDomainEventAgentLifecycleCallback(conn: libvirt.virConnect, dom: libvirt.virDomain, state: int, reason: int, opaque: _T) -> None: print("myDomainEventAgentLifecycleCallback: Domain %s(%s) %s %s" % ( dom.name(), dom.ID(), AGENT_STATES[state], AGENT_REASONS[reason]))
def myDomainEventBlockJob2Callback(conn: libvirt.virConnect, dom: libvirt.virDomain, disk: str, type: int, status: int, opaque: _T) -> None: print("myDomainEventBlockJob2Callback: Domain %s(%s) %s on disk %s %s" % ( dom.name(), dom.ID(), BLOCK_JOB_TYPES[type], disk, BLOCK_JOB_STATUS[status]))
def myDomainEventPMSuspendDiskCallback(conn: libvirt.virConnect, dom: libvirt.virDomain, reason: int, opaque: _T) -> None: print("myDomainEventPMSuspendDiskCallback: Domain %s(%s) system pmsuspend_disk" % ( dom.name(), dom.ID()))
def __init__(self, libvirt_domain: libvirt.virDomain): self.libvirt_domain = libvirt_domain self.name = libvirt_domain.name() self.libvirt_snapshot = None
def myDomainEventMemoryFailureCallback(conn: libvirt.virConnect, dom: libvirt.virDomain, recipient: int, action: int, flags: int, opaque: _T) -> None: print("myDomainEventMemoryFailureCallback: Domain %s(%s) memory failure recipient %d action %d flags %d" % ( dom.name(), dom.ID(), recipient, action, flags))
def myDomainEventMetadataChangeCallback(conn: libvirt.virConnect, dom: libvirt.virDomain, mtype: int, nsuri: str, opaque: _T) -> None: print("myDomainEventMetadataChangeCallback: Domain %s(%s) changed metadata mtype=%d nsuri=%s" % ( dom.name(), dom.ID(), mtype, nsuri))
def myDomainEventJobCompletedCallback(conn: libvirt.virConnect, dom: libvirt.virDomain, params: Dict[str, Any], opaque: _T) -> None: print("myDomainEventJobCompletedCallback: Domain %s(%s) %s" % ( dom.name(), dom.ID(), params))
def myDomainEventControlErrorCallback(conn: libvirt.virConnect, dom: libvirt.virDomain, opaque: _T) -> None: print("myDomainEventControlErrorCallback: Domain %s(%s)" % ( dom.name(), dom.ID()))
def myDomainEventGraphicsCallback(conn: libvirt.virConnect, dom: libvirt.virDomain, phase: int, localAddr: str, remoteAddr: str, authScheme: str, subject: str, opaque: _T) -> None: print("myDomainEventGraphicsCallback: Domain %s(%s) %s %s" % ( dom.name(), dom.ID(), GRAPHICS_PHASES[phase], authScheme))
def myDomainEventIOErrorReasonCallback(conn: libvirt.virConnect, dom: libvirt.virDomain, srcpath: str, devalias: str, action: int, reason: int, opaque: _T) -> None: print("myDomainEventIOErrorReasonCallback: Domain %s(%s) %s %s %s %s" % ( dom.name(), dom.ID(), srcpath, devalias, ERROR_EVENTS[action], reason))
def myDomainEventWatchdogCallback(conn: libvirt.virConnect, dom: libvirt.virDomain, action: int, opaque: _T) -> None: print("myDomainEventWatchdogCallback: Domain %s(%s) %s" % ( dom.name(), dom.ID(), WATCHDOG_ACTIONS[action]))
def myDomainEventRTCChangeCallback(conn: libvirt.virConnect, dom: libvirt.virDomain, utcoffset: int, opaque: _T) -> None: print("myDomainEventRTCChangeCallback: Domain %s(%s) %d" % ( dom.name(), dom.ID(), utcoffset))
def myDomainEventCallback(conn: libvirt.virConnect, dom: libvirt.virDomain, event: int, detail: int, opaque: _T) -> None: print("myDomainEventCallback%s EVENT: Domain %s(%s) %s %s" % ( opaque, dom.name(), dom.ID(), DOM_EVENTS[event], DOM_EVENTS[event][detail]))
def myDomainEventDeviceAddedCallback(conn: libvirt.virConnect, dom: libvirt.virDomain, dev: str, opaque: _T) -> None: print("myDomainEventDeviceAddedCallback: Domain %s(%s) device added: %s" % ( dom.name(), dom.ID(), dev))
def myDomainEventMigrationIteration(conn: libvirt.virConnect, dom: libvirt.virDomain, iteration: int, opaque: _T) -> None: print("myDomainEventMigrationIteration: Domain %s(%s) started migration iteration %d" % ( dom.name(), dom.ID(), iteration))
def myDomainEventDiskChangeCallback(conn: libvirt.virConnect, dom: libvirt.virDomain, oldSrcPath: str, newSrcPath: str, devAlias: str, reason: int, opaque: _T) -> None: print("myDomainEventDiskChangeCallback: Domain %s(%s) disk change oldSrcPath: %s newSrcPath: %s devAlias: %s reason: %s" % ( dom.name(), dom.ID(), oldSrcPath, newSrcPath, devAlias, DISK_EVENTS[reason]))
def myDomainEventDeviceRemovalFailedCallback(conn: libvirt.virConnect, dom: libvirt.virDomain, dev: str, opaque: _T) -> None: print("myDomainEventDeviceRemovalFailedCallback: Domain %s(%s) failed to remove device: %s" % ( dom.name(), dom.ID(), dev))
def myDomainEventTrayChangeCallback(conn: libvirt.virConnect, dom: libvirt.virDomain, devAlias: str, reason: int, opaque: _T) -> None: print("myDomainEventTrayChangeCallback: Domain %s(%s) tray change devAlias: %s reason: %s" % ( dom.name(), dom.ID(), devAlias, TRAY_EVENTS[reason]))
def myDomainEventBlockThresholdCallback(conn: libvirt.virConnect, dom: libvirt.virDomain, dev: str, path: str, threshold: int, excess: int, opaque: _T) -> None: print("myDomainEventBlockThresholdCallback: Domain %s(%s) block device %s(%s) threshold %d exceeded by %d" % ( dom.name(), dom.ID(), dev, path, threshold, excess))
def myDomainEventPMWakeupCallback(conn: libvirt.virConnect, dom: libvirt.virDomain, reason: int, opaque: _T) -> None: print("myDomainEventPMWakeupCallback: Domain %s(%s) system pmwakeup" % ( dom.name(), dom.ID()))
def myDomainEventBalloonChangeCallback(conn: libvirt.virConnect, dom: libvirt.virDomain, actual: int, opaque: _T) -> None: print("myDomainEventBalloonChangeCallback: Domain %s(%s) %d" % ( dom.name(), dom.ID(), actual))