Exemple #1
0
def ProjectCluster(request, id):
    ret = public(request, 'app-pro', '集群', '列表')
    ret['bodycss'] = 'sidebar-collapse'
    ret['clusters'] = cluster.objects.filter(toproject__id=id)
    ret['id'] = id
    ret['project'] = project.objects.get(id=id)
    return render_to_response('application/cluster_list.html', ret)
def Network(request):
    ret = public(request,'vmware-manage','网络','设置')
    node_list = node_network.objects.filter().values('name','vswitch','vlan','type','conn','times')
    node_list.query.group_by = ['name','vswitch','conn']
    ret['node_networks'] = node_list
    ret['nowtime'] = time.time() - 650
    return render_to_response('vmware/manage/network_list.html',ret)
def UserEdit(request, id):
    ret = public(request, 'User-List', '用户', '编辑')
    users = User(id)
    if request.method == 'POST':
        if str(id) != str(ret['uid']) or ret['uid'] == 1:
            form_value = dict()
            form_value['group'] = request.POST.getlist('group')
            form_value['ownpe'] = request.POST.getlist('ownpe')
            users.UserGroupUpdate(form_value)
            PublicLog(ret['uid'], u'编辑用户 %s 的信息' % users.GetUser().name,
                      5).Create
            return redirect('/User/')
        else:
            ret = UserEditError(ret)
            PublicLog(ret['uid'],
                      u'编辑用户 %s 的信息' % users.GetUser().name,
                      5,
                      result=1).Create
            return render_to_response('public/message.html', ret)
    else:
        ret['user'] = users.GetUser()
        ret['ingroup'] = users.GetUserGroup()
        ret['othergroup'] = users.GetUserOtherGroup()
        ret['inpermission'] = users.GetUserPermission()
        ret['otherpermission'] = users.GetUserOtherPermission()
        return render_to_response('user/edit.html', ret)
def NetworkDel(request,id,dvs_name,dvs_vswitch):
    ret = public(request,'vmware-manage','分布式网络','删除')
    network = MANAGE()
    del_network = {'name':dvs_name,'vswitch':dvs_vswitch}
    del_network['conn'] = network.GetVCFromId(id)
    rs = network.DelDvs(del_network)
    vMwareNodeDvsDelRight(ret) if rs else vMwareNodeDvsDelError(ret)
    return render_to_response('public/message.html',ret)
def OrderDetail(request,id):
    ret = public(request,'vmware-detail','订单','详情')
    ret['bodycss'] = 'sidebar-collapse'
    ret['order'] = order.objects.get(id=id)
    ret['info'] = order_resource.objects.filter(order__id=id)
    ret['flow'] = order_resource.objects.filter(order__id=id)
    ret['errors'] = order_error.objects.filter(order__id=id,status=0)
    ret['errors_2'] = order_vm_open_log.objects.filter(order__id=id,rs=1)
    return render_to_response('vmware/manage/order_detail.html',ret)
def MailActive(request):
    ret = public(request, 'User-Logout', '用户', '邮件激活')
    if request.method == 'POST':
        register_time = user.objects.get(id=ret['uid']).register_time
        UserRegisterActive(request, ret['uid'], ret['name'], register_time)
        ret['message'] = '=-=-=-=-=-=-=激活邮件已发送,请查收!=-=-=-=-=-=-='
        return render_to_response('user/mail_active_tip.html', ret)
    else:
        return render_to_response('user/mail_active_tip.html', ret)
