Exemple #1
0
def ipsubnet():
    '''IP子网'''
    role_Permission = getattr(Permission, current_user.role)
    ipsubnet_form = IpSubnetForm()
    sidebarclass = init__sidebar('edititem')
    if request.method == "POST" and \
            role_Permission >= Permission.ALTER_REPLY:
        sidebarclass = init__sidebar('additem')
        if ipsubnet_form.validate_on_submit():
            ipsubnet=IpSubnet(
                 subnet=ipsubnet_form.subnet.data,
                 start_ip=ipsubnet_form.start_ip.data,
                 end_ip=ipsubnet_form.end_ip.data,
                 netmask=ipsubnet_form.netmask.data,
                 site=ipsubnet_form.site.data,
                 sales=ipsubnet_form.sales.data,
                 client=ipsubnet_form.client.data,
                 start_time=ipsubnet_form.start_time.data,
                 expire_time=ipsubnet_form.expire_time.data,
                 remark=ipsubnet_form.remark.data
            )
            db.session.add(ipsubnet)
            db.session.commit()
            value = ("subnet:%s start_ip:%s end_ip:%s netmask:%s"
                     "site:%s sales:%s client:%s start_time:%s"
                     "expire_time:%s remark:%s" 
            ) % (ipsubnet.subnet, ipsubnet.start_ip, ipsubnet.end_ip,
                 ipsubnet.netmask, ipsubnet.site, ipsubnet.sales, ipsubnet.client,
                 ipsubnet.start_time, ipsubnet.expire_time, ipsubnet.remark)
            record_sql(current_user.username, u"创建", u"IP子网",
                       ipsubnet.id, "subnet", value)
            
            flash(u'IP子网添加成功')
        else:
            for key in ipsubnet_form.errors.keys():
                flash(ipsubnet_form.errors[key][0])

    if request.method == "GET":
        search = request.args.get('search', '')
        if search:
            # 搜索
            page = int(request.args.get('page', 1))
            sidebarclass = init__sidebar('edititem')
            res = search_res(IpSubnet, 'subnet', search)
            if res:
                pagination = res.paginate(page, 100, False)
                items = pagination.items
                return render_template(
                    'cmdb/item.html', titles=titles, thead=thead, 
                    endpoint=endpoint, del_page=del_page, change_page=change_page,
                    item_form=ipsubnet_form, sidebarclass=sidebarclass, pagination=pagination,
                    search_value=search, items=items
                )
    
    return render_template(
        'cmdb/item.html', titles = titles, item_form=ipsubnet_form,
        sidebarclass=sidebarclass
    )
Exemple #2
0
def rack():
    '''机架设置'''
    role_Permission = getattr(Permission, current_user.role)
    rack_form = RackForm()
    sidebarclass = init__sidebar('edititem')
    if request.method == "POST" and \
            role_Permission >= Permission.ALTER_REPLY:
        sidebarclass = init__sidebar('additem')
        if rack_form.validate_on_submit():
            rack = Rack(
                rack=rack_form.rack.data,
                site=rack_form.site.data,
                count=rack_form.count.data,
                power=rack_form.power.data,
                sales=rack_form.sales.data,
                client=rack_form.client.data,
                start_time=rack_form.start_time.data,
                expire_time=rack_form.expire_time.data,
                remark=rack_form.remark.data
            )
            db.session.add(rack)
            db.session.commit()
            value = (
                "rack:%s site:%s count:%s power:%s sales:%s client:%s"
                "start_time:%s expire_time:%s remark:%s"
            ) % (rack.rack, rack.site, rack.count, rack.power, rack.sales,
                 rack.client, rack.start_time, rack.expire_time, rack.remark)
            record_sql(current_user.username, u"创建", u"机架", rack.id, "rack", value)
            flash(u'机柜添加成功')
        else:
            for key in rack_form.errors.keys():
                flash(rack_form.errors[key][0])

    if request.method == "GET":
        search = request.args.get('search', '')
        if search:
            # 搜索
            page = int(request.args.get('page', 1))
            sidebarclass = init__sidebar('edititem')
            res = search_res(Rack, 'rack', search)
            if res:
                pagination = res.paginate(page, 100, False)
                items = pagination.items
                return render_template(
                    'cmdb/item.html', titles=titles, thead=thead, 
                    endpoint=endpoint, del_page=del_page, change_page=change_page,
                    item_form=rack_form, sidebarclass=sidebarclass, pagination=pagination,
                    search_value=search, items=items
                )
    
    return render_template(
        'cmdb/item.html', titles = titles, item_form=rack_form,
        sidebarclass=sidebarclass
    )
