Exemple #1
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")
Exemple #2
0
def deleteNetwork_configById(request):
    id = request.REQUEST.get('id', None)
    page = request.REQUEST.get('p', 1)
    result = {"ret": "delete faild"}
    if id:

        # sql = Sql.get_d_sql('network_config', {"id": id})
        nw = networkingmodel()
        r = nw.delete({"id": id})
        result = {"ret": "delete success"}
    else:
        return HttpResponse(json.dumps(result),
                            content_type="application/json")
    return HttpResponse(json.dumps(result), content_type="application/json")
Exemple #3
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")
Exemple #4
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
        })
Exemple #5
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")
Exemple #6
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
        })