def deletevm(request): user=request.user username=user.username if not checkUser(user)=='manager': return HttpResponse(u'权限不足,禁止访问') role = "admin" status=request.REQUEST.get("status") vmid=request.REQUEST.get("vmid") course_code=request.REQUEST.get("cid") ''' if(status=="s"): v=VirtualMachine.objects.filter(VM_number=vmid)[0] vm=Stu_VM.objects.filter(virtualmachine=v) vm.delete() elif(status=="t"): v=VirtualMachine.objects.filter(VM_number=vmid)[0] vm=Tea_VM.objects.filter(virtualmachine=v)[0] #vm.delete() ''' delete_vm.delete_vm_on_XenSever("aa",vmid) log = LogDetail(manager = user.manager,detail = u'删除虚拟机'+vmid) course=Course.objects.filter(course_code=course_code)[0] sl=Stu_VM.objects.filter(course=course) session=vm_status.create_session("http://192.178.1.100","root","123456") svmlist=[] for a in sl: vmstatus=vm_status.get_vm_status(session,a.virtualmachine.VM_number) if vmstatus==None: vmstatus="nothing" c=[a,vmstatus] svmlist.append(c) tvmlist=[] tl=Tea_VM.objects.filter(course=course) for a in tl: vmstatus=vm_status.get_vm_status(session,a.virtualmachine.VM_number) if vmstatus==None: vmstatus="nothing" c=[a,vmstatus] tvmlist.append(c) return render_to_response("coursevmlist.html", { "svmlist" : svmlist, "tvmlist" : tvmlist, "role":role, "cid":course_code, "username":username} , context_instance=RequestContext(request))
def getVmInfo(request): cid=request.REQUEST.get('cid') vm_num=request.REQUEST.get('vm_num') username=request.user.username session=vm_status.create_session("http://192.178.1.100","root","123456") vm_info = vm_status.get_vm_info(session,vm_num) if not checkUser(request.user)=='manager': return HttpResponse(u'权限不足,禁止访问') role = "admin" return render_to_response("vminfo.html", {"role":role, "vm_info":vm_info, "username":username, "cid":cid }, context_instance=RequestContext(request))
def changestatus(request): user=request.user username=user.username if not checkUser(user)=='manager': return HttpResponse(u'权限不足,禁止访问') role = "admin" vmid=request.REQUEST.get("id") newstatus=request.REQUEST.get("s") cid=request.REQUEST.get("cid") session=vm_status.create_session("http://192.178.1.100","root","123456") vm_status.change_vm_status(session,vmid,newstatus) course=Course.objects.filter(course_code=cid)[0] sl=Stu_VM.objects.filter(course=course) svmlist=[] for a in sl: vmstatus=vm_status.get_vm_status(session,a.virtualmachine.VM_number) if vmstatus==None: vmstatus="nothing" c=[a,vmstatus] svmlist.append(c) tvmlist=[] tl=Tea_VM.objects.filter(course=course) for a in tl: vmstatus=vm_status.get_vm_status(session,a.virtualmachine.VM_number) if vmstatus==None: vmstatus="nothing" c=[a,vmstatus] tvmlist.append(c) return render_to_response("coursevmlist.html", { "svmlist" : svmlist, "tvmlist" : tvmlist, "cid":cid, "role":role, "username":username} , context_instance=RequestContext(request))
def shutdownAll(request): user=request.user if not checkUser(user)=='manager': return HttpResponse(u'权限不足,禁止访问') courseId="" role="admin" username=user.username courseId=request.GET['cid'] if len(courseId)==1: courseId="0"+courseId session=vm_status.create_session("http://192.178.1.100","root","123456") vm_status.change_vm_list_status(session,courseId,"Halted") log_detail = LogDetail(manager = user.manager,detail = '对课程'+courseId+u'执行全部开机操作') log_detail.save() courselist=Course.objects.all() return render_to_response("allcourse.html", { "courseList" : courselist, "role":role, "username":username} , context_instance=RequestContext(request))
def rebootAll(request): user=request.user if not checkUser(user)=='manager': return HttpResponse(u'权限不足,禁止访问') courseId='' persion = user.manager role='admin' username=user.username courseId = request.GET['cid'] if len(courseId)==1: courseId = '0'+courseId session = vm_status.create_session('http://192.178.1.100','root','123456') vm_status.change_vm_list_status(session,courseId,"Reboot") log_detail = LogDetail(manager = user.manager,detail = '对课程'+courseId+u'执行全部重启操作') log_detail.save() courselist=Course.objects.all() return render_to_response("allcourse.html", { "courseList" : courselist, "role":role, "username":username} , context_instance=RequestContext(request))