--- virt-cluster/vc/vc-main-host-updater.py 2012/08/30 12:48:07 9 +++ virt-cluster/vc/vc-main-host-updater.py 2012/08/31 10:40:38 10 @@ -1,94 +1,94 @@ -#!/usr/bin/python -# -# BonFIRE Virtual Clusters on Federated Clouds Demonstration Kit -# -# Copyright (c) Fundacion Centro Tecnologico de Supercomputacion de Galicia 2012 -# -# License GPL Version 3 -# -# The research leading to these results has received funding from -# the European Community's Seventh Frameqork Programme (FP7/2007-2013) -# under agreement number 257386 -# -# This software is provided with ABSOLUTELY NO WARRANTY -# -import sys -import time - -from logger import log,configure - -UPDATER_PERIOD = 30 - -if len(sys.argv) >1: - configure(logfile = sys.argv[1], debug=True, console=False) -else: - configure(debug=True, console=True) - -try: - import bonfire - import ogs - import hostsfile - - default_bonfire = "/etc/default/bonfire" - bonfire.read_defaults(default_bonfire) - hosts_file = "/etc/hosts" - - log.info("Bonfire URI: %s" % bonfire.uri) - log.info("Credentials: %s:%s" % (bonfire.user,bonfire.password,)) - log.info("Experiment: %s" % bonfire.experiment_id) - - log.debug("Set OGS all.q queue to use /bin/bash") - while(True): - try: - ogs.modify_queue("all.q",{"shell":"/bin/bash"}) - ogs.modify_queue("all.q",{"rerun":"TRUE"}) - ogs.modify_global({"max_unheard":"00:02:00","reschedule_unknown":"00:01:00"}) - break - except Exception as excpt: - log.exception(excpt) - time.sleep(10) - - while(True): - try: - log.info("Get experiment") - experiment = bonfire.get_experiment(bonfire.experiment_id) - - try: - #Update /etc/hosts - log.info("Hosts file") - hosts = hostsfile.load(hosts_file) - new_hosts = [(compute['ip'],compute['hostname']) for compute in experiment['computes'] if "client" in compute['hostname'] and not "DONE" in compute['state'] and not "FAILED" in compute ['state'] and not hosts.has_key(compute['ip'])] - log.debug(new_hosts) - for ip,hostname in new_hosts: - #Add to hosts list file - hostsfile.append(hosts_file,ip,hostname) - except Exception as excpt: - log.exception(excpt) - - try: - #Update OGS - log.info("Update OGS") - hosts = ogs.get_execution_hosts() - new_hosts = [(compute['ip'],compute['hostname'],float(compute['cpu'])) for compute in experiment['computes'] if "client" in compute['hostname'] and not "DONE" in compute ['state'] and not "FAILED" in compute ['state'] and not compute['hostname'] in hosts] - log.debug(new_hosts) - for ip,hostname,cpu in new_hosts: - #Add to OGS - ogs.new_host(hostname,cpu) - except Exception as excpt: - log.exception(excpt) - - try: - #Remove invalid hosts - log.info("Remove invalid hosts") - done_hostnames = [compute['hostname'] for compute in experiment['computes'] if "client" in compute['hostname'] and (("DONE" in compute['state']) or ("FAILED" in compute['state']))] - log.debug(done_hostnames) - for hostname in done_hostnames: - #Remove from OGS - ogs.remove_host(hostname) - except Exception as excpt: - log.exception(excpt) - except Exception as excpt: - log.exception(excpt) - time.sleep(UPDATER_PERIOD) -except Exception as excpt: - log.exception(excpt) +#!/usr/bin/python +# +# BonFIRE Virtual Clusters on Federated Clouds Demonstration Kit +# +# Copyright (c) Fundacion Centro Tecnologico de Supercomputacion de Galicia 2012 +# +# License GPL Version 3 +# +# The research leading to these results has received funding from +# the European Community's Seventh Framework Programme (FP7/2007-2013) +# under agreement number 257386 +# +# This software is provided with ABSOLUTELY NO WARRANTY +# +import sys +import time + +from logger import log,configure + +UPDATER_PERIOD = 30 + +if len(sys.argv) >1: + configure(logfile = sys.argv[1], debug=True, console=False) +else: + configure(debug=True, console=True) + +try: + import bonfire + import ogs + import hostsfile + + default_bonfire = "/etc/default/bonfire" + bonfire.read_defaults(default_bonfire) + hosts_file = "/etc/hosts" + + log.info("Bonfire URI: %s" % bonfire.uri) + log.info("Credentials: %s:%s" % (bonfire.user,bonfire.password,)) + log.info("Experiment: %s" % bonfire.experiment_id) + + log.debug("Set OGS all.q queue to use /bin/bash") + while(True): + try: + ogs.modify_queue("all.q",{"shell":"/bin/bash"}) + ogs.modify_queue("all.q",{"rerun":"TRUE"}) + ogs.modify_global({"max_unheard":"00:02:00","reschedule_unknown":"00:01:00"}) + break + except Exception as excpt: + log.exception(excpt) + time.sleep(10) + + while(True): + try: + log.info("Get experiment") + experiment = bonfire.get_experiment(bonfire.experiment_id) + + try: + #Update /etc/hosts + log.info("Hosts file") + hosts = hostsfile.load(hosts_file) + new_hosts = [(compute['ip'],compute['hostname']) for compute in experiment['computes'] if "client" in compute['hostname'] and not "DONE" in compute['state'] and not "FAILED" in compute ['state'] and not hosts.has_key(compute['ip'])] + log.debug(new_hosts) + for ip,hostname in new_hosts: + #Add to hosts list file + hostsfile.append(hosts_file,ip,hostname) + except Exception as excpt: + log.exception(excpt) + + try: + #Update OGS + log.info("Update OGS") + hosts = ogs.get_execution_hosts() + new_hosts = [(compute['ip'],compute['hostname'],float(compute['cpu'])) for compute in experiment['computes'] if "client" in compute['hostname'] and not "DONE" in compute ['state'] and not "FAILED" in compute ['state'] and not compute['hostname'] in hosts] + log.debug(new_hosts) + for ip,hostname,cpu in new_hosts: + #Add to OGS + ogs.new_host(hostname,cpu) + except Exception as excpt: + log.exception(excpt) + + try: + #Remove invalid hosts + log.info("Remove invalid hosts") + done_hostnames = [compute['hostname'] for compute in experiment['computes'] if "client" in compute['hostname'] and (("DONE" in compute['state']) or ("FAILED" in compute['state']))] + log.debug(done_hostnames) + for hostname in done_hostnames: + #Remove from OGS + ogs.remove_host(hostname) + except Exception as excpt: + log.exception(excpt) + except Exception as excpt: + log.exception(excpt) + time.sleep(UPDATER_PERIOD) +except Exception as excpt: + log.exception(excpt)