Esempio n. 1
0
def containerdelete(request):
    path = request.get_full_path()
    #print(path)
    containerid = path.split('/')[3][:12]
    print(containerid)
    try:
        container = Container.objects.get(containerid__startswith=containerid)
    except:
        msg = '数据库查询有问题'
    print(container.password, container.containername, container.containerhost,
          container.dockerhost)
    dockerip = container.dockerhost
    containerip = container.containerhost
    docker = DockerHost.objects.get(ip=dockerip)
    dockerpassword = docker.hostpassword
    #print(dockerpassword)
    deleteresult = rundockercmd.deleteContainer(
        rundockercmd.sshClient(dockerip, dockerpassword), containerid)
    print(deleteresult)
    if deleteresult:
        return render_to_response('containerslist.html',
                                  {'deleteresult': deleteresult})
    else:
        try:
            container = Container.objects.get(
                containerid__startswith=containerid).delete()
            ContainerIp.objects.filter(ip=containerip).update(used=0)
            #container = Container.objects.filter(containerid=containerid).delete()
        except:
            msg = '删除数据失败'
            #print(msg)
    return HttpResponseRedirect('/containers/list/')
Esempio n. 2
0
def containerdelete(request):
    path = request.get_full_path()
    #print(path)
    containerid = path.split('/')[3][:12]
    #print(containerid)
    try:
        container = Container.objects.get(containerid__startswith=containerid)
    except :
        msg = '数据库查询有问题'
    #print(container.password,container.containername,container.containerhost,container.dockerhost)
    dockerip = container.dockerhost
    containerip = container.containerhost
    docker = DockerHost.objects.get(ip=dockerip)
    dockerpassword = docker.hostpassword
    #print(dockerpassword)
    deleteresult = rundockercmd.deleteContainer(rundockercmd.sshClient(dockerip,dockerpassword),containerid)
    print(deleteresult)
    if deleteresult:
        return render_to_response('containerslist.html',{'deleteresult':deleteresult })
    else:
        try:
            container = Container.objects.get(containerid__startswith=containerid).delete()
            ContainerIp.objects.filter(ip=containerip).update(used=0)
            #container = Container.objects.filter(containerid=containerid).delete()
        except :
            msg = '删除数据失败'
            #print(msg)
    return HttpResponseRedirect('/containers/list/')
Esempio n. 3
0
def containerdelete(request):
    msg = ''
    path = request.get_full_path()
    #print(path)
    containerid = path.split('/')[3][:12]
    #print(containerid)
    try:
        container = Container.objects.get(containerid__startswith=containerid)
    except:
        msg = '数据库查询有问题'
    #print(container.password,container.containername,container.containerhost,container.dockerhost)
    dockerip = container.dockerhost  #查询docker主机ip
    containerip = container.containerhost  #查询容器ip
    cpun = container.cpunumber  #查询使用cpu号
    print(cpun)
    formatobj = Format.objects.filter(ip__ip=dockerip).filter(
        usedcpu=cpun)  #查找对应主机上对应模板是否存在
    print(formatobj)
    for fcpu in formatobj:
        sumc = fcpu.cnumber  #查询现在运行了多少台容器
        print(sumc)
    docker = DockerHost.objects.get(ip=dockerip)
    dockerpassword = docker.hostpassword
    #print(dockerpassword)
    deleteresult = rundockercmd.deleteContainer(
        rundockercmd.sshClient(dockerip, dockerpassword), containerid)
    print(deleteresult)
    if deleteresult:
        msg = '删除失败,失败原因:' + deleteresult
    else:
        try:
            container = Container.objects.get(
                containerid__startswith=containerid).delete()  #删除数据库
            ContainerIp.objects.filter(ip=containerip).update(used=0)
            if sumc == 6:
                print('使用达到6个cpu')
                Format.objects.filter(ip__ip=dockerip).filter(
                    usedcpu=cpun).update(cnumber=sumc - 1)
                Format.objects.filter(ip__ip=dockerip).filter(
                    usedcpu=cpun).filter(ifexit=1).update(ifexit=0)
                msg = '删除容器成功'
            else:
                print('使用没有达到6个cpu')
                Format.objects.filter(ip__ip=dockerip).filter(
                    usedcpu=cpun).update(cnumber=sumc - 1)
                msg = '删除容器成功'
            #container = Container.objects.filter(containerid=containerid).delete()
        except:
            msg = '数据库查询有问题'
            #print(msg)
    return HttpResponseRedirect('/containers/list/?p1=%s' % (msg))
Esempio n. 4
0
def containerdelete(request):
    msg = ""
    path = request.get_full_path()
    # print(path)
    containerid = path.split("/")[3][:12]
    # print(containerid)
    try:
        container = Container.objects.get(containerid__startswith=containerid)
    except:
        msg = "数据库查询有问题"
    # print(container.password,container.containername,container.containerhost,container.dockerhost)
    dockerip = container.dockerhost  # 查询docker主机ip
    containerip = container.containerhost  # 查询容器ip
    cpun = container.cpunumber  # 查询使用cpu号
    print(cpun)
    formatobj = Format.objects.filter(ip__ip=dockerip).filter(usedcpu=cpun)  # 查找对应主机上对应模板是否存在
    print(formatobj)
    for fcpu in formatobj:
        sumc = fcpu.cnumber  # 查询现在运行了多少台容器
        print(sumc)
    docker = DockerHost.objects.get(ip=dockerip)
    dockerpassword = docker.hostpassword
    # print(dockerpassword)
    deleteresult = rundockercmd.deleteContainer(rundockercmd.sshClient(dockerip, dockerpassword), containerid)
    print(deleteresult)
    if deleteresult:
        msg = "删除失败,失败原因:" + deleteresult
    else:
        try:
            container = Container.objects.get(containerid__startswith=containerid).delete()  # 删除数据库
            ContainerIp.objects.filter(ip=containerip).update(used=0)
            if sumc == 6:
                print("使用达到6个cpu")
                Format.objects.filter(ip__ip=dockerip).filter(usedcpu=cpun).update(cnumber=sumc - 1)
                Format.objects.filter(ip__ip=dockerip).filter(usedcpu=cpun).filter(ifexit=1).update(ifexit=0)
                msg = "删除容器成功"
            else:
                print("使用没有达到6个cpu")
                Format.objects.filter(ip__ip=dockerip).filter(usedcpu=cpun).update(cnumber=sumc - 1)
                msg = "删除容器成功"
            # container = Container.objects.filter(containerid=containerid).delete()
        except:
            msg = "数据库查询有问题"
            # print(msg)
    return HttpResponseRedirect("/containers/list/?p1=%s" % (msg))