--- virt-cluster/vc/vc-node-init.py 2012/08/30 12:48:07 9 +++ virt-cluster/vc/vc-node-init.py 2012/08/31 10:40:38 10 @@ -1,111 +1,111 @@ -#!/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 os -import os.path -import subprocess -import sys -import time - -from logger import log,configure -if len(sys.argv)>1: - configure(logfile = sys.argv[1], debug=True, console=False) -else: - configure(debug=True, console=True) - -try: - import bonfire - import hostsfile - import ogs - import vcutil - - allow_single_cluster = True - 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) - - #Basic hostsfile for main nodes - while True: - try: - log.info("Get experiment") - master_host = None - shadow_host = None - while (master_host == None) and ((not allow_single_cluster) or (shadow_host == None)) : - experiment = bonfire.get_experiment(bonfire.experiment_id) - for compute in experiment['computes']: - if compute["hostname"].startswith("master"): - master_host = (compute['ip'],compute['hostname']) - elif compute["hostname"].startswith("shadow"): - shadow_host = (compute['ip'],compute['hostname']) - main_hosts = [('127.0.0.1','localhost'),(bonfire.wan_ip,bonfire.hostname), master_host] - if shadow_host: - main_hosts.append(shadow_host) - data_host = master_host - if bonfire.hostname.startswith("client-shadow"): - data_host = shadow_host - log.debug(str(main_hosts)) - break - except Exception as excpt: - log.exception(excpt) - time.sleep(20) - - hostsfile.store(hosts_file,main_hosts) - - #Try to mount shared - log.info("Try to mount NFS volume") - while True: - try: - log.debug(vcutil.execute("mount -t nfs %s:/volume /shared" % data_host[1])) - break - except Exception as excpt: - log.debug("NFS volume not available") - log.exception(excpt) - try: - log.debug(vcutil.execute("umount /shared")) - except Exception as excpt: - log.exception(excpt) - time.sleep(20) - - #Mount shared - log.debug(vcutil.execute("umount /shared")) - log.info("Sync mount NFS volume") - log.debug(vcutil.execute("mount -t nfs -o nordirplus,hard,nointr,rw %s:/volume /shared" % data_host[1])) - - while not (os.path.exists("/shared/ogs/default/common/sgeexecd") and os.path.exists("/shared/ogs/default/common/settings.sh")): - log.debug("OGS directory not available") - time.sleep(5) - - #Configure OGS installation - log.debug(vcutil.execute("""export SGE_ROOT=/shared/ogs -cd $SGE_ROOT -echo \". $SGE_ROOT/default/common/settings.sh\" >> /root/.bashrc -ln -s $SGE_ROOT/default/common/sgeexecd /etc/init.d/sgeexecd -""")) - - log.debug("Checking if OGS is available") - while True: - try: - log.debug(vcutil.execute(". /shared/ogs/default/common/settings.sh; qstat")) - break - except Exception as excpt: - log.exception(excpt) - time.sleep(10) - - log.debug(vcutil.execute(". /shared/ogs/default/common/settings.sh; python -u /root/vc/vc-node-execd.py /var/log/vc-node-execd.log" , fork = True)) -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 os +import os.path +import subprocess +import sys +import time + +from logger import log,configure +if len(sys.argv)>1: + configure(logfile = sys.argv[1], debug=True, console=False) +else: + configure(debug=True, console=True) + +try: + import bonfire + import hostsfile + import ogs + import vcutil + + allow_single_cluster = True + 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) + + #Basic hostsfile for main nodes + while True: + try: + log.info("Get experiment") + master_host = None + shadow_host = None + while (master_host == None) and ((not allow_single_cluster) or (shadow_host == None)) : + experiment = bonfire.get_experiment(bonfire.experiment_id) + for compute in experiment['computes']: + if compute["hostname"].startswith("master"): + master_host = (compute['ip'],compute['hostname']) + elif compute["hostname"].startswith("shadow"): + shadow_host = (compute['ip'],compute['hostname']) + main_hosts = [('127.0.0.1','localhost'),(bonfire.wan_ip,bonfire.hostname), master_host] + if shadow_host: + main_hosts.append(shadow_host) + data_host = master_host + if bonfire.hostname.startswith("client-shadow"): + data_host = shadow_host + log.debug(str(main_hosts)) + break + except Exception as excpt: + log.exception(excpt) + time.sleep(20) + + hostsfile.store(hosts_file,main_hosts) + + #Try to mount shared + log.info("Try to mount NFS volume") + while True: + try: + log.debug(vcutil.execute("mount -t nfs %s:/volume /shared" % data_host[1])) + break + except Exception as excpt: + log.debug("NFS volume not available") + log.exception(excpt) + try: + log.debug(vcutil.execute("umount /shared")) + except Exception as excpt: + log.exception(excpt) + time.sleep(20) + + #Mount shared + log.debug(vcutil.execute("umount /shared")) + log.info("Sync mount NFS volume") + log.debug(vcutil.execute("mount -t nfs -o nordirplus,hard,nointr,rw %s:/volume /shared" % data_host[1])) + + while not (os.path.exists("/shared/ogs/default/common/sgeexecd") and os.path.exists("/shared/ogs/default/common/settings.sh")): + log.debug("OGS directory not available") + time.sleep(5) + + #Configure OGS installation + log.debug(vcutil.execute("""export SGE_ROOT=/shared/ogs +cd $SGE_ROOT +echo \". $SGE_ROOT/default/common/settings.sh\" >> /root/.bashrc +ln -s $SGE_ROOT/default/common/sgeexecd /etc/init.d/sgeexecd +""")) + + log.debug("Checking if OGS is available") + while True: + try: + log.debug(vcutil.execute(". /shared/ogs/default/common/settings.sh; qstat")) + break + except Exception as excpt: + log.exception(excpt) + time.sleep(10) + + log.debug(vcutil.execute(". /shared/ogs/default/common/settings.sh; python -u /root/vc/vc-node-execd.py /var/log/vc-node-execd.log" , fork = True)) +except Exception as excpt: + log.exception(excpt) +