Example #1
0
def new_room(request):
    name_tips = ""
    insert = {}
    if request.method == 'POST':
        room_name = request.REQUEST.get('room_name')
        room_addr = request.REQUEST.get('room_addr')
        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))

        insert = {"room_name": room_name, 'room_addr': room_addr}
        rm = roommodel()
        isF = isexist(rm, 'room_name', room_name)
        if isF == 1 and editor == 0:
            name_tips = "名称重复"

        elif room_name is not None and room_addr is not None:
            if editor and id:
                room_id = rm.update(insert, {"id": id})
            else:

                room_id = rm.insert(insert)
            if room_id:
                return HttpResponseRedirect("/room_list/?p=" +
                                            str(editor_current_page))
        else:
            name_tips = "参数错误"
    return render(request, 'room/new_room.html', {
        "val": insert,
        "name_tips": name_tips
    })
Example #2
0
def getNetwork_configById(request):
    id = request.REQUEST.get('id', None)
    result = {}
    if id is None or id == 0:
        return HttpResponse(json.dumps(result),
                            content_type="application/json")

    key_list = [
        'id', 'device_name', 'idc_name', 'manage_ip', 'other_ip', 'dev_type',
        'dev_ports', 'sn', 'an', 'units', 'rack_number', 'rack_units'
    ]
    # sql = Sql.get_s_sql('network_config', key_list, {"id": id})
    nw = networkingmodel()
    r = nw.find({"id": id})
    result = Query.fSqlResult(r, key_list)

    key_list = ['id', 'room_name']
    # sql = Sql.get_s_sql('room', key_list, {})
    rm = roommodel()
    r = rm.find({})
    room = Query.fSqlResult(r, key_list)

    key_list_1 = ['id', 'idc_name']
    # sql_1 = Sql.get_s_sql('idc', key_list_1, {})
    rk = rackmodel()
    r_1 = rk.find({})
    idc = Query.fSqlResult(r_1, key_list_1)

    ret = {'result': result[0], 'idc': idc, 'room': room}
    return HttpResponse(json.dumps(ret), content_type="application/json")
Example #3
0
def deleteRoomById(request):
    id = request.REQUEST.get('id', None)
    result = {"ret": "delete faild"}
    if id:
        rm = roommodel()
        r = rm.delete({"id": id})
        result = {"ret": "delete success"}

    return HttpResponse(json.dumps(result), content_type="application/json")
Example #4
0
def room_list(request):
    key_list = ['id', 'room_name', 'room_addr']

    rm = roommodel()
    r = rm.find({})
    print r
    result = Query.fSqlResult(r, key_list)
    print result
    return render(request, 'room/room_list.html', {'ret': result})
Example #5
0
def getServerById(request):
    id = request.REQUEST.get('id', None)
    result = {}
    if id is None or id == 0:
        return HttpResponse(json.dumps(result),
                            content_type="application/json")

    key_list = [
        'id', 'hostname', 'manage_ip', 'other_ip', 'app_name',
        'system_version', 'zabbix_template', 'owner_group', 'server_type',
        'cpu', 'mem', 'disk', 'sn', 'an', 'units', 'idc_name', 'rack_number',
        'rack_units', 'create_date', 'end_date', 'switch_name', 'switch_port',
        'change_time', 'change_dev_info', 'change_people', 'description',
        'status'
    ]
    # sql = Sql.get_s_sql('server', key_list, {"id": id})
    sv = servermodel()
    r = sv.find({"id": id})
    result = Query.fSqlResult(r, key_list)

    key_list = ['id', 'room_name']
    # sql = Sql.get_s_sql('room', key_list, {})
    rm = roommodel()
    r = rm.find({})
    room = Query.fSqlResult(r, key_list)

    key_list_1 = ['id', 'idc_name']
    # sql_1 = Sql.get_s_sql('idc', key_list_1, {})
    rk = rackmodel()
    r = rk.find({})
    idc = Query.fSqlResult(r_1, key_list_1)

    key_list_2 = ['id', 'device_name']
    # sql_2 = Sql.get_s_sql('network_config', key_list_2, {})
    nw = networkingmodel()
    r_2 = nw.find({})
    network = Query.fSqlResult(r_2, key_list_2)

    ret = {
        'result': result[0],
        'idc': idc,
        'room': room,
        'owner_group': ServerGroup.group,
        'server_type': ServerGroup.type,
        'network': network
    }
    print "ret=" + str(ret)
    return HttpResponse(json.dumps(ret), content_type="application/json")
