예제 #1
0
def newReview(request, app_id):
  #未登陆
  if not request.user.is_authenticated() and not sso_user_is_authenticated(request) :
    return HttpResponseRedirect('/accounts/login/?next=%s' % request.path)
  #如果不在admin组中,不能使用审批页面
  if len(AdminGroup.objects.filter(username=sso_user_get_username(request))) != 1 and not request.user.is_authenticated():
    error = u"对不起, %s 您没有审批权限, 需要开通请联系Tair答疑" % (sso_user_get_username(request))
    return render_to_response('alert.html',{"text":error},context_instance=RequestContext(request))
  #print app_id
  app = App.objects.get(pk=app_id)
  if request.method == 'POST':
    form = ReviewForm(request.POST)
    decline = request.POST.get("decline","")
    if decline == True:
      app.change_status("4")
      return HttpResponse("ok")
    elif form.is_valid():
      data = form.cleaned_data
      #print data['group']
      g = Group.objects.get(pk=data['group']) 
      review = AppReview(group=g, 
          namespace=data['namespace'], version='', quota=data['quota'], 
          review_by_username=sso_user_get_username(request), old_type=False)
      review.save()
      app.add_review(review)
      app.change_status(data['status'])
      #if data['mail']:
      #  return render_to_response('thanks.html', {'mail': data['mail']},context_instance=RequestContext(request))
      #else:
      #  return HttpResponseRedirect('/app/thanks')

      #更新group信息
      g.incr_app_num()
      g.update_max_namespace(data['namespace'])
      return HttpResponseRedirect('/app/%s/mail'%(app_id))
    #print >> sys.stderr, form
  else:
      form = ReviewForm()
  return render_to_response('review.html', {'form': form, 'apply':app.apply},context_instance=RequestContext(request))
예제 #2
0
def allocNamespace(key, quota, group, app, ctype):
  print group.cluster.master_1, group.cluster.slave_1, group.name, group.cluster.diamond, key, quota
  #print "client start"
  tc = tairclient(group.cluster.master_1, group.cluster.slave_1, group.name)
  #tc = tairclient('10.249.199.174:5198', '10.249.199.184:5198', 'group_1')
  #print "client ok"
  new_area = tc.alloc_namespace(key, quota)
  try:
    # new appreview
    review = AppReview(group=group, 
        namespace=new_area, version='', quota=quota ,
        review_by_username="******", old_type=False)
    review.save()
    app.add_review(review)
    app.change_status('3')
    #print "ok", ctype
    #print group.name
    #print group.cluster.master_1
    #print group.cluster.slave_1
    #print group.cluster.master_2
    #print group.cluster.slave_2
    gdict=[]
    if ctype == "alloc0":
      return (TAIR_SUCCESS, {'areanum':new_area, 'diamond':group.cluster.diamond})
    if ctype == "alloc1":
      distrib = group.cluster.distrib
      if distrib == '1'  or distrib == '2' or distrib == '3':
        #print {'areanum':new_area, 'address':{'group':group.name,'master':group.cluster.master_1,'slave':group.cluster.slave_1}}
        gdict.append({'areanum':new_area,
               'address':{'group':group.name,'master':group.cluster.master_1,'slave':group.cluster.slave_1}})
      if distrib == '4'  or distrib == '5':
        #print {'areanum':new_area,'group':group.name,'master':group.cluster.master_2,'slave':group.cluster.slave_2}
        gdict.append({'areanum':new_area,
               'address':{'group':group.name,'master':group.cluster.master_2,'slave':group.cluster.slave_2}})
      return (TAIR_SUCCESS, {'clusters':gdict})
  except ValueError as e:
    return (TAIR_FAILURE, e)