Пример #1
0
def equip_api(request):  #下面客户传来的数据接收并存库
    result = {"statue": "error", "data": ""}
    if request.method == "POST":
        requestData = request.POST
        hostname = requestData.get("hostname")
        mac = requestData.get("mac")
        ip = request.META["REMOTE_ADDR"]
        system_type = requestData.get("version")
        memory = requestData.get("memory")
        disk = requestData.get("disk")
        cpu_count = requestData.get("cpu_count")
        system_version = requestData.get("system")
        try:
            eq = Equipment()
            eq.hostname = hostname
            eq.mac = mac
            eq.ip = ip
            eq.sys_type = system_type
            eq.memory = memory
            eq.disk = disk
            eq.cpu_count = cpu_count
            eq.sys_version = system_version
            eq.save()
        except Exception as e:
            result["data"] = str(e)
        else:
            result["statue"] = "success"
            result["data"] = "your data is saved"
    else:
        result["data"] = "request must be post"
    return JsonResponse(result)
Пример #2
0
def add_eq(request):
    for i in range(100):
        e = Equipment()
        e.hostname = "localhost_%s" % i
        e.IP = "192.168.1.%s" % (i + 2)
        e.System = random.choice([
            "win7_32",
            "win7_64",
            "centos.6_32",
            "centos.7",
        ])
        e.Statue = random.choice(["True", "False"])
        e.Mac = random.choice(["00:0c:29:92:85:4e", "00:0c:29:5b:2a:a1"])
        e.user = "******"
        e.Password = "******"
        e.save()
    return JsonResponse({"statue": "ahh"})