Exemple #3
0
def client():
    '''机房设置'''
    role_Permission = getattr(Permission, current_user.role)
    client_form = ClientForm()
    sidebarclass = init__sidebar('edititem')
    if request.method == "POST" and \
            role_Permission >= Permission.ALTER_REPLY:
        sidebarclass = init__sidebar('additem')
        if client_form.validate_on_submit():
            client = Client(username=client_form.username.data,
                            contact=client_form.contact.data,
                            remark=client_form.remark.data)
            db.session.add(client)
            db.session.commit()
            value = ("username:%s contact:%s remark:%s") % (
                client.username, client.contact, client.remark)
            record_sql(current_user.username, u"创建", u"销售", client.id,
                       "client", value)
            flash(u'客户添加成功')
        else:
            for key in client_form.errors.keys():
                flash(client_form.errors[key][0])

    if request.method == "GET":
        search = request.args.get('search', '')
        if search:
            # 搜索
            page = int(request.args.get('page', 1))
            sidebarclass = init__sidebar('edititem')
            res = search_res(Client, 'username', search)
            if res:
                pagination = res.paginate(page, 100, False)
                items = pagination.items
                return render_template('cmdb/item.html',
                                       titles=titles,
                                       thead=thead,
                                       endpoint=endpoint,
                                       del_page=del_page,
                                       change_page=change_page,
                                       item_form=client_form,
                                       sidebarclass=sidebarclass,
                                       pagination=pagination,
                                       search_value=search,
                                       items=items)

    return render_template('cmdb/item.html',
                           titles=titles,
                           item_form=client_form,
                           sidebarclass=sidebarclass)
Exemple #4
0
def client():
    '''机房设置'''
    role_Permission = getattr(Permission, current_user.role)
    client_form = ClientForm()
    sidebarclass = init__sidebar('edititem')
    if request.method == "POST" and \
            role_Permission >= Permission.ALTER_REPLY:
        sidebarclass = init__sidebar('additem')
        if client_form.validate_on_submit():
            client = Client(
                username=client_form.username.data,
                contact=client_form.contact.data,
                remark=client_form.remark.data
            )
            db.session.add(client)
            db.session.commit()
            value = (
                "username:%s contact:%s remark:%s"
            ) % (client.username, client.contact, client.remark)
            record_sql(current_user.username, u"创建", u"销售", client.id, "client", value)
            flash(u'客户添加成功')
        else:
            for key in client_form.errors.keys():
                flash(client_form.errors[key][0])
        
    if request.method == "GET":
        search = request.args.get('search', '')
        if search:
            # 搜索
            page = int(request.args.get('page', 1))
            sidebarclass = init__sidebar('edititem')
            res = search_res(Client, 'username' , search)
            if res:
                pagination = res.paginate(page, 100, False)
                items = pagination.items
                return render_template(
                    'cmdb/item.html', titles=titles, thead=thead, 
                    endpoint=endpoint, del_page=del_page, change_page=change_page, 
                    item_form=client_form, sidebarclass=sidebarclass, pagination=pagination,
                    search_value=search, items=items
                )

    return render_template(
        'cmdb/item.html', titles = titles, item_form=client_form, 
        sidebarclass=sidebarclass
    )
Exemple #5
0
def record():
    '''机房设置'''
    search = request.args.get('search', '')
    if search:
        # 搜索
        page = int(request.args.get('page', 1))
        res = search_res(Record, 'username' , search)
        if res:
            pagination = res.paginate(page, 100, False)
            items = pagination.items
            return render_template(
                'cmdb/record.html', titles=titles, thead=thead, 
                endpoint=endpoint, pagination=pagination,
                search_value=search, items=items
            )

    return render_template(
        'cmdb/record.html', titles = titles, 
    )
Exemple #6
0
def record():
    '''机房设置'''
    search = request.args.get('search', '')
    if search:
        # 搜索
        page = int(request.args.get('page', 1))
        res = search_res(Record, 'username', search)
        if res:
            pagination = res.paginate(page, 100, False)
            items = pagination.items
            return render_template('cmdb/record.html',
                                   titles=titles,
                                   thead=thead,
                                   endpoint=endpoint,
                                   pagination=pagination,
                                   search_value=search,
                                   items=items)

    return render_template(
        'cmdb/record.html',
        titles=titles,
    )
