import sys, os import Config import xmlrpclib from ConfigSlice import ConfigSlice class ConfigSvivaldi: def __init__(self,slice_spec): self.slice_spec=slice_spec #Connecting self.url="https://%s:443/PLCAPI/"%Config.host self.server=xmlrpclib.Server(self.url,allow_none=True) def is_name(self): return self.slice_spec['slice_fields']['name'] def is_file(self,slice_spec): hostnames="Hostnames_list-%s.txt"%self.is_name() if (not os.path.isfile(hostnames)): test_slice = ConfigSlice(slice_spec) hosts=test_slice.get_hostnames(slice_spec) if (not hosts): return False return hostnames def run_svivaldi(self,slice_spec,command): ## run the Svivaldie cmd try: hostnames=self.is_file(slice_spec) id=os.popen('set -x;pssh -v -t 10 -h %s -l %s -o /tmp/foo \"cd /usr/share/Svivaldi/ && sudo %s\" &' %(hostnames,self.is_name(),command)) except Exception,e: print str(e) ##for each slice killing vivladi deamon running on remote hosts def kill_svivaldi(self,slice_spec): try: hostnames=self.is_file(slice_spec) print hostnames os.system('set -x;pssh -t 10 -h %s -l %s sudo killall run-sim.pl &'%(hostnames,self.is_name())) os.system('set -x;pssh -t 10 -h %s -l %s sudo killall p2psim &'%(hostnames,self.is_name())) return True except Exception, e: return False print str(e) exit(1) ##recuperate a remote file or directory def recup_log(self,slice_spec): try: file=open(self.is_file(slice_spec),"r") hosts = [line.strip() for line in file.readlines()] for host in hosts: log_file="Coordinates-log-%s"%host os.system("mkdir %s"%log_file) path="/usr/share/Svivaldi/NewLOGS/*" id=os.system("set -x; scp -r %s@%s:%s %s "%(self.is_name(),host, path, log_file)) print "the id of the cmd is",id if(not id): Config.header("SUCCESSFUL to get log file from the first Supervisor: %s"%host) return True else: os.system("rm -rf %s"%log_file)##ca aussi c'est trop creniossse Config.header("FAILED to get log file from %s"%host) return True except Exception, e: print str(e) exit(1) ##permit to rsync any def sync_svivaldi(self,hostnames, local_file, remote_file): try: cmd="set -x;prsync -t 3000 -h %s -l %s -r"%(hostnames, self.slice_spec['name']) os.system(' %s %s %s '%(cmd, local_file, remote_file)) except Exception, e: print str(e) sys.exit(1)