Пример #1
0
def destroyVolume():
	jsonpFunc = str(request.args.get('jsonp_callback'))
	volumeid = int(request.args.get('volumeid'))
	volumeDetails=query_db('select * from volumes where volumeid=?',[volumeid]);
	destroy={'status':1}
	if volumeDetails:
		volumeDetails=volumeDetails[0];
		status=volumeDetails[1];
		name=volumeDetails[2];
		cid=volumeDetails[3];
		size=volumeDetails[4];

		if status=="attached":
			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];

				retVal=col.detachVolume(path,volumeDetails,vmid);
				if retVal!=-1: 
       	        			db = get_db()
        				db.execute('''update volumes set status="available",vmid=0,volxml='' where volumeid=?''',[volumeid]);
					db.commit()
				else:
					destroy={'status':0}
		if destroy['status']!=0:
			# destroy volume	
			retVal=col.destroyVolume(volumeDetails)
		
			if retVal!=-1:
       	        		db = get_db()
				db.execute('''delete from volumes where volumeid=?''',[volumeid]);
				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);
Пример #2
0
def destroyVolume():
	volumeid = int(request.args.get('volumeid'))
	volumeDetails=query_db('select * from volumes where volumeid=?',[volumeid]);
	if volumeDetails:
		volumeDetails=volumeDetails[0];
		status=volumeDetails[1];
		name=volumeDetails[2];
		cid=volumeDetails[3];
		size=volumeDetails[4];

		if status=="attached":
			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];

				retVal=col.detachVolume(path,volumeDetails,vmid);
				if retVal!=-1: 
       	        			db = get_db()
        				db.execute('''update volumes set status="available",vmid=0,volxml='' where volumeid=?''',[volumeid]);
					db.commit()
				else:
					return jsonify({'status':0})
		# destroy volume	
		retVal=col.destroyVolume(volumeDetails)

		if retVal!=-1:
       	        	db = get_db()
			db.execute('''delete from volumes where volumeid=?''',[volumeid]);
			db.commit()
			return jsonify({'status':1})
		else:
			return jsonify({'status':0})
	else:
		return jsonify({'status':0})