def OrderOpened(request,id): ret = public(request,'apply-apply','订单','开通') if request.method == 'POST': form_key = ['ippools',] form_value = GetFormPost(request,form_key) order_rs = order_flow.objects.filter(order__id=id,key='opened_ippools') if len(order_rs) == 0: order.objects.filter(id=id).update(status=3) OrderFlowSave({'order':id,'key':'opened_ippools','rs':0,'uid':ret['uid'],'ippool':form_value.get('ippools',None)}) return redirect('/vMware/manage/') else: vMwareOrderInfoError(ret) return render_to_response('public/message.html',ret)
def vCenterAdd(request): ret = public(request,'vmware-manage','vCenter','新增') if request.method == 'POST': form_key = ['host','user','password','alias',] form_value = GetFormPost(request,form_key) form_value['status'] = 0 vcenter(**form_value).save() return redirect('/vMware/vCenter/') else: return render_to_response('vmware/manage/vCenter_add.html',ret)
def vCenterEdit(request,id): ret = public(request,'vmware-manage','vCenter','编辑') if request.method == 'POST': form_key = ['host','user','password','alias',] form_value = GetFormPost(request,form_key) vcenter.objects.filter(id=id).update(**form_value) return redirect('/vMware/vCenter/') else: ret['vCenters'] = vcenter.objects.get(id=id) return render_to_response('vmware/manage/vCenter_edit.html',ret)
def MessageMail(request): ret = public(request,'vmware-manage','通知邮件','配置') if request.method == 'POST': form_key = ['mail_add','mail_smtp','mail_user','mail_pwd',] form_value = GetFormPost(request,form_key) system.objects.filter().update(**form_value) return redirect('/vMware/message/conf/') else: ret['sys'] = system.objects.filter().first() return render_to_response('vmware/manage/message_mail.html',ret)
def CustomEdit(request,id): ret = public(request,'vmware-manage','虚拟机命名规则','新增') if request.method == 'POST': form_key = ['prefix','suffix','pointer'] form_value = GetFormPost(request,form_key) vm_name.objects.filter(id=id).update(**form_value) return redirect('/vMware/customization/') else: ret['vcs'] = vcenter.objects.filter(status=0).values('id','host','alias') ret['name'] = vm_name.objects.get(id=id) return render_to_response('vmware/manage/custome_edit.html',ret)
def BulletinAdd(request): ret = public(request,'vmware-manage','公告','新增') if request.method == 'POST': form_key = ['title','site','endtime','content',] form_value = GetFormPost(request,form_key) bulletin = MANAGE() bulletin.BulletinSave(form_value,ret) return redirect('/vMware/bulletin/') else: ret['sites'] = bulletin_site.objects.filter() return render_to_response('vmware/manage/bulletin_add.html',ret)
def OrderReject(request,id): ret = public(request,'apply-apply','订单','驳回') if request.method == 'POST': form_key = ['remark'] form_value = GetFormPost(request,form_key) print form_value reject_order = order.objects.get(id=id) status = reject_order.status if status in [0,1]: rs = Regect0(reject_order,form_value,ret['uid']) return redirect('/vMware/manage/')
def Resource(request): ret = public(request,'vmware-manage','资源位置','列表') if request.method == 'POST': form_key = ['name','vc','type','node','data'] form_value = GetFormPost(request,form_key) typesadd = MANAGE() typesadd.ResourceAdd(form_value) return redirect('/vMware/resource/') else: ret['resources'] = resource.objects.filter() ret['vcs'] = vcenter.objects.filter(status=0).values('host','id') return render_to_response('vmware/manage/resource.html',ret)
def ClusterAdd(request, id): ret = public(request, 'app-pro', '集群', '列表') if request.method == 'POST': form_key = ['name', 'types', 'port', 'sadd', 'remark'] form_value = GetFormPost(request, form_key) form_value['toproject'] = id app = Application() app.ClusterSave(form_value) return redirect('/application/app/%s/' % id) else: ret['env'] = env.objects.filter() return render_to_response('application/cluster_add.html', ret)
def ProjectAdd(request): ret = public(request, 'app-pro', '应用', '新增') if request.method == 'POST': form_key = ['name', 'belongu', 'devu', 'examu', 'remark'] form_value = GetFormPost(request, form_key) app = Application() app.ProjectSave(form_value) return redirect('/application/app/list/') else: users = User() ret['users'] = users.GetUserList() return render_to_response('application/project_add.html', ret)
def ClusterEdit(request, id): ret = public(request, 'app-pro', '集群', '编辑') if request.method == 'POST': form_key = ['name', 'types', 'port', 'sadd', 'remark'] form_value = GetFormPost(request, form_key) form_value['id'] = id app = Application() toproject = app.ClusterUpdate(form_value) return redirect('/application/app/%s/' % toproject) else: ret['env'] = env.objects.filter() ret['cluster'] = cluster.objects.get(id=id) return render_to_response('application/cluster_edit.html', ret)
def BulletinEdit(request,id): ret = public(request,'vmware-manage','公告','编辑') if request.method == 'POST': form_key = ['title','site','endtime','content',] form_value = GetFormPost(request,form_key) bulletins = MANAGE() bulletins.BulletinUpdate(form_value,id) return redirect('/vMware/bulletin/') else: ret['sites'] = bulletin_site.objects.filter() ret['bulletin'] = bulletin.objects.get(id=id) ret['now'] = time.time() return render_to_response('vmware/manage/bulletin_edit.html',ret)
def ProjectEdit(request, projectid): ret = public(request, 'app-pro', '应用', '编辑') if request.method == 'POST': form_key = ['name', 'belongu', 'devu', 'examu', 'remark'] form_value = GetFormPost(request, form_key) form_value['id'] = projectid app = Application() app.ProjectUpdate(form_value) return redirect('/application/app/list/') else: users = User() ret['users'] = users.GetUserList() ret['project'] = project.objects.get(id=projectid) return render_to_response('application/project_edit.html', ret)
def Message(request): ret = public(request,'vmware-manage','通知','配置') if request.method == 'POST': form_key = ['order_apply','order_pay','wechat_secret','wechat_id','wechat_corp'] form_value = GetFormPost(request,form_key) new = dict() for x in form_key: new['key'] = x new['val'] = form_value.get(x) mess = message.objects.filter(key=x) if mess.count() == 0 : message(**new).save() else: mess.update(**new) return redirect('/vMware/message/') else: mes = message.objects.filter() messa = dict() for x in mes: messa[x.key] = x.val ret['messages'] = messa ret['num'] = mes.count() return render_to_response('vmware/manage/message.html',ret)
def AssetEdit(request,id): ret = public(request,'app-asset','主机','修改') if request.method == 'POST': form_key = ['ip','name','towhere','toroom','toenv','belongu','remark','department'] form_value = GetFormPost(request,form_key) app = Application() app.HostUpdate(id, form_value) return redirect('/application/list/') else: ret['host'] = asset.objects.get(id=id) ret['department'] = department.objects.filter(active=0) ret['wheres'] = where.objects.filter() ret['room'] = room.objects.filter() ret['env'] = env.objects.filter() return render_to_response('application/asset_edit.html',ret)
def PasswdUpdate(request): ret = public(request, 'User-PasswdUpdate', '用户', '更改密码') if request.method == 'POST': form_key = ['nowPwd', 'newPwd', 'confirmPwd'] form_value = GetFormPost(request, form_key) if form_value['newPwd'] == form_value['confirmPwd']: user_class = User(int(ret['uid'])) rs = user_class.UpdatePasswd(form_value['nowPwd'], form_value['newPwd']) ret = UserUpdatePwdRight(ret) if rs else UserUpdatePwdError(ret) rs_status = 0 if ret['status'] == 'right' else 1 PublicLog(ret['uid'], u'修改密码', 5, result=rs_status).Create return render_to_response('public/message.html', ret) else: return render_to_response('user/MustRestPwd.html', ret)
def IPPoolEdit(request,id): ret = public(request,'vmware-manage','IP地址池','管理') if request.method == 'POST': form_key = ['pooladd','netmask','gateway','dns1','dns2','vlan','alia','remark'] form_value = GetFormPost(request,form_key) ip_pool = MANAGE() rs = ip_pool.IpPoolCreate(form_value,id=id) if not rs: vMwareIpPoolCreateError(ret) return render_to_response('public/message.html',ret) else: return redirect('/vMware/ippool/') else: ret['pools'] = ippool.objects.get(id=id) return render_to_response('vmware/manage/pool_edit.html',ret)
def AssetAdd(request): ret = public(request,'app-asset','主机','新增') if request.method == 'POST': form_key = ['ip','name','towhere','toroom','toenv','belongu','remark','department'] form_value = GetFormPost(request,form_key) form_value['belongu'] = ret['uid'] app = Application() app.AssetSave(form_value) return redirect('/application/asset_add/') else: ret['department'] = department.objects.filter(active=0) ret['wheres'] = where.objects.filter() ret['room'] = room.objects.filter() ret['env'] = env.objects.filter() return render_to_response('application/asset_add.html',ret)
def IPPool(request): ret = public(request,'vmware-manage','IP地址池','管理') ret['bodycss'] = 'sidebar-collapse' if request.method == 'POST': form_key = ['pooladd','netmask','gateway','dns1','dns2','vlan','alia','remark'] form_value = GetFormPost(request,form_key) ip_pool = MANAGE() rs = ip_pool.IpPoolCreate(form_value) if not rs: vMwareIpPoolCreateError(ret) return render_to_response('public/message.html',ret) else: return redirect('/vMware/ippool/') else: ret['ippools'] = ippool.objects.filter() return render_to_response('vmware/manage/ip_pool.html',ret)
def GroupEdit(request, id): ret = public(request, 'User-Group', '组', '编辑') groups = Group(id) if request.method == 'POST': form_key = ['name', 'remark'] form_value = GetFormPost(request, form_key) form_value['ownpe'] = request.POST.getlist('ownpe') groups.UpdateGroup(form_value) PublicLog(ret['uid'], u'编辑 %s 组' % form_value['name'], 8).Create return redirect('/User/group/edit/%s/' % id) else: ret['users'] = groups.GetGroupUser() ret['group'] = groups.GetGroup() ret['ownpes'] = groups.GetGroupPermission() ret['otherpes'] = groups.GetGroupOtherPermission() ret['buttom'] = '确认修改' return render_to_response('user/group/edit.html', ret)
def VMTypesAdd(request): ret = public(request,'vmware-manage','虚拟机类型','新增') if request.method == 'POST': form_key = ['type_name','template','application','remark'] form_value = GetFormPost(request,form_key) typesadd = MANAGE() typesadd.VmTypesAdd(form_value) return redirect('/vMware/virtual_type/') else: exclude_abc = vmtype.objects.filter(status=0).values_list().values('type_name') abc = list() for x in exclude_abc: abc.append(x.get('type_name')) ret['abc'] = GenerateAtoZ(abc) ret['templates'] = vms.objects.filter(type=1,status=0).values('id','name','vc') print ret['templates'].query return render_to_response('vmware/manage/virtual_type_add.html',ret)
def GroupList(request): ret = public(request, 'User-Group', '组', '列表') if request.method == 'POST': form_key = ['name', 'remark'] form_value = GetFormPost(request, form_key) groups = Group() rs = groups.Add(form_value) if rs: PublicLog(ret['uid'], u'新增 %s 组' % form_value['name'], 9).Create return redirect('/User/group/') else: ret = GroupAddError(ret) PublicLog(ret['uid'], u'新增 %s 组' % form_value['name'], 9, result=1).Create return render_to_response('public/message.html', ret) else: ret['groups'] = group.objects.filter(active__lt=9999) return render_to_response('user/group/list.html', ret)
def NetworkEdit(request,id,dvs_name): ret = public(request,'vmware-manage','分布式网络','编辑') if request.method == 'POST': form_key = ['name','vlan','vc'] form_value = GetFormPost(request,form_key) network_vlan = MANAGE() rs = network_vlan.UpdateDvsVlan(form_value) if not rs: vMwareNodeDvsUpdateError(ret) return render_to_response('public/message.html',ret) else: return redirect('/vMware/network/') else: networks = node_network.objects.filter(conn=id,name=dvs_name) ret['network'] = networks.first() networks.query.group_by = ['name'] ret['hosts'] = networks return render_to_response('vmware/manage/network_edit.html',ret)
def CustomAdd(request): ret = public(request,'vmware-manage','虚拟机命名规则','新增') if request.method == 'POST': form_key = ['prefix','suffix','pointer','vc',] form_value = GetFormPost(request,form_key) cust_name = MANAGE() rs = cust_name.SaveName(form_value) if not rs: ret['message_url'] = '/vMware/customization/' ret['status'] = 'error' ret['message_title'] = '新增失败' ret['message_content'] = '每个VC下面只能有一个命名规则,而此VC下已有命名规则!' return render_to_response('public/message.html',ret) else: return redirect('/vMware/customization/') else: ret['vcs'] = vcenter.objects.filter(status=0).values('id','host','alias') return render_to_response('vmware/manage/custome_add.html',ret)
def VMApplyOrder(request,types): ret = public(request,'apply-apply','虚拟机','申请') if request.method == 'POST': form_key = ['num','resource','project','endtime','template'] form_value = GetFormPost(request,form_key) form_value['uid'] = ret['uid'] order = MANAGE() rs = order.Save(form_value) vMwareOrderAddRight(ret) if rs else vMwareOrderAddError(ret) return render_to_response('public/message.html',ret) else: ret['num'] = range(1,10) ret['x'] = vmtype.objects.get(type_name=types,status=0) vmtypes = vmtype.objects.get(type_name=types,status=0) template_name = vmtypes.template.name vms_vc = vms.objects.filter(name=template_name,status=0).values_list('vc') vc_list = list() [ vc_list.append(int(x[0])) for x in vms_vc if len(x) > 0 ] ret['resoruce'] = resource.objects.filter(vc__id__in = vc_list).values('name','id','status') return render_to_response('vmware/order.html',ret)
def Login(request): ret = public(request, 'User-Register', '用户', '注册') if request.method == 'POST': form_key = ['name', 'password'] form_value = GetFormPost(request, form_key) login_check = User() login_rs = login_check.CheckLogin(form_value) if login_rs: writsession(request, login_rs) UpdateLoginTime(request) PublicLog(login_rs.id, u'登录', 1).Create jump_url = request.session.get('history_url', '/Dashboard/') return redirect(jump_url) else: ret['message'] = 'The Password or Username error!' return render_to_response('login.html', ret) else: ret['bulletins'] = bulletin.objects.filter(status=0, endtime__gt=time.time(), site__id__in=[1, 2]) login_redirect = CheckSession(request) return render_to_response( 'login.html', ret) if login_redirect.CheckLogin() else redirect('/Dashboard/')
def Register(request): ret = public(request, 'User-Register', '用户', '注册') if request.method == 'POST': form_key = ['name', 'password', 'password2', 'tel', 'department'] form_value = GetFormPost(request, form_key) form_value['register_time'] = time.time() form_value['last_login'] = time.time() form_value['mail'] = str(form_value['name']) + str(ret['mail_add']) form_value['active'] = 1 #the mail no active users = User() rs = users.Add(form_value) if rs: PublicLog(rs, u'用户注册', 2).Create rs = UserRegisterActive(request, rs, form_value['name'], form_value['register_time']) print 'fun_rs:', rs ret = UserRegisterRight(ret) if rs == 0 else MailSettingError( ret, rs) else: ret = UserRegisterError(ret) return render_to_response('public/message.html', ret) else: ret['departments'] = GetGroup() return render_to_response('register.html', ret)