예제 #1
0
def services_install_setup_node(request):
    """安装系统"""
    content = {}
    if request.method == 'POST':
        node_hostname = request.POST
        hostname_id = node_hostname.getlist("hostname_id")
        for i in hostname_id:
            host_list = Host.objects.get(uuid=str(i))
            # 向pxe提交数据
            pxe_url = pxe_url_api + "create-physical-instances"
            pxe_data = pxe_api({
                "ip": host_list.eth1,
                "mac": host_list.mac,
                "brand": host_list.brand,
            }, pxe_url)

            test = pxe_data.run()
            pxe_post_data = json.loads(test)
            print pxe_post_data
            if pxe_post_data["status"] == 200:
                host_list.status = 2
                # host_list.save()
                content["return"] = True
                content["result"] = pxe_post_data["result"]
                content.update(csrf(request))
                return render_to_response('autoinstall/auto_setup_system_error.html', locals(), context_instance=RequestContext(request))
            else:
                content["return"] = False
                content["result"] = pxe_post_data["result"]
                host_list.status = 0
                host_list.save()
                content.update(csrf(request))
                return render_to_response('autoinstall/auto_setup_system_error.html', locals(), context_instance=RequestContext(request))
    return render_to_response('autoinstall/install_list.html', content, context_instance=RequestContext(request))
예제 #2
0
def services_install_all(request):
    content = {}
    server_list = Host.objects.filter(status=0).order_by("-create_time")
    server_type = Project.objects.all()
    content["server_type"] = server_type
    content["list"] = server_list
    if request.method == 'POST':
        node_hostname = request.POST
        hostname_id = node_hostname.getlist("hostname_id")
        setup_error = []
        for i in hostname_id:
            host_list = Host.objects.get(id=i)
            '''向pxe提交数据'''
            pxe_url = pxe_url_api + "create-physical-instances"
            pxe_data = pxe_api(
                {
                    "hostname": host_list.node_name.strip(),
                    "operating": host_list.system.lower() + "_6u4_64".strip(),
                    "mac": host_list.mac.strip(),
                    "usage": host_list.usage,
                    "model": host_list.brand.lower().strip(),
                }, pxe_url)
            pxe_post_data = json.loads(pxe_data.run())
            if pxe_post_data["status"] == 200:
                host_list.status = 1
                host_list.save()
            else:
                setup_error.append(pxe_post_data)
                host_list.status = 0
                host_list.save()
        content["error"] = True
        content["data"] = setup_error
        content.update(csrf(request))
        if "jumeiops" in request.request.user.department or "admin" in request.user.department:
            return render_to_response('autoinstall/install_system.html',
                                      content,
                                      context_instance=RequestContext(request))
        else:
            return render_to_response('user/auth_error_index.html',
                                      content,
                                      context_instance=RequestContext(request))
    return render_to_response('autoinstall/install_system.html',
                              content,
                              context_instance=RequestContext(request))
예제 #3
0
def services_install_setup_node(request):
    """安装系统"""
    content = {}
    if request.method == 'POST':
        node_hostname = request.POST
        hostname_id = node_hostname.getlist("hostname_id")
        for i in hostname_id:
            host_list = Host.objects.get(uuid=str(i))
            # 向pxe提交数据
            pxe_url = pxe_url_api + "create-physical-instances"
            pxe_data = pxe_api(
                {
                    "ip": host_list.eth1,
                    "mac": host_list.mac,
                    "brand": host_list.brand,
                }, pxe_url)

            test = pxe_data.run()
            pxe_post_data = json.loads(test)
            print pxe_post_data
            if pxe_post_data["status"] == 200:
                host_list.status = 2
                # host_list.save()
                content["return"] = True
                content["result"] = pxe_post_data["result"]
                content.update(csrf(request))
                return render_to_response(
                    'autoinstall/auto_setup_system_error.html',
                    locals(),
                    context_instance=RequestContext(request))
            else:
                content["return"] = False
                content["result"] = pxe_post_data["result"]
                host_list.status = 0
                host_list.save()
                content.update(csrf(request))
                return render_to_response(
                    'autoinstall/auto_setup_system_error.html',
                    locals(),
                    context_instance=RequestContext(request))
    return render_to_response('autoinstall/install_list.html',
                              content,
                              context_instance=RequestContext(request))
예제 #4
0
def services_install_all(request):
    content = {}
    server_list = Host.objects.filter(status=0).order_by("-create_time")
    server_type = Project.objects.all()
    content["server_type"] = server_type
    content["list"] = server_list
    if request.method == 'POST':
        node_hostname = request.POST
        hostname_id = node_hostname.getlist("hostname_id")
        setup_error = []
        for i in hostname_id:
            host_list = Host.objects.get(id=i)
            '''向pxe提交数据'''
            pxe_url = pxe_url_api + "create-physical-instances"
            pxe_data = pxe_api({
                "hostname": host_list.node_name.strip(),
                "operating": host_list.system.lower() + "_6u4_64".strip(),
                "mac": host_list.mac.strip(),
                "usage": host_list.usage,
                "model": host_list.brand.lower().strip(),
            }, pxe_url)
            pxe_post_data = json.loads(pxe_data.run())
            if pxe_post_data["status"] == 200:
                host_list.status = 1
                host_list.save()
            else:
                setup_error.append(pxe_post_data)
                host_list.status = 0
                host_list.save()
        content["error"] = True
        content["data"]=setup_error
        content.update(csrf(request))
        if "jumeiops" in request.request.user.department or "admin" in request.user.department:
            return render_to_response('autoinstall/install_system.html', content, context_instance=RequestContext(request))
        else:
            return render_to_response('user/auth_error_index.html', content, context_instance=RequestContext(request))
    return render_to_response('autoinstall/install_system.html', content, context_instance=RequestContext(request))