def edit_group(request,groupid=0): re=group.show(groupid) if re: context={} context['title']="Group Edit" context['group']=re context['members']=group.getMember(groupid) if context['group'].type=="Host": for p in context['members']: p.setIP(host.getIP(p.id)) return render(request, 'core/edit_group.html',context) else: return HttpResponseRedirect("/cmdb/group")
def edit_group(request, groupid=0): re = group.show(groupid) if re: context = {} context['title'] = "Group Edit" context['group'] = re context['members'] = group.getMember(groupid) if context['group'].type == "Host": for p in context['members']: p.setIP(host.getIP(p.id)) return render(request, 'core/edit_group.html', context) else: return HttpResponseRedirect("/cmdb/group")
def groups(request,groupid=0,grouptype=""): if (not groupid): if request.method=='POST': meth=request.POST.get('_method','show') if meth=='new': name=request.POST.get('name') t=request.POST.get('type') member=request.POST.get('member') if name and t and member: m=member.split(';') m.pop(-1) group.addMember(group.create(name, t), m) return HttpResponse("ok") else: context={} q=request.GET.get('q') p=int(request.GET.get('page',1)) if q: re=group.search(q) context['title']="Groups in search" elif grouptype: re=group.listByType(grouptype) context['title']=grouptype.capitalize()+" Groups Manage" else: re=group.showAll() context['title']="Group List" if re: page=Paginator(re,10) if p>0 and p<=page.num_pages: context['page']=page.page(p) else: context['page']=page.page(1) context['num_pages']=page.num_pages for p in context['page']: p.setUrl("/cmdb/group/"+str(p.id)) context['uri']='group' context['with_group']=False context['with_new']=True return render(request,'list.html',context) else: if request.method=="POST": meth=request.POST.get('_method','show') if meth=='delete': group.delete(groupid) return HttpResponse("ok") if meth=='edit': name=request.POST.get('name') add_list=request.POST.get('add') if add_list: group.addMember(groupid, add_list.split(',')) del_list=request.POST.get('del') if del_list: group.delMember(groupid, del_list.split(',')) group.changeName(groupid, name) return HttpResponse("ok") else: re=group.show(groupid) if re: context={} context['group']=group.show(groupid) context['members']=group.getMember(groupid) context['title']="Group Info" if context['group'].type=="Host": for p in context['members']: p.setIP(host.getIP(p.id)) return render(request,'core/group.html',context) else: return HttpResponseRedirect("/cmdb/group")
def relationship(request,function,functype=''): if request.method=="POST": if function=='add': if functype=='single2single': hosts=request.POST.get('host') configs=request.POST.get('config') if hosts and configs: h=host.get(hosts) c=config.get(configs) if h and c: host.addConfig(h, c) elif functype=='group2single': hosts=request.POST.get('host') configs=request.POST.get('config') if hosts and configs: h=host.get(hosts) configlist=group.getMember(configs) if h and configlist: for c in configlist: host.addConfig(h, c) elif functype=='single2group': hosts=request.POST.get('host') configs=request.POST.get('config') if hosts and configs: hostlist=group.getMember(hosts) c=config.get(configs) if hostlist and c: for h in hostlist: host.addConfig(h, c) elif functype=='group2group': hosts=request.POST.get('host') configs=request.POST.get('config') if hosts and configs: hostlist=group.getMember(hosts) configlist=group.getMember(configs) if hostlist and configlist: for h in hostlist: for c in configlist: host.addConfig(h, c) if function=='remove': hosts=request.POST.get('host') configs=request.POST.get('config') if functype=='single2single': hosts=request.POST.get('host') configs=request.POST.get('config') if hosts and configs: h=host.get(hosts) c=config.get(configs) if h and c: host.removeConfig(h, c) elif functype=='group2single': hosts=request.POST.get('host') configs=request.POST.get('config') if hosts and configs: h=host.get(hosts) configlist=group.getMember(configs) if h and configlist: for c in configlist: host.removeConfig(h, c) elif functype=='single2group': hosts=request.POST.get('host') configs=request.POST.get('config') if hosts and configs: hostlist=group.getMember(hosts) c=config.get(configs) if hostlist and c: for h in hostlist: host.removeConfig(h, c) elif functype=='group2group': hosts=request.POST.get('host') configs=request.POST.get('config') if hosts and configs: hostlist=group.getMember(hosts) configlist=group.getMember(configs) if hostlist and configlist: for h in hostlist: for c in configlist: host.removeConfig(h, c) return HttpResponse("ok") else: context={} context['title']="Host and Config Relationship Manage" context['function']=function context['hostlist']=host.showAll() context['configlist']=config.showAll() context['hostgrouplist']=group.listByType("Host") context['configgrouplist']=group.listByType("CONFIG") return render(request,'core/relationship.html',context)
def groups(request, groupid=0, grouptype=""): if (not groupid): if request.method == 'POST': meth = request.POST.get('_method', 'show') if meth == 'new': name = request.POST.get('name') t = request.POST.get('type') member = request.POST.get('member') if name and t and member: m = member.split(';') m.pop(-1) group.addMember(group.create(name, t), m) return HttpResponse("ok") else: context = {} q = request.GET.get('q') p = int(request.GET.get('page', 1)) if q: re = group.search(q) context['title'] = "Groups in search" elif grouptype: re = group.listByType(grouptype) context['title'] = grouptype.capitalize() + " Groups Manage" else: re = group.showAll() context['title'] = "Group List" if re: page = Paginator(re, 10) if p > 0 and p <= page.num_pages: context['page'] = page.page(p) else: context['page'] = page.page(1) context['num_pages'] = page.num_pages for p in context['page']: p.setUrl("/cmdb/group/" + str(p.id)) context['uri'] = 'group' context['with_group'] = False context['with_new'] = True return render(request, 'list.html', context) else: if request.method == "POST": meth = request.POST.get('_method', 'show') if meth == 'delete': group.delete(groupid) return HttpResponse("ok") if meth == 'edit': name = request.POST.get('name') add_list = request.POST.get('add') if add_list: group.addMember(groupid, add_list.split(',')) del_list = request.POST.get('del') if del_list: group.delMember(groupid, del_list.split(',')) group.changeName(groupid, name) return HttpResponse("ok") else: re = group.show(groupid) if re: context = {} context['group'] = group.show(groupid) context['members'] = group.getMember(groupid) context['title'] = "Group Info" if context['group'].type == "Host": for p in context['members']: p.setIP(host.getIP(p.id)) return render(request, 'core/group.html', context) else: return HttpResponseRedirect("/cmdb/group")
def relationship(request, function, functype=''): if request.method == "POST": if function == 'add': if functype == 'single2single': hosts = request.POST.get('host') configs = request.POST.get('config') if hosts and configs: h = host.get(hosts) c = config.get(configs) if h and c: host.addConfig(h, c) elif functype == 'group2single': hosts = request.POST.get('host') configs = request.POST.get('config') if hosts and configs: h = host.get(hosts) configlist = group.getMember(configs) if h and configlist: for c in configlist: host.addConfig(h, c) elif functype == 'single2group': hosts = request.POST.get('host') configs = request.POST.get('config') if hosts and configs: hostlist = group.getMember(hosts) c = config.get(configs) if hostlist and c: for h in hostlist: host.addConfig(h, c) elif functype == 'group2group': hosts = request.POST.get('host') configs = request.POST.get('config') if hosts and configs: hostlist = group.getMember(hosts) configlist = group.getMember(configs) if hostlist and configlist: for h in hostlist: for c in configlist: host.addConfig(h, c) if function == 'remove': hosts = request.POST.get('host') configs = request.POST.get('config') if functype == 'single2single': hosts = request.POST.get('host') configs = request.POST.get('config') if hosts and configs: h = host.get(hosts) c = config.get(configs) if h and c: host.removeConfig(h, c) elif functype == 'group2single': hosts = request.POST.get('host') configs = request.POST.get('config') if hosts and configs: h = host.get(hosts) configlist = group.getMember(configs) if h and configlist: for c in configlist: host.removeConfig(h, c) elif functype == 'single2group': hosts = request.POST.get('host') configs = request.POST.get('config') if hosts and configs: hostlist = group.getMember(hosts) c = config.get(configs) if hostlist and c: for h in hostlist: host.removeConfig(h, c) elif functype == 'group2group': hosts = request.POST.get('host') configs = request.POST.get('config') if hosts and configs: hostlist = group.getMember(hosts) configlist = group.getMember(configs) if hostlist and configlist: for h in hostlist: for c in configlist: host.removeConfig(h, c) return HttpResponse("ok") else: context = {} context['title'] = "Host and Config Relationship Manage" context['function'] = function context['hostlist'] = host.showAll() context['configlist'] = config.showAll() context['hostgrouplist'] = group.listByType("Host") context['configgrouplist'] = group.listByType("CONFIG") return render(request, 'core/relationship.html', context)