Пример #1
0
def containercommit(request):
    msg = ''
    path = request.get_full_path()
    #print(path)
    containerid = path.split('/')[3][:12]
    #print(containerid)
    commitimagename = request.POST.get('commitimagename')
    print(commitimagename)
    try:
        container = Container.objects.get(containerid__startswith=containerid)
    except:
        msg = '数据库查询有问题'
    print(container.password, container.containername, container.containerhost,
          container.dockerhost)
    dockerip = container.dockerhost
    docker = DockerHost.objects.get(ip=dockerip)
    dockerpassword = docker.hostpassword
    print(dockerpassword)
    commitresult = rundockercmd.commitContainer(
        rundockercmd.sshClient(dockerip, dockerpassword), containerid,
        commitimagename)
    msg = 'commit 失败' + commitresult
    if commitresult:
        #print(commitresult)
        tagresult = rundockercmd.pushImage(
            rundockercmd.sshClient(dockerip, dockerpassword), commitresult,
            commitimagename)
        print(tagresult)
        msg = '提交远程完成!'
    else:
        return render_to_response('containercommit.html',
                                  {'commitresult': commitresult})
    return render_to_response('containercommit.html', {'msg': msg})
Пример #2
0
def containercommit(request):
    msg = ''
    path = request.get_full_path()
    #print(path)
    containerid = path.split('/')[3][:12]
    #print(containerid)
    commitimagename = request.POST.get('commitimagename')
    print(commitimagename)
    try:
        container = Container.objects.get(containerid__startswith=containerid)
    except :
        msg = '数据库查询有问题'
    print(container.password,container.containername,container.containerhost,container.dockerhost)
    dockerip = container.dockerhost
    docker = DockerHost.objects.get(ip=dockerip)
    dockerpassword = docker.hostpassword
    print(dockerpassword)
    commitresult = rundockercmd.commitContainer(rundockercmd.sshClient(dockerip,dockerpassword),containerid,commitimagename)
    msg = 'commit 失败' + commitresult
    if commitresult:
        #print(commitresult)
        tagresult = rundockercmd.pushImage(rundockercmd.sshClient(dockerip,dockerpassword),commitresult,commitimagename)
        print(tagresult)
        msg = '提交远程完成!'
    else:
        return render_to_response('containercommit.html',{'commitresult':commitresult})
    return render_to_response('containercommit.html',{'msg':msg})
Пример #3
0
def containercommit(request):
    username = request.session.get("username")
    msg = ""
    departmentobj = Project.objects.all()
    # print(departmentobj)
    if request.method == "POST":
        path = request.get_full_path()
        # print(path)
        containerid = path.split("/")[3][:12]
        # print(containerid)
        commitimagename = request.POST.get("commitimagename")
        # print(commitimagename)
        commitdeparment = request.POST.get("department")
        print(commitdeparment)
        commitbz = request.POST.get("bz")
        print(commitbz)
        imageexist = ImageName.objects.filter(imagename=commitimagename)  # 判断容器名是否存在
        if imageexist:
            msg = "容器名已存在!!!"
        else:
            try:
                container = Container.objects.get(containerid__startswith=containerid)
            except:
                msg = "数据库查询有问题"
            # print(container.password,container.containername,container.containerhost,container.dockerhost)
            dockerip = container.dockerhost  # 获取docker主机IP地址
            docker = DockerHost.objects.get(ip=dockerip)  # 根据ip地址查询
            dockerpassword = docker.hostpassword  # 获取密码
            # print(dockerpassword)
            commitresult = rundockercmd.commitContainer(
                rundockercmd.sshClient(dockerip, dockerpassword), containerid, commitimagename
            )
            msg = "commit 失败" + commitresult
            if commitresult:
                registryup = registryjson.getregistryjson(registryjson.sshClient(dockerip, dockerpassword))
                m = re.findall(r"repositories", registryup)
                if m:
                    print(commitresult)
                    tagresult = rundockercmd.pushImage(
                        rundockercmd.sshClient(dockerip, dockerpassword), commitresult, commitimagename
                    )
                    print(tagresult)
                    msg = "提交远程镜像完成!"
                    createimage = ImageName.objects.create(
                        username=username, imagename=commitimagename, departmentname=commitdeparment, bz=commitbz
                    )
                else:
                    msg = "私有仓库有问题,请联管理员"
                return render_to_response("containercommit.html", {"msg": msg})
                # return HttpResponseRedirect('/containers/list/?p1=%s' % (msg))
            else:
                print(commitresult)
                return render_to_response("containercommit.html", {"commitresult": commitresult, "msg": msg})
            return render_to_response("containercommit.html", {"msg": msg})
        return render_to_response("containercommit.html", {"msg": msg})
        # return HttpResponseRedirect('/containers/list/?p1=%s' % (msg))
    return render_to_response(
        "containercommit.html", {"msg": msg, "departmentobj": departmentobj, "username": username}
    )
