def reports(request,report_id=0,groupid=0): if report_id: context=report.show(report_id) context['title']="Report Detail" return render(request,'puppet/report.html',context) else: context={} p=int(request.GET.get('page',1)) if groupid: re=report.listByHost(groupid) context['title']="Reports in Group" else: re=report.showAll() context['title']="Report 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.setHost(report.getHost(p)) p.setUrl("/cmdb/report/"+str(p.id)) context['grouplist']=host.showAll() context['uri']="report" context['with_new']=False context['with_group']=True context['nosearch']=True return render(request,'list.html',context)
def hosts(request,hostid=0,groupid=0): if not hostid: context={} q=request.GET.get('q') p=int(request.GET.get('page',1)) if q: re=host.search(q) context['title']="Hosts in search" elif groupid: re=host.listByGroup(groupid) context['title']="Hosts in Group" else: re=host.showAll() context['title']="Host 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.setIP(host.getIP(p.id)) p.setUrl("/cmdb/host/"+str(p.id)) context['grouplist']=group.listByType('Host') context['uri']='host' context['with_group']=True context['with_new']=False return render(request, 'list.html',context) else: if request.method=='POST': meth=request.POST.get('_method','show') if meth=='delete': host.delete(hostid) return HttpResponse("ok") elif meth=='edit_desc': desc=unquote(request.POST.get('desc','')) host.edit_desc(hostid,desc) return HttpResponse("ok") elif meth=='addparam': key=request.POST.get('key') value=request.POST.get('value') return HttpResponse(parameter.createByHost(hostid,key,value)) elif meth=='delparam': pid=request.POST.get('pid') parameter.delete(pid) return HttpResponse("ok") else: re=host.show(hostid) if re: context=re context['title']="Host Info" return render(request, 'core/host.html',context) else: return HttpResponseRedirect("/cmdb/host")
def hosts(request, hostid=0, groupid=0): if not hostid: context = {} q = request.GET.get('q') p = int(request.GET.get('page', 1)) if q: re = host.search(q) context['title'] = "Hosts in search" elif groupid: re = host.listByGroup(groupid) context['title'] = "Hosts in Group" else: re = host.showAll() context['title'] = "Host 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.setIP(host.getIP(p.id)) p.setUrl("/cmdb/host/" + str(p.id)) context['grouplist'] = group.listByType('Host') context['uri'] = 'host' context['with_group'] = True context['with_new'] = False return render(request, 'list.html', context) else: if request.method == 'POST': meth = request.POST.get('_method', 'show') if meth == 'delete': host.delete(hostid) return HttpResponse("ok") elif meth == 'edit_desc': desc = unquote(request.POST.get('desc', '')) host.edit_desc(hostid, desc) return HttpResponse("ok") elif meth == 'addparam': key = request.POST.get('key') value = request.POST.get('value') return HttpResponse(parameter.createByHost(hostid, key, value)) elif meth == 'delparam': pid = request.POST.get('pid') parameter.delete(pid) return HttpResponse("ok") else: re = host.show(hostid) if re: context = re context['title'] = "Host Info" return render(request, 'core/host.html', context) else: return HttpResponseRedirect("/cmdb/host")
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 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)