예제 #1
0
def osinstallrefresh(request, id):
    from apps.networkcenter.shortcut import get_device_ip, get_osinstall, get_device_mac

    os = OSInstallQueue.objects.get(id=id)
    d = Device.objects.get(sn=os.sn)
    (os.install, os.ilo_ip, os.os_ip, os.eth0_mac) = (get_osinstall(d.sn), get_device_ip(d, "ilo"),
                                                      get_device_ip(d, "bond0"), get_device_mac(d))
    if os.install and os.ilo_ip and os.os_ip and os.eth0_mac:
        os.save()
        return HttpResponse(json.dumps({"code": 1, "message": 1}))
    else:
        return HttpResponse(json.dumps({"code": 0, "message": 1}))
예제 #2
0
def osinstall(request):
    index = 'cobbler'
    uname = request.user.username
    if request.method == "POST":
        form = OSInstallQueueForm(request.POST)
        if form.is_valid():
            instance = form.save()
            desc = request.POST.get("description")
            unavailable_device = []
            from apps.networkcenter.shortcut import get_device_ip, get_osinstall, get_device_mac
            batch = "%s%s%s" % (time.strftime("%Y%m%d%H%M%S"), uname.upper(), instance.needs_user.username.upper())
            batch_instance = OSInstallTask.objects.get_or_create(batch_name=batch, description=desc)[0]
            for sn in [sn for sn in instance.sn.split("\r\n") if sn != ""]:
                try:
                    d = Device.objects.get(sn=sn)
                except Device.DoesNotExist:
                    d = None
                try:
                    #判断装机任务是否已经存在 and 是否有人已经提交
                    os = OSInstallQueue.objects.get(Q(sn=d.sn) & ~Q(status="11"))
                except Exception, e:
                    os = None
                if not d.status and not os:
                    os = OSInstallQueue(sn=d.sn, tp_type=instance.tp_type, install=get_osinstall(d.sn),
                                        create_user=uname, ilo_ip=get_device_ip(d, "ilo"),
                                        os_ip=get_device_ip(d, "bond0"), eth0_mac=get_device_mac(d),
                                        needs_user=instance.needs_user, batch=batch_instance)
                    os.save()
                    d.status = True
                    d.save()
                else:
                    unavailable_device.append(sn)
            return HttpResponse(json.dumps({"code": 1, "message": {"unavailable_device": unavailable_device}}))
        else:
            return HttpResponse(json.dumps({"code": 0, "message": {"sn": form['sn'].errors,
                                                                   "needs_user": form["needs_user"].errors,
                                                                   "description": form["description"].errors}}))