def area(request, area_key): print "xxx" if request.method == 'POST': ctype = request.POST.get("type", "") quota = request.POST.get("quota", -1) print "post ", area_key, ctype, quota try: q = int(quota) except : return HttpResponseBadRequest("quota invalid") #if q <= 0: # return HttpResponseBadRequest("quota invalid") if ctype == "alloc0" or ctype == "alloc1": app = App.objects.filter(name=area_key) if app.count() != 0: return HttpResponseConflict("app key existed!") apply = AppApply(name=area_key,describe="system auto",qps=0,capacity=q,notes="", cache_or_durable=True,restful_api=False,trade_critical=False, data_source=False,complicate_datastruct=False,entry_num=0, get_none_key=False, two_cluster=True, used_tair_before=False, create_by_username="******",email="*****@*****.**") apply.save() app = App(name=area_key, status='1', important='3', apply=apply) app.save() g = findGroupAuto("mdb") if g == None: return HttpResponseNotFound("suitable group not found!") (ret, res) = allocNamespace(area_key ,q, g, app, ctype) if ret == TAIR_SUCCESS: return HttpResponse(json.dumps(res)) else: print "alloc ns error" return HttpResponse({'error':res}) elif ctype == "modify": app = App.objects.filter(name=area_key) if (app.count() == 0): return HttpResponseNotFound("area key not existed!") if not app[0].review: return HttpResponseNotFound("area key not reviewed!") group = app[0].review.group ret = setQuota(area_key, quota, group, app[0]) if ret == TAIR_SUCCESS: app.review.quota = quota app.review.save() return HttpResponse(json.dumps({'error':'OK'})) else : return HttpResponse(json.dumps({'error':'error'})) else : return HttpResponseBadRequest("ctype invalid") if request.method == 'GET': ctype = request.GET.get("type", None) #quota = request.POST.get("quota", -1) #cs_1 = request.POST.get("cs1", None) #cs_2 = request.POST.get("cs2", None) #group = request.POST.get("group", None) #cluster_id = request.POST.get("cluster", -1) if ctype == 'cluster': g = findGroupAuto("mdb") if g == None: return HttpResponseNotFound("suitable group not found!") app = App.objects.filter(name=area_key) if (app.count() == 0): return HttpResponseNotFound("area key not existed!") area_num = app[0].review.namespace quota = app[0].review.quota (ret, res)= getClusterInfo(g, area_num, quota) if ret == TAIR_SUCCESS: return HttpResponse(json.dumps(res)) else : return HttpResponseNotFound("area cluster info not found!") if ctype == 'stat': app = App.objects.filter(name=area_key) if (app.count() == 0): return HttpResponseNotFound("area key not existed!") if not app[0].review: return HttpResponseNotFound("area key not reviewed!") group = app[0].review.group (ret, res) = getAreaStat(area_key, group, app) if ret == TAIR_SUCCESS: return HttpResponse(json.dumps(res)) else : return HttpResponseNotFound("area key get stat failed!") return HttpResponse("please indicate type") if request.method == 'DELETE': app = App.objects.filter(name=area_key) if (app.count() == 0): return HttpResponseNotFound("area key not existed!") if not app[0].review: return HttpResponseNotFound("area key not reviewed!") group = app[0].review.group print 'xxx', area_key ret = setQuota(area_key, 0, group, app[0]) if ret == TAIR_SUCCESS: review = app[0].review apply = app[0].apply try: if review: print 's2reveiw' review.delete() if apply: print 's2apply' apply.delete() except e: print e return HttpResponse(json.dumps(ret)) else : return HttpResponseNotFound("area key delete failed!")