Log In | Get Help   
Home My Page Projects Code Snippets Project Openings BonFIRE VCOC Demonstration Kit
Summary Activity SCM Files Wiki
[bonfiredemokit] View of /virt-cluster/vc/vc-node-init.py
[bonfiredemokit] / virt-cluster / vc / vc-node-init.py Repository:
ViewVC logotype

View of /virt-cluster/vc/vc-node-init.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (download) (as text) (annotate)
Mon Aug 27 11:46:35 2012 UTC (11 years, 9 months ago) by agomez
File size: 3007 byte(s)
#!/usr/bin/python
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)


root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge