def vm(request): key_list = [ 'id', 'hostname', 'manage_ip', 'other_ip', 'app_name', 'cpu', 'mem', 'disk', 'status', 'hypervisor_host' ] # sql = Sql.get_s_sql('vm', key_list, {}) v = vmmodel() r = v.find({}) result = Query.fSqlResult(r, key_list) return render(request, 'vm/vm.html', {'ret': result})
def deleteVmById(request): id = request.REQUEST.get('id', None) page = request.REQUEST.get('p', 1) result = {"ret": "delete faild"} if id: v = vmmodel() r = v.delete({"id": id}) if r: result = {"ret": "delete success"} return HttpResponse(json.dumps(result), content_type="application/json")
def getVmById(request): id = request.REQUEST.get('id', None) result = {} if id is None or id == 0: return HttpResponse(json.dumps(result), content_type="application/json") v = vmmodel() key_list = [ 'id', 'hostname', 'manage_ip', 'other_ip', 'app_name', 'system_version', 'zabbix_template', 'owner_group', 'cpu', 'mem', 'disk', 'hypervisor_host', 'change_time', 'change_dev_info', 'change_people', 'description', 'status' ] # sql = Sql.get_s_sql('vm', key_list, {"id": id}) r = v.find({{"id": id}}) result = Query.fSqlResult(r, key_list) ret = {'result': result[0], 'owner_group': ServerGroup.group} return HttpResponse(json.dumps(ret), content_type="application/json")
def ajax_vm(request): page = request.REQUEST.get('p', 1) pageSize = request.REQUEST.get('pageSize', 6) key_list = [ 'id', 'hostname', 'manage_ip', 'other_ip', 'app_name', 'system_version', 'zabbix_template', 'owner_group', 'cpu', 'mem', 'disk', 'hypervisor_host', 'change_time', 'change_dev_info', 'change_people', 'description', 'status' ] v = vmmodel() r = v.find({}) result = Query.fSqlResult(r, key_list) totalPage = v.count({}) if totalPage % pageSize: totalPage = totalPage / pageSize + 1 else: totalPage = totalPage / pageSize head = { 'a_id': "自增序号", 'b_hostname': "虚拟主机名称", 'c_manage_ip': "管理IP", 'i_cpu': "CPU", 'j_mem': '内存', 'k_disk': "硬盘", 'l_hypervisor_host': "宿主机地址", 'r_oper': "操作" } ret = { "body": result, "head": head, "page": { "current": page, "totalpage": totalPage, "lastpage": totalPage } } return HttpResponse(json.dumps(ret, sort_keys=True), content_type="application/json")
def index(request): rm = roommodel() rc = rackmodel() sv = servermodel() v = vmmodel() room_num = rm.count({}) rack_num = rc.count({}) server_num = sv.count({}) vm_num = v.count({}) online_num = sv.count({"status": 1}) offline_num = server_num - sv.count({"status": 1}) return render( request, 'index.html', { "room": room_num, 'rack': rack_num, 'server': server_num, 'vm': vm_num, 'online': online_num, 'offline': offline_num })
def new_vm(request): name_tips = "" insert = {} if request.method == 'POST': hostname = request.REQUEST.get('hostname') manage_ip = request.REQUEST.get('manage_ip') other_ip = request.REQUEST.get('other_ip') app_name = request.REQUEST.get('app_name') system_version = request.REQUEST.get('system_version') zabbix_template = request.REQUEST.get('zabbix_template') owner_group = request.REQUEST.get('owner_group') cpu = request.REQUEST.get('cpu') mem = request.REQUEST.get('mem') disk = request.REQUEST.get('disk') change_dev_info = request.REQUEST.get('change_dev_info') change_people = request.REQUEST.get('change_people') description = request.REQUEST.get('description') status = request.REQUEST.get('status') hypervisor_host = request.REQUEST.get('hypervisor_host') editor = int(request.REQUEST.get('editor', 0)) id = int(request.REQUEST.get('id', 0)) editor_current_page = int(request.REQUEST.get('editor_current_page', 1)) v = vmmodel() # table = 'vm' insert = { "hostname": hostname, 'manage_ip': manage_ip, 'other_ip': other_ip, 'app_name': app_name, 'system_version': system_version, 'zabbix_template': zabbix_template, 'owner_group': owner_group, 'cpu': cpu, 'mem': mem, 'disk': disk, 'description': description, 'status': status, 'hypervisor_host': hypervisor_host } if change_dev_info: insert['change_dev_info'] = change_dev_info if change_people: insert['change_people'] = change_people isF = isexist(v, 'hostname', hostname) if isF == 1 and editor == 0: name_tips = "名称重复" elif hostname and manage_ip: if editor and id: insert['change_time'] = time.time() efeck_row = v.update(insert, {"id": id}) else: efeck_row = v.insert(insert) if efeck_row: return HttpResponseRedirect("/vm/?p=" + str(editor_current_page)) else: name_tips = "参数错误" return render(request, 'vm/new_vm.html', { "server_group": ServerGroup.group, "val": insert, "name_tips": name_tips })