Exemple #7
0
def ippool():
    '''IP池'''
    role_Permission = getattr(Permission, current_user.role)
    ippool_form = IpPoolForm()
    sidebarclass = init__sidebar('edititem')
    if request.method == "POST" and \
            role_Permission >= Permission.ALTER_REPLY:
        sidebarclass = init__sidebar('additem')
        if ippool_form.validate_on_submit():
            ip_list = ippool_form.start_ip.data.split('.')
            fornt_ip = '.'.join(ip_list[:-1])
            start_ip = int(ip_list[-1])
            end_ip = int(ippool_form.end_ip.data) + 1
            for i in range(start_ip, end_ip):
                add_ip = fornt_ip + ".%s" % i
                if not IpPool.query.filter_by(ip=add_ip).first():
                    ippool = IpPool(ip=add_ip,
                                    netmask=ippool_form.netmask.data,
                                    gateway=ippool_form.gateway.data,
                                    subnet=ippool_form.subnet.data,
                                    site=ippool_form.site.data,
                                    client=ippool_form.client.data,
                                    remark=ippool_form.remark.data)
                    db.session.add(ippool)
                    db.session.commit()

                    value = ("ip:%s gateway:%s subnet:%s site:%s"
                             "client:%s remark:%s") % (
                                 ippool.ip, ippool.gateway, ippool.subnet,
                                 ippool.site, ippool.client, ippool.remark)
                    record_sql(current_user.username, u"创建", u"IP池", ippool.id,
                               "ip", value)

                else:
                    flash(u'添加失败 %s 已经添加' % add_ip)
                    break
            flash(u'IP添加成功')

        else:
            for key in ippool_form.errors.keys():
                flash(ippool_form.errors[key][0])

    if request.method == "GET":
        search = request.args.get('search', '')
        if search:
            # 搜索
            page = int(request.args.get('page', 1))
            sidebarclass = init__sidebar('edititem')
            res = search_res(IpPool, 'ip', search)
            if res:
                pagination = res.paginate(page, 100, False)
                items = pagination.items
                return render_template('cmdb/item.html',
                                       titles=titles,
                                       thead=thead,
                                       endpoint=endpoint,
                                       del_page=del_page,
                                       change_page=change_page,
                                       item_form=ippool_form,
                                       sidebarclass=sidebarclass,
                                       pagination=pagination,
                                       search_value=search,
                                       items=items)

    return render_template('cmdb/item.html',
                           titles=titles,
                           item_form=ippool_form,
                           sidebarclass=sidebarclass)
Exemple #8
0
def cabinet():
    '''机柜表'''
    role_Permission = getattr(Permission, current_user.role)
    cabinet_form = CabinetForm()
    sidebarclass = init__sidebar('edititem')
    if request.method == "POST" and \
            role_Permission >= Permission.ALTER_REPLY:
        sidebarclass = init__sidebar('additem')
        if cabinet_form.validate_on_submit():
            cabinet = Cabinet(
                 an = cabinet_form.an.data,
                 wan_ip = cabinet_form.wan_ip.data,
                 lan_ip = cabinet_form.lan_ip.data,
                 site=cabinet_form.site.data,
                 rack=cabinet_form.rack.data,
                 seat=cabinet_form.seat.data,
                 bandwidth=cabinet_form.bandwidth.data,
                 up_link=cabinet_form.up_link.data,
                 height=cabinet_form.height.data,
                 brand=cabinet_form.brand.data,
                 model=cabinet_form.model.data,
                 sn=cabinet_form.sn.data,
                 sales=cabinet_form.sales.data,
                 client=cabinet_form.client.data,
                 start_time=cabinet_form.start_time.data,
                 expire_time=cabinet_form.expire_time.data,
                 remark=cabinet_form.remark.data
            )
            db.session.add(cabinet)
            db.session.commit()
            if cabinet_form.wan_ip.data:
                ip = IpPool.query.filter_by(ip=cabinet_form.wan_ip.data).first()
                ip.client = cabinet_form.client.data
                db.session.add(ip)

            value = ("an:%s wan_ip:%s lan_ip:%s site:%s rack:%s seat:%s"
                    "bandwidth:%s up_link:%s height:%s brand:%s model:%s"
                    "sn:%s sales:%s client:%s start_time:%s expire_time%s remark:%s"
            ) % (cabinet.an, cabinet.wan_ip, cabinet.lan_ip, cabinet.site, 
                 cabinet.rack, cabinet.seat, cabinet.bandwidth, cabinet.up_link,
                 cabinet.height, cabinet.brand, cabinet.model, cabinet.sn,
                 cabinet.sales, cabinet.client, cabinet.start_time, cabinet.expire_time,
                 cabinet.remark)
            record_sql(current_user.username, u"创建", u"机柜表", cabinet.id, "an", value)

            flash(u'设备添加成功')
        else:
            for key in cabinet_form.errors.keys():
                flash(cabinet_form.errors[key][0])

    if request.method == "GET":
        search = request.args.get('search', '')
        if search:
            # 搜索
            page = int(request.args.get('page', 1))
            sidebarclass = init__sidebar('edititem')
            res = search_res(Cabinet, 'an', search)
            if res:
                pagination = res.paginate(page, 100, False)
                items = pagination.items
                return render_template(
                    'cmdb/item.html', titles=titles, thead=thead, 
                    endpoint=endpoint, del_page=del_page, change_page=change_page,
                    item_form=cabinet_form, sidebarclass=sidebarclass, pagination=pagination,
                    search_value=search, items=items
                )
    
    return render_template(
        'cmdb/item.html', titles = titles, item_form=cabinet_form,
        sidebarclass=sidebarclass
    )
