def images(request, imgid=0): if not imgid: context = {} q = request.GET.get('q') p = int(request.GET.get('page', 1)) if q: re = image.search(q) context['title'] = "Image in search" else: re = image.showAll() context['title'] = "Image 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/image/" + str(pa.id)) context['uri'] = 'image' 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': image.delete(imgid) return HttpResponse("ok") else: context = {} re = image.show(imgid) if re: context['title'] = "Image Info" context['baseinfo'] = re context['apps'] = image.getAppByImage(re.id) return render(request, 'docker/image.html', context)
def images(request,imgid=0): if not imgid: context={} q=request.GET.get('q') p=int(request.GET.get('page',1)) if q: re=image.search(q) context['title']="Image in search" else: re=image.showAll() context['title']="Image 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/image/"+str(pa.id)) context['uri']='image' 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': image.delete(imgid) return HttpResponse("ok") else: context={} re=image.show(imgid) if re: context['title']="Image Info" context['baseinfo']=re context['apps']=image.getAppByImage(re.id) return render(request, 'docker/image.html',context)
def create_application(request): if request.method == 'GET': context = {} context['title'] = "Create Application" context['images'] = image.showAll() return render(request, 'docker/create_application.html', context) elif request.method == 'POST': meth = request.POST['meth'] ip = request.POST['ip'] port = request.POST['port'] imagename = request.POST['imagename'] if meth == 'pull': re = dockerclient.pull(ip, port, imagename) if re: respones = {} respones['result'] = 'ok' respones['msg'] = re return JsonResponse(respones, safe=False) else: respones = {} respones['result'] = 'fail' return JsonResponse(respones, safe=False) elif meth == "create": hostid = request.POST['hostid'] name = request.POST['name'] description = request.POST['description'] l_command = request.POST['command'] l_entrypoint = request.POST['entrypoint'] container_name = request.POST['container_name'] host_name = request.POST['host_name'] network_mode = request.POST['network_mode'] privileged = True if request.POST['privileged'] == "true" else False l_security_opt = request.POST['security_opt'] ulimit_nofile = request.POST['ulimit_nofile'] ulimit_noproc = request.POST['ulimit_noproc'] arr_ports = JSONDecoder().decode(request.POST['ports']) arr_volum = JSONDecoder().decode(request.POST['volum']) arr_dns_server = JSONDecoder().decode(request.POST['dns_server']) arr_hosts = JSONDecoder().decode(request.POST['hosts']) arr_environment = JSONDecoder().decode(request.POST['environment']) ports = [] port_bindings = {} command = [] command = l_command.split(";") entrypoint = [] entrypoint = l_entrypoint.split(";") security_opt = [] security_opt = l_security_opt.split(";") for p in arr_ports: if p.split(":")[0]: port_bindings[int(p.split(":")[0])] = int(p.split(":")[1]) ports.append(int(p.split(":")[0])) print port_bindings print ports volume = [] binds = {} for v in arr_volum: vv = {} if v.split(":")[0]: vv['bind'] = v.split(":")[1] vv['mode'] = 'rw' volume.append(v.split(":")[1]) binds[v.split(":")[0]] = vv dns_server = [] for d in arr_dns_server: if d: dns_server.append(d) hosts = {} for h in arr_hosts: if h.split(":")[0]: hosts[h.split(":")[0]] = h.split(":")[1] environment = {} for e in arr_environment: if e.split(":")[0]: environment[e.split(":")[0]] = e.split(":")[1] msg = application.create_new( ip, port, hostid, name, description, imagename, command, entrypoint, container_name, host_name, network_mode, privileged, security_opt, ulimit_nofile, ulimit_noproc, ports, port_bindings, volume, binds, dns_server, hosts, environment) respones = {} respones['result'] = 'ok' respones['msg'] = msg return JsonResponse(respones, safe=False)
def create_application(request): if request.method == 'GET': context={} context['title']="Create Application" context['images']=image.showAll() return render(request,'docker/create_application.html',context) elif request.method == 'POST': meth=request.POST['meth'] ip=request.POST['ip'] port=request.POST['port'] imagename=request.POST['imagename'] if meth=='pull': re=dockerclient.pull(ip, port, imagename) if re: respones={} respones['result']='ok' respones['msg']=re return JsonResponse(respones,safe=False) else: respones={} respones['result']='fail' return JsonResponse(respones,safe=False) elif meth=="create": hostid=request.POST['hostid'] name=request.POST['name'] description=request.POST['description'] l_command=request.POST['command'] l_entrypoint=request.POST['entrypoint'] container_name=request.POST['container_name'] host_name=request.POST['host_name'] network_mode=request.POST['network_mode'] privileged=True if request.POST['privileged']=="true" else False l_security_opt=request.POST['security_opt'] ulimit_nofile=request.POST['ulimit_nofile'] ulimit_noproc=request.POST['ulimit_noproc'] arr_ports = JSONDecoder().decode(request.POST['ports']) arr_volum = JSONDecoder().decode(request.POST['volum']) arr_dns_server = JSONDecoder().decode(request.POST['dns_server']) arr_hosts = JSONDecoder().decode(request.POST['hosts']) arr_environment = JSONDecoder().decode(request.POST['environment']) ports=[] port_bindings={} command=[] command=l_command.split(";") entrypoint=[] entrypoint=l_entrypoint.split(";") security_opt=[] security_opt=l_security_opt.split(";") for p in arr_ports: if p.split(":")[0]: port_bindings[int(p.split(":")[0])]=int(p.split(":")[1]) ports.append(int(p.split(":")[0])) print port_bindings print ports volume=[] binds={} for v in arr_volum: vv={} if v.split(":")[0]: vv['bind']=v.split(":")[1] vv['mode']='rw' volume.append(v.split(":")[1]) binds[v.split(":")[0]]=vv dns_server=[] for d in arr_dns_server: if d: dns_server.append(d) hosts={} for h in arr_hosts: if h.split(":")[0]: hosts[h.split(":")[0]]=h.split(":")[1] environment={} for e in arr_environment: if e.split(":")[0]: environment[e.split(":")[0]]=e.split(":")[1] msg=application.create_new(ip, port, hostid, name, description, imagename, command, entrypoint, container_name, host_name, network_mode, privileged, security_opt, ulimit_nofile, ulimit_noproc, ports, port_bindings, volume, binds, dns_server, hosts, environment) respones={} respones['result']='ok' respones['msg']=msg return JsonResponse(respones,safe=False)