Ejemplo n.º 1
0
def destroyVM():
    vmid = int(request.args.get('vmid'))
    clientDetails = query_db('select * from clients where cid=?', [vmid])
    if clientDetails:
        clientDetails = clientDetails[0]
        machineDetails = query_db('select * from machines where mid=?',
                                  [clientDetails[4]],
                                  one=True)
        path = machineDetails[1]
        vmid = clientDetails[1]
        #destroy this vm at host path with this vmid
        retVal = col.destroyVM(path, vmid)
        if retVal != -1:
            instance_type = query_db('select * from vmTypes where tid=?',
                                     [clientDetails[3]],
                                     one=True)
            cpu = instance_type[1]
            ram = instance_type[2]
            disk = instance_type[3]
            db = get_db()
            db.execute('''update machines set ram=?,cpu=? where mid=?''', [
                machineDetails[3] + ram, machineDetails[2] + cpu,
                machineDetails[0]
            ])
            db.commit()

            db.execute('''delete from clients where cid=?''',
                       [clientDetails[0]])
            db.commit()
            return jsonify({'status': 1})
        else:
            return jsonify({'status': 0})
    else:
        return jsonify({'status': 0})
Ejemplo n.º 2
0
def destroyVM():
	vmid = int(request.args.get('vmid'))
	clientDetails=query_db('select * from clients where cid=?',[vmid]);
	if clientDetails:
		clientDetails=clientDetails[0];
		machineDetails=query_db('select * from machines where mid=?',[clientDetails[4]], one=True);
		path=machineDetails[1]
		vmid=clientDetails[1]
		#destroy this vm at host path with this vmid
		retVal=col.destroyVM(path,vmid)
		if retVal!=-1: 
			instance_type=query_db('select * from vmTypes where tid=?',[clientDetails[3]], one=True);
        		cpu=instance_type[1]
        		ram=instance_type[2]
        		disk=instance_type[3]
       	        	db = get_db()
        		db.execute('''update machines set ram=?,cpu=? where mid=?''',[machineDetails[3]+ram,machineDetails[2]+cpu,machineDetails[0]]);
			db.commit()
       
			db.execute('''delete from clients where cid=?''',[clientDetails[0]]);
			db.commit()
			return jsonify({'status':1})
		else:
			return jsonify({'status':0})
	else:
		return jsonify({'status':0})
Ejemplo n.º 3
0
def destroyVM():
    	jsonpFunc = str(request.args.get('jsonp_callback'))
	cid = int(request.args.get('vmid'))
	clientDetails=query_db('select * from clients where cid=?',[cid]);
	destroy={'status':1}
	if clientDetails:
		clientDetails=clientDetails[0];
		machineDetails=query_db('select * from machines where mid=?',[clientDetails[4]], one=True);
		path=machineDetails[1]
		vmid=clientDetails[1]

		#detach the volume from this vm
		volumeDetails=query_db('select * from volumes where vmid=?',[cid]);
		if volumeDetails:
			for i in volumeDetails:
				retVal=col.detachVolume(path,i,vmid);
				if retVal!=-1: 
       	        			db = get_db();
        				db.execute('''update volumes set status="available",vmid=0,volxml='' where volumeid=?''',[i[0]]);
					db.commit();
				else:
					destroy={'status':0}
		print destroy['status']
		if destroy['status']!=0:
			print destroy['status']
			#destroy this vm at host path with this vmid
			retVal=col.destroyVM(path,vmid);

			if retVal!=-1: 
				instance_type=query_db('select * from vmTypes where tid=?',[clientDetails[3]], one=True);
        			cpu=instance_type[1]
        			ram=instance_type[2]
        			disk=instance_type[3]
       	        		db = get_db()
        			db.execute('''update machines set ram=?,cpu=? where mid=?''',[machineDetails[3]+ram,machineDetails[2]+cpu,machineDetails[0]]);
				db.commit()
       	
				db.execute('''delete from clients where cid=?''',[clientDetails[0]]);
				db.commit()
				destroy={'status':1}
			else:
				destroy={'status':0}
		else:
			destroy={'status':0}
	else:
		destroy={'status':0}
    	if jsonpFunc!='None':
		ast=jsonpFunc+'('+json.dumps(destroy)+')'
		print ast
		return ast
	return jsonify(destroy)
Ejemplo n.º 4
0
def destroyVM():
	cid = int(request.args.get('vmid'))
	clientDetails=query_db('select * from clients where cid=?',[cid]);
	if clientDetails:
		clientDetails=clientDetails[0];
		machineDetails=query_db('select * from machines where mid=?',[clientDetails[4]], one=True);
		path=machineDetails[1]
		vmid=clientDetails[1]

		#detach the volume from this vm
		volumeDetails=query_db('select * from volumes where vmid=?',[cid]);
		if volumeDetails:
			for i in volumeDetails:
				retVal=col.detachVolume(path,i,vmid);
				if retVal!=-1: 
       	        			db = get_db();
        				db.execute('''update volumes set status="available",vmid=0,volxml='' where volumeid=?''',[i[0]]);
					db.commit();
				else:
					return jsonify({'status':0})

		#destroy this vm at host path with this vmid
		retVal=col.destroyVM(path,vmid);

		if retVal!=-1: 
			instance_type=query_db('select * from vmTypes where tid=?',[clientDetails[3]], one=True);
        		cpu=instance_type[1]
        		ram=instance_type[2]
        		disk=instance_type[3]
       	        	db = get_db()
        		db.execute('''update machines set ram=?,cpu=? where mid=?''',[machineDetails[3]+ram,machineDetails[2]+cpu,machineDetails[0]]);
			db.commit()
       
			db.execute('''delete from clients where cid=?''',[clientDetails[0]]);
			db.commit()
			return jsonify({'status':1})
		else:
			return jsonify({'status':0})
	else:
		return jsonify({'status':0})