Example #6
0
def new_rack_config(request):
    if request.method == 'POST':
        idc_name = request.REQUEST.get('idc_name')
        rack_number = request.REQUEST.get('rack_number')
        start_time = request.REQUEST.get('start_time')
        end_time = request.REQUEST.get('end_time')
        service_provider = request.REQUEST.get('service_provider')
        print idc_name, rack_number, start_time, end_time, service_provider
        if idc_name is not None and rack_number is not None:
            start_time = time.strptime(start_time, "%Y-%m-%d %H:%M:%S")
            end_time = time.strptime(end_time, "%Y-%m-%d %H:%M:%S")
            start_time = time.mktime(start_time)
            end_time = time.mktime(end_time)
            if start_time > end_time:
                return

            insert = {
                "idc_name": idc_name,
                'rack_number': rack_number,
                'start_time': start_time,
                'end_time': end_time,
                'service_provider': service_provider
            }
            table = 'idc'
            rk = rackmodel()
            rack_id = rk.insert(insert)

            if rack_id:
                return HttpResponseRedirect("/rack_list/")
    else:
        pass

    key_list = ['id', 'room_name']
    rm = roommodel()
    r = rm.find({})
    result = Query.fSqlResult(r, key_list)
    key_list_1 = ['id', 'idc_name']

    # sql_1 = Sql.get_s_sql('idc', key_list_1, {})

    rk = rackmodel()
    r_1 = rk.find({})
    result_1 = Query.fSqlResult(r_1, key_list_1)
    return render(request, 'new__config.html', {
        'room_list': result,
        'rack_list': result_1
    })
Example #7
0
def getRoomById(request):
    id = request.REQUEST.get('id', None)
    result = {}
    if id is None or id == 0:
        return HttpResponse(json.dumps(result),
                            content_type="application/json")
    rm = roommodel()

    key_list = ['id', 'room_name', 'room_addr']

    r = rm.find({"id": id})

    result = Query.fSqlResult(r, key_list)

    ret = {'result': result[0]}

    return HttpResponse(json.dumps(ret), content_type="application/json")
Example #8
0
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
        })
Example #9
0
def ajaxroomlist(request):
    page = request.REQUEST.get('p', 1)

    pageSize = request.REQUEST.get('pageSize', 6)

    key_list = ['id', 'room_name', 'room_addr']

    rm = roommodel()
    r = rm.find({})
    result = Query.fSqlResult(r, key_list)
    # rk = rackmodel()
    totalPage = rm.count({})

    if totalPage % pageSize:
        totalPage = totalPage / pageSize + 1
    else:
        totalPage = totalPage / pageSize

    head = {
        'a_id': "自增序号",
        'b_room_name': "机房名称",
        'c_room_addr': "机房所在地址",
        "d_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")
Example #10
0
def new_server(request):
    name_tips = ""
    insert = {}
    if request.method == 'POST':
        idc_name = request.REQUEST.get('idc_name')
        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')
        server_type = request.REQUEST.get('server_type')
        cpu = request.REQUEST.get('cpu')
        mem = request.REQUEST.get('mem')
        disk = request.REQUEST.get('disk')
        sn = request.REQUEST.get('sn')
        an = request.REQUEST.get('an')
        units = request.REQUEST.get('units')
        rack_number = request.REQUEST.get('rack_number')
        rack_units = request.REQUEST.get('rack_units')
        create_date = request.REQUEST.get('create_date')
        end_date = request.REQUEST.get('end_date')
        switch_name = request.REQUEST.get('switch_name')
        switch_port = request.REQUEST.get('switch_port')
        # change_time = request.REQUEST.get('change_time',None)
        change_dev_info = request.REQUEST.get('change_dev_info', None)
        change_people = request.REQUEST.get('change_people', None)
        description = request.REQUEST.get('description')
        status = request.REQUEST.get('status')
        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))

        sv = servermodel()

        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,
            'server_type': server_type,
            'cpu': cpu,
            'mem': mem,
            'disk': disk,
            'sn': sn,
            'an': an,
            'units': units,
            'rack_number': rack_number,
            'rack_units': rack_units,
            'create_date': create_date,
            'end_date': end_date,
            'switch_name': switch_name,
            'switch_port': switch_port,
            'description': description,
            'status': status,
            'idc_name': idc_name
        }
        table = 'server'
        isF = isexist(table, 'hostname', hostname)
        if isF == 1 and editor == 0:
            name_tips = "名称重复"
        elif hostname and manage_ip:
            if editor and id:
                insert['change_time'] = time.time()
            if change_dev_info:
                insert['change_dev_info'] = change_dev_info
            if change_people:
                insert['change_people'] = change_people

            if editor and id:
                afeck_row = sv.update(insert, {"id": id})
            else:
                afeck_row = sv.insert(insert)

            if afeck_row:
                return HttpResponseRedirect("/server/?p=" +
                                            str(editor_current_page))
        else:
            name_tips = "参数错误"

    key_list = ['id', 'room_name']
    # sql = Sql.get_s_sql('room', key_list, {})
    rm = roommodel()
    r = rm.find({})
    result = Query.fSqlResult(r, key_list)
    key_list_1 = ['id', 'idc_name']

    # sql_1 = Sql.get_s_sql('idc', key_list_1, {})
    rk = rackmodel()
    r_1 = rk.find({})
    result_1 = Query.fSqlResult(r_1, key_list_1)

    server_group = ServerGroup.group
    server_type = ServerGroup.type
    key_list_2 = [
        'id', 'idc_name', 'manage_ip', 'other_ip', 'dev_type', 'dev_ports',
        'sn', 'an', 'units', 'rack_number', 'rack_units'
    ]
    # sql_2 = Sql.get_s_sql('network_config', key_list_2, {})
    nw = networkingmodel()

    r_2 = nw.find({})

    result_2 = Query.fSqlResult(r_2, key_list_2)

    return render(
        request, 'server/new_server.html', {
            'server_group': server_group,
            'server_type': server_type,
            'room_list': result,
            'rack_list': result_1,
            'network': result_2,
            "val": insert,
            "name_tips": name_tips
        })