def Manage(request):
    ret = public(request,'vmware-manage','虚拟化','管理')
    ret['bodycss'] = 'sidebar-collapse'
    ret['resources'] = resource.objects.filter().count()
    ret['orders'] = order.objects.filter(status__lt=9)
    ret['wait_start'] = order.objects.filter(status__lt=9).values('num').aggregate(Sum('num')).get('num__sum',0)
    ret['over'] = order.objects.filter(status=100).values('num').aggregate(Sum('num')).get('num__sum',0)
    ret['type'] = vmtype.objects.filter(status__lt=100).count()
    ret['ippools'] = ippool.objects.all()
    return render_to_response('vmware/manage/virtual_manage.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 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 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 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 PasswdRest(request, id):
    ret = public(request, 'User-PasswdRest', 'User', 'PasswdRest')
    users = User(id)
    rs, name = users.ResetPwd()
    if rs:
        PublicLog(ret['uid'], u'重置 %s 密码' % name, 4, id).Create
        UserResetPwd(request, rs, name)
        return redirect('/User/')
    else:
        ret = UserResetPwdError(ret)
        PublicLog(ret['uid'], u'重置 %s 密码' % name, 4, id, 1).Create
        return render_to_response('public/message.html', ret)
def GroupDel(request, id):
    ret = public(request, 'User-Group', '组', '删除')
    group_name = group.objects.get(id=id).name
    groups = Group(id)
    rs = groups.Del()
    if not rs:
        ret = GroupDelError(ret)
        PublicLog(ret['uid'], u'删除 %s 组' % group_name, 7, result=1).Create
        return render_to_response('public/message.html', ret)
    else:
        PublicLog(ret['uid'], u'删除 %s 组' % group_name, 7).Create
        return redirect('/User/group/')
Exemple #16
0
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 Logout(request):
    ret = public(request, 'User-Logout', '用户', '退出')
    PublicLog(ret['uid'], u'退出登录', 4).Create
    del request.session['logintime']
    del request.session['uid']
    del request.session['mail']
    del request.session['name']
    del request.session['dpid']
    del request.session['dpname']
    del request.session['permission']
    request.session['history_url'] = '/Dashboard/'
    return redirect('/login/')
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)
Exemple #19
0
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 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 UserDel(request, id):
    ret = public(request, 'User-Del', '用户', '删除')
    users = user.objects.get(id=id)
    if users.active == 1:
        users.user_group.remove()
        users.user_department.remove()
        users.delete()
        PublicLog(ret['uid'], u'删除用户 %s' % users.name, 3).Create
    else:
        users.active = 10000
        users.save()
        PublicLog(ret['uid'], u'删除用户 %s' % users.name, 3).Create
    return redirect('/User/')
Exemple #22
0
def ProjectDel(request, projectid):
    ret = public(request, 'app-pro', '集群主机', '删除应用')
    if projectid:
        cluster_num = cluster.objects.filter(toproject__id=projectid).count()
        if cluster_num == 0:
            project.objects.get(id=projectid).delete()
            return redirect('/application/app/list/')
        else:
            ret['message_url'] = '/application/app/list/'
            ret['status'] = 'error'
            ret['message_title'] = '删除失败'
            ret['message_content'] = '请移除属于此应用的集群之后再进行应用的删除!'
            return render_to_response('public/message.html', ret)
Exemple #23
0
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)
Exemple #24
0
def AssetDel(request, id):
    ret = public(request, 'app-pro', '主机', '删除主机')
    if id:
        cluster_num = cluster.objects.filter(host__id=id).count()
        if cluster_num == 0:
            asset.objects.get(id=id).delete()
            return redirect('/application/list/')
        else:
            ret['message_url'] = '/application/list/'
            ret['status'] = 'error'
            ret['message_title'] = '删除失败'
            ret['message_content'] = '此主机仍归属于集群,请解除主机与群集的关系后再进行删除!'
            return render_to_response('public/message.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)
Exemple #26
0
def ClusterHostList(request, id):
    ret = public(request, 'app-pro', '集群主机', '列表')
    ret['bodycss'] = 'sidebar-collapse'
    if request.method == 'POST':
        host_lists = request.POST.getlist('hostselect')
        for x in host_lists:
            cluster.objects.get(id=id).host.add(asset.objects.get(id=x))
        return redirect('/application/cluster/host/%s/' % id)
    else:
        ret['host'] = asset.objects.filter(cluster__id=id)
        ret['id'] = id
        ret['assets'] = asset.objects.filter()
        ret['cluster'] = cluster.objects.get(id=id)
        return render_to_response('application/host_list.html', ret)
Exemple #27
0
def ClusterDel(request, clusterid, projectid):
    ret = public(request, 'app-pro', '集群主机', '移除群集')
    if clusterid:
        asset_num = asset.objects.filter(cluster__id=clusterid).count()
        print asset_num
        if asset_num == 0:
            cluster.objects.get(id=clusterid).delete()
            return redirect('/application/app/%s/' % projectid)
        else:
            ret['message_url'] = '/application/app/%s/' % clusterid
            ret['status'] = 'error'
            ret['message_title'] = '删除失败'
            ret['message_content'] = '请移除属于集群的节点之后再进行集群的删除!'
            return render_to_response('public/message.html', ret)
Exemple #28
0
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 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 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)