Exemple #9
0
def ipsubnet():
    '''IP子网'''
    role_Permission = getattr(Permission, current_user.role)
    ipsubnet_form = IpSubnetForm()
    sidebarclass = init__sidebar('edititem')
    if request.method == "POST" and \
            role_Permission >= Permission.ALTER_REPLY:
        sidebarclass = init__sidebar('additem')
        if ipsubnet_form.validate_on_submit():
            ipsubnet = IpSubnet(subnet=ipsubnet_form.subnet.data,
                                start_ip=ipsubnet_form.start_ip.data,
                                end_ip=ipsubnet_form.end_ip.data,
                                netmask=ipsubnet_form.netmask.data,
                                site=ipsubnet_form.site.data,
                                sales=ipsubnet_form.sales.data,
                                client=ipsubnet_form.client.data,
                                start_time=ipsubnet_form.start_time.data,
                                expire_time=ipsubnet_form.expire_time.data,
                                remark=ipsubnet_form.remark.data)
            db.session.add(ipsubnet)
            db.session.commit()
            value = ("subnet:%s start_ip:%s end_ip:%s netmask:%s"
                     "site:%s sales:%s client:%s start_time:%s"
                     "expire_time:%s remark:%s") % (
                         ipsubnet.subnet, ipsubnet.start_ip, ipsubnet.end_ip,
                         ipsubnet.netmask, ipsubnet.site, ipsubnet.sales,
                         ipsubnet.client, ipsubnet.start_time,
                         ipsubnet.expire_time, ipsubnet.remark)
            record_sql(current_user.username, u"创建", u"IP子网", ipsubnet.id,
                       "subnet", value)

            flash(u'IP子网添加成功')
        else:
            for key in ipsubnet_form.errors.keys():
                flash(ipsubnet_form.errors[key][0])

    if request.method == "GET":
        search = request.args.get('search', '')
        if search:
            # 搜索
            page = int(request.args.get('page', 1))
            sidebarclass = init__sidebar('edititem')
            res = search_res(IpSubnet, 'subnet', search)
            if res:
                pagination = res.paginate(page, 100, False)
                items = pagination.items
                return render_template('cmdb/item.html',
                                       titles=titles,
                                       thead=thead,
                                       endpoint=endpoint,
                                       del_page=del_page,
                                       change_page=change_page,
                                       item_form=ipsubnet_form,
                                       sidebarclass=sidebarclass,
                                       pagination=pagination,
                                       search_value=search,
                                       items=items)

    return render_template('cmdb/item.html',
                           titles=titles,
                           item_form=ipsubnet_form,
                           sidebarclass=sidebarclass)
