def table_idc_add(request, app_name, model_name): print('request', request) print('app_name', app_name) print('model_name', model_name) admin_class = admin_func().get('idc') print('admin_class-', admin_class) form = forms.create_dynamic_modelform(admin_class.model) print('form--', form()) if request.method == "GET": print('IS GET') form_obj = form() print('form_obj-GET', form_obj) elif request.method == "POST": print('is post----') form_obj = form(data=request.POST) print('form-obj', form_obj.is_valid()) if form_obj.is_valid(): print('form_obj--save', form_obj.save) form_obj.save() print('POST 执行return', form_obj) return redirect("/idc/") print('GET 执行return') return render(request, 'list/idc_add.html', locals())
def table_group_edit(request, app_name, object_id): print('编辑', request) # print('admin_class',admin_class) # print('admin_class类型',type(admin_class)) print('object_id', object_id) # admin_class = admin_func().get('hostgroup') if app_name in site.registered_admins: admin_class = site.registered_admins[app_name].get('hostgroup') object = admin_class.model.objects.get(id=object_id) form = forms.create_dynamic_modelform(admin_class.model) print('form--', form()) print('form--', dir(form())) if request.method == "GET": print('编辑---GET', form()) form_obj = form(instance=object) elif request.method == "POST": print('编辑---POST') form_obj = form(instance=object, data=request.POST) print('编辑---form_obj', form_obj.is_valid()) if form_obj.is_valid(): print('执行保存---') form_obj.save() return redirect('/host_group/') print('保存失败--') return render(request, 'host_info/table_object_change.html', locals())
def table_obj_edit(request, app_name, model_name, object_id): print('编辑', request) if app_name in site.registered_admins: if model_name in site.registered_admins[app_name]: admin_class = site.registered_admins[app_name][model_name] object = admin_class.model.objects.get(id=object_id) form = forms.create_dynamic_modelform(admin_class.model) print('form--', form()) print('form--', dir(form())) if request.method == "GET": print('编辑---GET', form()) form_obj = form(instance=object) print('form_obj-----', form_obj.instance) print('form_obj-----', dir(form_obj.instance)) elif request.method == "POST": print('编辑---POST') form_obj = form(instance=object, data=request.POST) print('编辑---form_obj', form_obj.is_valid()) if form_obj.is_valid(): print('执行保存---') form_obj.save() return redirect('/host_list/') print('保存失败--') return render(request, 'list/host_edit.html', locals())
def master_add(request, app_name, model_name): print('集群app_name', app_name) print('集群model_name', model_name) admin_class = admin_func().get('master') form = forms.create_dynamic_modelform(admin_class.model) if request.method == "GET": print('IS GET') form_obj = form() print('form_obj-GET', form_obj) for field in form_obj: print('field-dir', dir(field.field)) print('field-dir-verbose_name', field.label) elif request.method == "POST": print('is post----') form_obj = form(data=request.POST) print('集群form-obj----', form_obj) print('验证集群信息') if form_obj.is_valid(): print('验证通过,开始保存') form_obj.save() print('集群信息保存成功,跳转至主机组页面') return redirect('/host_group/') else: print('集群信息验证失败') return render(request, 'list/host_group_add.html', locals())
def sys_settings(request): print('request', request) for app_name in site.registered_admins: if app_name in site.registered_admins: admin_class = site.registered_admins[app_name].get('email') object = admin_class.model.objects.get(id='1') form = forms.create_dynamic_modelform(admin_class.model) if request.method == 'GET': form_obj = form(instance=object) elif request.method == 'POST': print('request-post', request) form_obj = form(instance=object, data=request.POST) if form_obj.is_valid(): form_obj.save() return redirect('/sys_settings/') # print('设置admin',admin_class) # form = forms.create_dynamic_modelform(admin_class.model) # if request.method == "GET": # form_obj = form() # elif request.method == "POST": # form_obj = form(data=request.POST) # if form_obj.is_valid(): # form_obj.save() # return redirect('/sys_settings/') return render(request, 'host_setting/settings.html', locals())
def table_obj_add(request, app_name, model_name): print('request', request) print('app_name', app_name) print('model_name', model_name) if app_name in site.registered_admins: print('app_name in site') if model_name in site.registered_admins[app_name]: print('model_name in site[app_name]') admin_class = site.registered_admins[app_name][model_name] print('admin_class-', admin_class) form = forms.create_dynamic_modelform(admin_class.model) print('form--', form()) if request.method == "GET": print('IS GET') form_obj = form() elif request.method == "POST": print('is post----') form_obj = form(data=request.POST) print('form-obj', form_obj.is_valid()) if form_obj.is_valid(): print('form_obj--save', form_obj.save) form_obj.save() print('POST 执行return', form_obj) return redirect("/host_list/") print('GET 执行return') return render(request, 'host_monitor/table_object_add.html', locals())
def host_group_add(request, app_name): print('request', request) print('app_name', app_name) for host_group in app_name: if host_group in app_name: host_group = site.registered_admins[app_name] host_group = site.registered_admins[app_name].get('hostgroup') print('host_group------', host_group) form = forms.create_dynamic_modelform(host_group.model) if request.method == "GET": print('IS GET') form_obj = form() elif request.method == "POST": print('is post----') form_obj = form(data=request.POST) # print('form-obj',form_obj.is_valid()) if form_obj.is_valid(): form_obj.save() return redirect('/host_group/') return render(request, 'host_group_add.html', locals())
def master_ns_add(request, app_name, model_name): # print('admin_class-ADD',admin_class) admin_class = admin_func().get('namespaces') form = forms.create_dynamic_modelform(admin_class.model) if request.method == "GET": print('IS GET') form_obj = form() print('form_obj-GET', form_obj) for field in form_obj: print('field-dir', dir(field.field)) print('field-dir-verbose_name', field.label) elif request.method == "POST": print('is post----') form_obj = form(data=request.POST) print('命名空间form-obj----', form_obj) print('验证命名空间') if form_obj.is_valid(): print('验证通过,开始保存') form_obj.save() print('命名空间保存成功,跳转至主机组页面') return redirect('/master_ns_list/') else: print('命名空间信息验证失败') return render(request, 'list/master_ns_add.html', locals())
def host_monitor_list(request): print('request', request) admin_class = admin_func().get('monitor') monitor_data = admin_class.model.objects.all() print('获取主机列表') host_list = monitor_data.values('hostname__ip_address').distinct() form = forms.create_dynamic_modelform(admin_class.model) if request.method == "GET": form_obj = form() elif request.method == "POST": print('POST请求') print('定义当前时间') print('获取主机IP') host_ip = request.POST.get("host_ip") print("获取时间") data_func = request.POST.get("func_data") print("获取到的时间:", data_func) if data_func == 'now_data': print('开始获取主机ID') id_list = monitor_data.filter( hostname__ip_address=host_ip).values('id').last() print("主机ID获取成功,开始获取数据") data = {} for index, id_info in enumerate(id_list): host_info = monitor_data.filter(id=id_list.get('id')) print('host_info----', host_info) for info in host_info: cpu_use = info.cpu_use ram_use = info.ram_use.split('%')[0] disk_use = info.disk_use.split('%')[0] host_input = info.host_input host_output = info.host_output time = info.date.strftime('%Y-%m-%d %H:%M:%S') data.update({ index: { 'cpu_use': cpu_use, 'ram_use': ram_use, 'disk_use': disk_use, 'host_input': host_input, 'host_output': host_output, 'host_date': time } }) print('data数据2', data) return HttpResponse(json.dumps(data)) elif data_func == 'three_data': print("主机ID获取成功,开始获取主机3天数据") day_count = 3 host_date = date_function(monitor_data, host_ip, day_count) print('3天数据', host_date) return HttpResponse(json.dumps(host_date)) elif data_func == 'seven_data': print("主机ID获取成功,开始获取主机3天数据") day_count = 7 host_date = date_function(monitor_data, host_ip, day_count) print('7天数据', host_date) return HttpResponse(json.dumps(host_date)) elif data_func == 'thirty_data': print("主机ID获取成功,开始获取主机30天数据") day_count = 30 host_date = date_function(monitor_data, host_ip, day_count) print('30天数据', host_date) return HttpResponse(json.dumps(host_date)) return render(request, 'monitor/host_monitor_list.html', locals())