def container_update(request): if request.method == 'GET': x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') if x_forwarded_for: ip = x_forwarded_for.split(',')[0] else: ip = request.META.get('REMOTE_ADDR') port = "2375" if ip and port: ping = dockerclient.testEngine(ip, port) if ping: re1 = dockerclient.listContainers(ip, port) re2 = application.listByIp(ip) if re1: for re in re1: #auto detect if not application.exist(re['id']): application.auto_detect(ip, port, re['id']) if re2: for re in re2: #update status application.updateStatus(re) return HttpResponse("ok") return HttpResponseNotFound("403")
def container_update(request): if request.method == 'GET': x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') if x_forwarded_for: ip = x_forwarded_for.split(',')[0] else: ip = request.META.get('REMOTE_ADDR') port="2375" if ip and port: ping=dockerclient.testEngine(ip, port) if ping: re1=dockerclient.listContainers(ip,port) re2=application.listByIp(ip) if re1: for re in re1: #auto detect if not application.exist(re['id']): application.auto_detect(ip, port, re['id']) if re2: for re in re2: #update status application.updateStatus(re) return HttpResponse("ok") return HttpResponseNotFound("403")
def applications(request, appid=0): if not appid: context = {} q = request.GET.get('q') p = int(request.GET.get('page', 1)) if q: re = application.search(q) context['title'] = "Applications in search" else: re = application.showAll() context['title'] = "Applications 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 pa in context['page']: pa.setUrl("/cmdb/application/" + str(pa.id)) context['uri'] = 'application' 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': application.delete(appid) return HttpResponse("ok") if meth == 'edit': name = request.POST.get('name') description = request.POST.get('description') if name: application.edit(appid, name, description) return HttpResponse("ok") if meth == 'start': app = application.show(appid) containerid = app.containerid ip = app.engineip port = app.engineport dockerclient.start(ip, port, containerid) application.updateStatus(app) return HttpResponse("ok") if meth == 'stop': app = application.show(appid) containerid = app.containerid ip = app.engineip port = app.engineport dockerclient.stop(ip, port, containerid) application.updateStatus(app) return HttpResponse("ok") else: context = {} re = application.show(appid) if re: inspect = dockerclient.inspect_container( re.engineip, re.engineport, re.containername) context['title'] = "Applications Info" context['baseinfo'] = re context['inspect'] = inspect return render(request, 'docker/application.html', context) else: return HttpResponseRedirect("/cmdb/application")
def applications(request,appid=0): if not appid: context={} q=request.GET.get('q') p=int(request.GET.get('page',1)) if q: re=application.search(q) context['title']="Applications in search" else: re=application.showAll() context['title']="Applications 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 pa in context['page']: pa.setUrl("/cmdb/application/"+str(pa.id)) context['uri']='application' 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': application.delete(appid) return HttpResponse("ok") if meth=='edit': name=request.POST.get('name') description=request.POST.get('description') if name: application.edit(appid, name, description) return HttpResponse("ok") if meth=='start': app=application.show(appid) containerid=app.containerid ip=app.engineip port=app.engineport dockerclient.start(ip, port, containerid) application.updateStatus(app) return HttpResponse("ok") if meth=='stop': app=application.show(appid) containerid=app.containerid ip=app.engineip port=app.engineport dockerclient.stop(ip, port, containerid) application.updateStatus(app) return HttpResponse("ok") else: context={} re=application.show(appid) if re: inspect=dockerclient.inspect_container(re.engineip,re.engineport,re.containername) context['title']="Applications Info" context['baseinfo']=re context['inspect']=inspect return render(request, 'docker/application.html',context) else: return HttpResponseRedirect("/cmdb/application")