diff options
author | Bill Peck <bpeck@redhat.com> | 2014-06-18 10:58:23 -0400 |
---|---|---|
committer | Bill Peck <bpeck@redhat.com> | 2014-06-18 10:58:23 -0400 |
commit | b81acc58e24227379093000edd61818029441686 (patch) | |
tree | d339f267c74bc86bfedb93a83d20f4fb9506baec /distribution/virt/import/lxml_guestname_resolution.py | |
parent | cb96f1c472f0bcfcddf38c108c24d385a59d2328 (diff) | |
download | tests-b81acc58e24227379093000edd61818029441686.tar.gz tests-b81acc58e24227379093000edd61818029441686.tar.xz tests-b81acc58e24227379093000edd61818029441686.zip |
new /virt/import test which will use pre-existing images
Diffstat (limited to 'distribution/virt/import/lxml_guestname_resolution.py')
-rwxr-xr-x | distribution/virt/import/lxml_guestname_resolution.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/distribution/virt/import/lxml_guestname_resolution.py b/distribution/virt/import/lxml_guestname_resolution.py new file mode 100755 index 0000000..551a238 --- /dev/null +++ b/distribution/virt/import/lxml_guestname_resolution.py @@ -0,0 +1,54 @@ +#!/usr/bin/python +# +# this script is used to update the /etc/hosts file in the host/dom0 so that the +# guestname will be resolved to the guest's IP address. +# + +import sys +import os +import time +import xmlrpclib +from lxml import etree +from cStringIO import StringIO +from optparse import OptionParser +import socket + +#start here +usage = "usage: %prog --recipeid " +parser = OptionParser() +parser.add_option("-r", "--recipeid", dest="recipeid", help="recipe id of the guest to hostname of.") +(options, args) = parser.parse_args() +recipeid = options.recipeid + +xml_tries = 1 +interval = 300 +proxy = xmlrpclib.ServerProxy('http://%s:8000/RPC2' % os.environ['LAB_CONTROLLER']) +while xml_tries < 5: + try: + recipe_xml = proxy.get_my_recipe(dict(recipe_id=recipeid)) + break + except: + print "Couldn't get guestinfo from %s . sleeping %i secs" % (os.environ['LAB_CONTROLLER'] , interval) + time.sleep(interval) + xml_tries += 1 + +if xml_tries == 5: + print "Can't get guestinfo from %s" % os.environ['LAB_CONTROLLER'] + sys.exit(1) + +thetree = etree.parse(StringIO(recipe_xml)) +for node in thetree.xpath('/job/recipeSet/recipe/guestrecipe'): + print "in node" + if node.attrib['id'] == recipeid: + guestname = node.attrib['guestname'] + guesthost = node.attrib['system'] + guestip = socket.gethostbyname(guesthost) + print "guestname: " + guestname + " guesthost: " + guesthost + " ip: " + guestip + # update /etc/hosts with this info + fh = open('/etc/hosts', 'a') + fh.write(guestip+" "+guestname+"\n") + fh.close() + +sys.exit(0) + + |