Bin gerade unterwegs und würde gerne heute Abend wenn ich wieder Zuhause bin mich mit diesem Script hier weiter beschäftigen.
Derzeit wird anhand der MAC Adresse des jeweiligen KVM guest-Systems die IP-Adresse durch die arp-Tabelle rausgefiltert!
Zumindest sollte das so sein!
Code:
Code: Alles auswählen
try:
	from lxml import etree
	
except ImportError:	
	import xml.etree.cElementTree as etree
import libvirt
import argparse
import sys,subprocess,os
import StringIO
debug = False
argument = argparse.ArgumentParser(description='Get ip from KVM Guest.')
parser.add_argument('--hypervisor', '-hv',
                    action='store',
                    help='Sourcepath -hv or --hypervisor')
					
parser = etree.XMLParser()
conn = libvirt.openReadOnly(args.hypervisor)
if conn == None:
    print 'Failed to open connection to the hypervisor'
    sys.exit(1)
domain=conn.lookupByName(args.hypervisor)
desc = etree.fromstring(domain.XMLDesc(0))
macAddr = desc.find("devices/interface[@type='network']/mac").attrib["address"].lower().strip()
if debug:
    print >>sys.stderr,"XMLDesc = %s" % macAddr
output = subprocess.Popen(["arp", "-n"], stdout=subprocess.PIPE).communicate()[0]
lines = [line.split() for line in output.split("\n")[1:]]
if debug:
	print lines
IPaddr = [line[0] for line in lines if (line and (line[2] == macAddr))]
if IPaddr:
	print IPaddr[0]Würde das so in der Art funkten?
LG

