From e0eebfd5c5ba792c89ceedb5ecaf5804d645a63d Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Fri, 18 Jan 2008 09:21:58 +0000 Subject: [PATCH] support for round-robin allocation of vserver addresses - using ping to check for free slots --- system/TestMain.py | 2 ++ system/config_onelab.py | 2 +- system/config_onelab_vserver.py | 25 ++++++++++++++++--------- system/utils.py | 18 ++++++++++++++++++ 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/system/TestMain.py b/system/TestMain.py index 8a61956..c4be4c8 100755 --- a/system/TestMain.py +++ b/system/TestMain.py @@ -74,6 +74,8 @@ steps refer to a method in TestPlc or to a step_* module"""%(TestMain.default_bu if len(self.args) == 0: if self.options.all_steps: self.options.steps=TestMain.default_steps + elif self.options.dry_run: + self.options.steps=TestMain.default_steps else: print 'No step found (do you mean -a ? )' print "Run %s --help for help"%sys.argv[0] diff --git a/system/config_onelab.py b/system/config_onelab.py index db874f9..eca4b2e 100644 --- a/system/config_onelab.py +++ b/system/config_onelab.py @@ -177,7 +177,7 @@ def slices (): def plc () : return { - 'name' : 'onelab', + 'name' : 'onelabtest', # as of yet, not sure we can handle foreign hosts, but this is required though 'hostname' : 'localhost', # set these two items to run within a vserver diff --git a/system/config_onelab_vserver.py b/system/config_onelab_vserver.py index 700b320..d02f575 100644 --- a/system/config_onelab_vserver.py +++ b/system/config_onelab_vserver.py @@ -1,21 +1,28 @@ -available = [ ('vbuild1.inria.fr','138.96.250.131'), - ('vbuild2.inria.fr','138.96.250.132'), - ('vbuild3.inria.fr','138.96.250.133'), - ('vbuild4.inria.fr','138.96.250.134'), - ] +import utils + +available = [ ( i, 'vnode%02d.inria.fr'%i, '138.96.250.13%d'%i) for i in range(1,10) ] def config (plcs,options): available.reverse() for plc in plcs: - # get next slot -- xxx shoud check for running ones - (name,ip)=available.pop() - plc['vservername']=name + ### locating the next available hostname (using ping) + while True: + try: + (i,hostname,ip)=available.pop() + if not utils.check_ping(hostname): + break + except: + raise Exception('Cannot find an available IP for %s - exiting'%plc['name']) + plc['vservername']=hostname plc['vserverip']=ip + plc['name'] = "%s_%02d"%(plc['name'],i) + utils.header("Attaching plc %s to vserver %s (%s)"%\ + (plc['name'],plc['vservername'],plc['vserverip'])) for key in [ 'PLC_DB_HOST', 'PLC_API_HOST', 'PLC_WWW_HOST', 'PLC_BOOT_HOST', ]: - plc[key] = name + plc[key] = hostname return plcs diff --git a/system/utils.py b/system/utils.py index 2219848..589f77a 100644 --- a/system/utils.py +++ b/system/utils.py @@ -1,6 +1,7 @@ # $Id$ import time import os +import commands import pprint # how could this accept a list again ? @@ -18,3 +19,20 @@ def system(command): print "+",now return os.system("set -x; " + command) +# checks whether a given hostname/ip responds to ping +ping_timeout_option = None +def check_ping (hostname): + # check OS (support for macos) + global ping_timeout_option + if not ping_timeout_option: + (status,osname) = commands.getstatusoutput("uname -s") + if status != 0: + raise Exception, "Cannot figure your OS name" + if osname == "Linux": + ping_timeout_option="-w" + elif osname == "Darwin": + ping_timeout_option="-t" + + command="ping -c 1 %s 1 %s"%(ping_timeout_option,hostname) + (status,output) = commands.getstatusoutput(command) + return status == 0 -- 2.47.0