Exemplo n.º 1
0
def buildBundle(payload, payloadDir):
	try:
		#RM old bundle
		res=GF.run("rm "+payload)
		GF.log("rm "+payload,1)
		#make new bundle
		res=GF.run("tar cvf "+payload+' '+payloadDir+"/*")
		GF.log("tar cvf "+payload+' '+payloadDir+"/*",1)
	except Exception as x:
		print x, "\n", res
		sys.exit()
Exemplo n.º 2
0
def startNodes(ami, inst_size, keyName, maxPrice, nodecnt):
	GF.log("... starting " + str(nodecnt) + " node(s)", 1);
	local=[]
	try:		
		res = GF.run("ec2-request-spot-instances " + ami + " -p " + str(maxPrice) + " -instance-type " + inst_size + " -n " + str(nodecnt) + " --type one-time" + " --key " + keyName)
		lines=res.split("\n")
		for i in range(0,len(res.split("\n"))):
			line=lines[i]
			print "res: ",i,line
			if line.find("SPOTINSTANCEREQUEST")>=0:
				inst=line.split("\t")
				local.append(CLnode.CLnode( ''    ,'slave' ,inst[5], ''  ,  '' ,  ''  ,inst[6] ,inst[0],  ''   ,False,inst[1],False))
				                           #instID,instName,status , ami , key , size ,  date  , ntype ,  url  ,master,sir,deployed):

		if res.find("timeout")>=0:
			print "TIMEOUT: ", res
			sys.exit()
		if res.find("InvalidAMIID")>=0:
			print "INVALID AMI ID: ", res
			sys.exit()
		
	except Exception as x:
		print x, "\n", res
		sys.exit()
	GF.addNewNodes(local)
Exemplo n.º 3
0
    def gather(self, logsDir, sshKey):
        print "\n============================================"
        print "Gathering logs: ", self.instID, "/", self.instName
        print "====="
        logsDir += "/" + self.instID + "-" + self.instName

        try:
            res = GF.run("mkdir -p " + logsDir)
            res = GF.run(
                "scp -r -o StrictHostKeyChecking=no -i " + sshKey + " ubuntu@" + self.url + ":/var/tmp/log " + logsDir
            )
            print "scp -r -o StrictHostKeyChecking=no -i " + sshKey + " ubuntu@" + self.url + ":/var/tmp/log " + logsDir
        except Exception as x:
            print x, "\n", res
            return -1

        """
Exemplo n.º 4
0
    def deploy(self, payload, sshKey, launch=False):
        # TODO: error handeling
        # remove SIG with ssh-keygen -f "/home/madmaze/.ssh/known_hosts" -R ec2-184-73-46-186.compute-1.amazonaws.com
        print "\n============================================"
        print "Deploing", self.instID, "/", self.instName
        print "====="

        if self.master is False:
            try:
                res = GF.run(
                    "scp -o StrictHostKeyChecking=no -i " + sshKey + " " + payload + "  ubuntu@" + self.url + ":~/"
                )
                print "scp -o StrictHostKeyChecking=no -i " + sshKey + " " + payload + "  ubuntu@" + self.url + ":~/"
            except Exception as x:
                print x, "\n", res
                return -1

                # EXTRACT payload
            try:
                res = GF.run(
                    "ssh -o StrictHostKeyChecking=no -i " + sshKey + " ubuntu@" + self.url + " 'tar xvf ~/bundle.tar;'"
                )
                print "ssh -o StrictHostKeyChecking=no -i " + sshKey + " ubuntu@" + self.url + " 'tar xvf ~/bundle.tar;'"
            except Exception as x:
                print x, "\n", res
                return -1

            if launch is True:
                # LAUNCH Payload
                try:
                    print "ssh -o StrictHostKeyChecking=no -i " + sshKey + " ubuntu@" + self.url + " 'python ~/payload/setup.py&'"
                    res = GF.run(
                        "ssh -o StrictHostKeyChecking=no -i "
                        + sshKey
                        + " ubuntu@"
                        + self.url
                        + " 'screen -dm python ~/payload/setup.py'"
                    )

                    self.deployed = True
                except Exception as x:
                    print x, "\n", res
                    return -1
        else:
            print "Master node: No need to deploy!"
Exemplo n.º 5
0
 def kill(self):
     if self.status != "running":
         print "Instance is not running, therefore will not shutdown"
         return
     try:
         res = ""
         res = GF.run("ec2-terminate-instances " + self.instID)
         print res
         self.status = "terminated"
     except Exception as x:
         print x, "\n", res
         return -1
Exemplo n.º 6
0
def getSpotRequests():
	try:
		res = GF.run("ec2-describe-spot-instance-requests")
		if res.find("timeout")>=0:
			print "TIMEOUT: ", res
			sys.exit()
		for line in res.split("\n"):
			if line.find("INSTANCE")>=0:
				inst=line.split("\t")
				GF.reqests.append(CLnode.CLnode(inst[1],inst[1],inst[5],'','','',inst[6],inst[0],''))
	except Exception as x:
		print x, "\n", res
		sys.exit()
Exemplo n.º 7
0
def getRunningInstances():
	try:
		res = GF.run("ec2-describe-instances")
		if res.find("timeout")>=0:
			print "TIMEOUT: ", res
			sys.exit()
		for line in res.split("\n"):
			if line.find("INSTANCE")>=0:
				inst=line.split("\t")
				if inst[5] != "terminated":
					GF.nodes.append(CLnode.CLnode(inst[1],inst[1],inst[5],inst[2],inst[6],inst[9],inst[10],inst[0],inst[3],'',inst[22]))
				else:
					GF.log("found terminated"+line,2)
	except Exception as x:
		print x, "\n", res
		sys.exit()
Exemplo n.º 8
0
def curSpotCost(inst_size):
	lt = time.localtime(time.time())	
	curdate = str(lt[0])+"-"+str(lt[1])+"-"+str(lt[2])+"T"+str(lt[3])+":"+str(lt[4])+":"+str(lt[5])+":"+str(lt[6])+"-0000"
	try:
		res = GF.run("ec2-describe-spot-price-history -d Linux/UNIX --region us-east-1 --instance-type "+inst_size+" -s "+curdate)
		if res.find("timeout")>=0:
			print "TIMEOUT: ", res
			sys.exit()
		cost=0
		for i in res.split("\n"):
			cost += float((i.split("\t"))[1]);
		cost = cost/len(res.split("\n"))
	except Exception as x:
		print x, "\n", res
		sys.exit()
	GF.log("Current Instance Cost: "+str(cost), 1);
	return cost
Exemplo n.º 9
0
def launchMaster(ami, inst_size, keyName):
	GF.log("Launching Master node..",1)
	local=[]
	try:
		res = GF.run("ec2-run-instances " + ami + " -k " + keyName + " -t " + size)
		if res.find("InvalidAMIID")>=0:
			print "INVALID AMI ID: ", res
			sys.exit()
		print res
		i=0
		lines=res.split("\n")
		master=CLnode.CLnode()
		for l in lines:
			inst=l.split("\t")
			if inst[0]=="INSTANCE":
				master = CLnode.CLnode(inst[1],"MASTER",inst[5],inst[2],inst[6],inst[9],inst[10],inst[0],'',True)
		master.desc_detail()
		local.append(master)
		GF.addNewNodes(local)
	except Exception as x:
		print x, "\n", res
		sys.exit()