Example #11
0
def ajax_network_config(request):
    page = request.REQUEST.get('p', 1)
    pageSize = request.REQUEST.get('pageSize', 6)

    key_list = [
        'id', 'device_name', 'idc_name', 'manage_ip', 'other_ip', 'dev_type',
        'dev_ports', 'sn', 'an', 'units', 'rack_number', 'rack_units'
    ]

    nw = networkingmodel()
    r = nw.find({})
    result = Query.fSqlResult(r, key_list)

    totalPage = nw.count({})

    if totalPage % pageSize:
        totalPage = totalPage / pageSize + 1
    else:
        totalPage = totalPage / pageSize

    key_list = ['id', 'room_name']
    # sql = Sql.get_s_sql('room', key_list, {})
    rm = roommodel()
    r = rm.find({})
    room = Query.fSqlResult(r, key_list)

    key_list_1 = ['id', 'idc_name']
    # sql_1 = Sql.get_s_sql('idc', key_list_1, {})
    rk = rackmodel()
    r_1 = rk.find({})
    idc = Query.fSqlResult(r_1, key_list_1)

    head = {
        'a_id': "自增序号",
        'b_device_name': "设备名称",
        'c_idc_name': "所在机房",
        'd_manage_ip': "管理IP",
        'e_other_ip': "非管理IP",
        'j_rack_number': "所在机柜",
        'k_rack_units': "机柜编号",
        "x_oper": "操作"
    }
    new_room = {}
    for j in room:
        new_room[j['id']] = j['room_name']
    new_idc = {}
    for k in idc:
        new_idc[k['id']] = k['idc_name']
    new_result = []
    for item in result:
        if new_room.has_key(item['idc_name']):
            item['idc_name'] = new_room[item['idc_name']]
        if new_idc.has_key(item['rack_number']):
            item['rack_number'] = new_idc[item['rack_number']]
        new_result.append(item)
    ret = {
        "body": new_result,
        "head": head,
        "idc": idc,
        'room': room,
        "page": {
            "current": page,
            "totalpage": totalPage,
            "lastpage": totalPage
        }
    }
    return HttpResponse(json.dumps(ret, sort_keys=True),
                        content_type="application/json")
Example #12
0
def new_network_config(request):
    name_tips = ""
    insert = {}
    if request.method == 'POST':
        device_name = request.REQUEST.get('device_name')
        idc_name = request.REQUEST.get('idc_name')
        manage_ip = request.REQUEST.get('manage_ip')
        other_ip = request.REQUEST.get('other_ip')
        dev_type = request.REQUEST.get('dev_type')
        dev_ports = request.REQUEST.get('dev_ports')
        sn = request.REQUEST.get('sn')
        an = request.REQUEST.get('an')
        units = request.REQUEST.get('units')
        rack_number = request.REQUEST.get('rack_number')
        rack_units = request.REQUEST.get('rack_units')
        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))

        insert = {
            'device_name': device_name,
            "idc_name": idc_name,
            'manage_ip': manage_ip,
            'other_ip': other_ip,
            'dev_type': dev_type,
            'dev_ports': dev_ports,
            'sn': sn,
            'an': an,
            'units': units,
            'rack_number': rack_number,
            'rack_units': rack_units
        }

        table = 'network_config'
        nw = networkingmodel()
        isF = isexist(nw, 'device_name', device_name)
        if isF == 1 and editor == 0:
            name_tips = "名称重复"
        elif idc_name is not None and rack_number is not None:
            if editor and id:
                rack_id = nw.update(insert, {"id": id})
            else:

                rack_id = nw.insert(insert)

            if rack_id:
                return HttpResponseRedirect("/network_config/?p" +
                                            str(editor_current_page))
        else:
            name_tips = "参数错误"

    rm = roommodel()
    key_list = ['id', 'room_name']
    r = rm.find({})
    result = Query.fSqlResult(r, key_list)

    key_list_1 = ['id', 'idc_name']
    rk = rackmodel()
    r_1 = rk.find({})
    result_1 = Query.fSqlResult(r_1, key_list_1)
    return render(
        request, 'network/new_network_config.html', {
            'room_list': result,
            'rack_list': result_1,
            "name_tips": name_tips,
            "val": insert
        })