Пример #4
0
def containercommit(request):
    username = request.session.get('username')
    msg = ''
    departmentobj = Project.objects.all()
    #print(departmentobj)
    if request.method == "POST":
        path = request.get_full_path()
        #print(path)
        containerid = path.split('/')[3][:12]
        #print(containerid)
        commitimagename = request.POST.get('commitimagename')
        #print(commitimagename)
        commitdeparment = request.POST.get('department')
        print(commitdeparment)
        commitbz = request.POST.get('bz')
        print(commitbz)
        imageexist = ImageName.objects.filter(imagename=commitimagename) #判断容器名是否存在
        if imageexist:
              msg = "容器名已存在!!!"
        else:
            try:
                container = Container.objects.get(containerid__startswith=containerid)
            except :
                msg = '数据库查询有问题'
            #print(container.password,container.containername,container.containerhost,container.dockerhost)
            dockerip = container.dockerhost #获取docker主机IP地址
            docker = DockerHost.objects.get(ip=dockerip) #根据ip地址查询
            dockerpassword = docker.hostpassword #获取密码
            #print(dockerpassword)

            commitresult = rundockercmd.commitContainer(rundockercmd.sshClient(dockerip,dockerpassword),containerid,commitimagename)
            msg = 'commit 失败' + commitresult
            if commitresult:
                registryup = registryjson.getregistryjson(registryjson.sshClient(dockerip,dockerpassword))
                m = re.findall(r"repositories",registryup)
                if m:
                    print(commitresult)
                    tagresult = rundockercmd.pushImage(rundockercmd.sshClient(dockerip,dockerpassword),commitresult,commitimagename)
                    print(tagresult)
                    msg = '提交远程完成!'
                    createimage = ImageName.objects.create(username=username,imagename=commitimagename,departmentname=commitdeparment,bz=commitbz)
                else:
                    msg ='私有仓库有问题,请联管理员'
                return render_to_response('containercommit.html',{'msg':msg})
            else:
                return render_to_response('containercommit.html',{'commitresult':commitresult,'msg':msg})
            return render_to_response('containercommit.html',{'msg':msg})
        return render_to_response('containercommit.html',{'msg':msg})
    return render_to_response('containercommit.html',{'msg':msg,'departmentobj':departmentobj,'username':username})
Пример #5
0
def containercommit(request):
    username = request.session.get('username')
    msg = ''
    departmentobj = Project.objects.all()
    #print(departmentobj)
    if request.method == "POST":
        path = request.get_full_path()
        #print(path)
        containerid = path.split('/')[3][:12]
        #print(containerid)
        commitimagename = request.POST.get('commitimagename')
        #print(commitimagename)
        commitdeparment = request.POST.get('department')
        print(commitdeparment)
        commitbz = request.POST.get('bz')
        print(commitbz)
        imageexist = ImageName.objects.filter(
            imagename=commitimagename)  #判断容器名是否存在
        if imageexist:
            msg = "容器名已存在!!!"
        else:
            try:
                container = Container.objects.get(
                    containerid__startswith=containerid)
            except:
                msg = '数据库查询有问题'
            #print(container.password,container.containername,container.containerhost,container.dockerhost)
            dockerip = container.dockerhost  #获取docker主机IP地址
            docker = DockerHost.objects.get(ip=dockerip)  #根据ip地址查询
            dockerpassword = docker.hostpassword  #获取密码
            #print(dockerpassword)

            commitresult = rundockercmd.commitContainer(
                rundockercmd.sshClient(dockerip, dockerpassword), containerid,
                commitimagename)
            msg = 'commit 失败' + commitresult
            if commitresult:
                registryup = registryjson.getregistryjson(
                    registryjson.sshClient(dockerip, dockerpassword))
                m = re.findall(r"repositories", registryup)
                if m:
                    print(commitresult)
                    tagresult = rundockercmd.pushImage(
                        rundockercmd.sshClient(dockerip, dockerpassword),
                        commitresult, commitimagename)
                    print(tagresult)
                    msg = '提交远程完成!'
                    createimage = ImageName.objects.create(
                        username=username,
                        imagename=commitimagename,
                        departmentname=commitdeparment,
                        bz=commitbz)
                else:
                    msg = '私有仓库有问题,请联管理员'
                return render_to_response('containercommit.html', {'msg': msg})
            else:
                return render_to_response('containercommit.html', {
                    'commitresult': commitresult,
                    'msg': msg
                })
            return render_to_response('containercommit.html', {'msg': msg})
        return render_to_response('containercommit.html', {'msg': msg})
    return render_to_response('containercommit.html', {
        'msg': msg,
        'departmentobj': departmentobj,
        'username': username
    })