Exemple #10
0
def cabinet():
    '''机柜表'''
    role_Permission = getattr(Permission, current_user.role)
    cabinet_form = CabinetForm()
    sidebarclass = init__sidebar('edititem')
    if request.method == "POST" and \
            role_Permission >= Permission.ALTER_REPLY:
        sidebarclass = init__sidebar('additem')
        if cabinet_form.validate_on_submit():
            cabinet = Cabinet(an=cabinet_form.an.data,
                              wan_ip=cabinet_form.wan_ip.data,
                              lan_ip=cabinet_form.lan_ip.data,
                              site=cabinet_form.site.data,
                              rack=cabinet_form.rack.data,
                              seat=cabinet_form.seat.data,
                              bandwidth=cabinet_form.bandwidth.data,
                              up_link=cabinet_form.up_link.data,
                              height=cabinet_form.height.data,
                              brand=cabinet_form.brand.data,
                              model=cabinet_form.model.data,
                              sn=cabinet_form.sn.data,
                              sales=cabinet_form.sales.data,
                              client=cabinet_form.client.data,
                              start_time=cabinet_form.start_time.data,
                              expire_time=cabinet_form.expire_time.data,
                              remark=cabinet_form.remark.data)
            db.session.add(cabinet)
            db.session.commit()
            if cabinet_form.wan_ip.data:
                ip = IpPool.query.filter_by(
                    ip=cabinet_form.wan_ip.data).first()
                ip.client = cabinet_form.client.data
                db.session.add(ip)

            value = (
                "an:%s wan_ip:%s lan_ip:%s site:%s rack:%s seat:%s"
                "bandwidth:%s up_link:%s height:%s brand:%s model:%s"
                "sn:%s sales:%s client:%s start_time:%s expire_time%s remark:%s"
            ) % (cabinet.an, cabinet.wan_ip, cabinet.lan_ip, cabinet.site,
                 cabinet.rack, cabinet.seat, cabinet.bandwidth,
                 cabinet.up_link, cabinet.height, cabinet.brand, cabinet.model,
                 cabinet.sn, cabinet.sales, cabinet.client, cabinet.start_time,
                 cabinet.expire_time, cabinet.remark)
            record_sql(current_user.username, u"创建", u"机柜表", cabinet.id, "an",
                       value)

            flash(u'设备添加成功')
        else:
            for key in cabinet_form.errors.keys():
                flash(cabinet_form.errors[key][0])

    if request.method == "GET":
        search = request.args.get('search', '')
        if search:
            # 搜索
            page = int(request.args.get('page', 1))
            sidebarclass = init__sidebar('edititem')
            res = search_res(Cabinet, 'an', search)
            if res:
                pagination = res.paginate(page, 100, False)
                items = pagination.items
                return render_template('cmdb/item.html',
                                       titles=titles,
                                       thead=thead,
                                       endpoint=endpoint,
                                       del_page=del_page,
                                       change_page=change_page,
                                       item_form=cabinet_form,
                                       sidebarclass=sidebarclass,
                                       pagination=pagination,
                                       search_value=search,
                                       items=items)

    return render_template('cmdb/item.html',
                           titles=titles,
                           item_form=cabinet_form,
                           sidebarclass=sidebarclass)
Exemple #11
0
def ippool():
    '''IP池'''
    role_Permission = getattr(Permission, current_user.role)
    ippool_form = IpPoolForm()
    sidebarclass = init__sidebar('edititem')
    if request.method == "POST" and \
            role_Permission >= Permission.ALTER_REPLY:
        sidebarclass = init__sidebar('additem')
        if ippool_form.validate_on_submit():
            ip_list = ippool_form.start_ip.data.split('.')
            fornt_ip = '.'.join(ip_list[:-1])
            start_ip = int(ip_list[-1]) 
            end_ip = int(ippool_form.end_ip.data) + 1
            for i in range(start_ip, end_ip):
                add_ip = fornt_ip + ".%s" % i
                if not IpPool.query.filter_by(ip=add_ip).first():
                    ippool = IpPool(
                        ip = add_ip,
                        netmask=ippool_form.netmask.data,
                        gateway=ippool_form.gateway.data,
                        subnet=ippool_form.subnet.data,
                        site=ippool_form.site.data,
                        client=ippool_form.client.data,
                        remark=ippool_form.remark.data
                    )
                    db.session.add(ippool)
                    db.session.commit()
                    
                    value = ("ip:%s gateway:%s subnet:%s site:%s"
                             "client:%s remark:%s"
                    ) % (ippool.ip, ippool.gateway, ippool.subnet,
                         ippool.site, ippool.client, ippool.remark)
                    record_sql(current_user.username, u"创建", u"IP池",
                               ippool.id, "ip", value)

                else:
                    flash(u'添加失败 %s 已经添加' % add_ip)
                    break
            flash(u'IP添加成功')    
             
        else:
            for key in ippool_form.errors.keys():
                flash(ippool_form.errors[key][0])

    if request.method == "GET":
        search = request.args.get('search', '')
        if search:
            # 搜索
            page = int(request.args.get('page', 1))
            sidebarclass = init__sidebar('edititem')
            res = search_res(IpPool, 'ip', search)
            if res:
                pagination = res.paginate(page, 100, False)
                items = pagination.items
                return render_template(
                    'cmdb/item.html', titles=titles, thead=thead, 
                    endpoint=endpoint, del_page=del_page, change_page=change_page,
                    item_form=ippool_form, sidebarclass=sidebarclass, pagination=pagination,
                    search_value=search, items=items
                )
    
    return render_template(
        'cmdb/item.html', titles = titles, item_form=ippool_form, sidebarclass=sidebarclass
    )