Example #1
0
def get_interfaces():
    form = SearchForm(request.args)
    query = Interface.objects(is_deleted=False, is_template=False)

    # 简单搜索
    if form.searchKey.data:
        search_key = form.searchKey.data
        query = query.filter(
            Q(name__contains=search_key) | Q(note__contains=search_key))
        return build_order_by(query, form.orderBy.data), 200

    # 高级搜索
    if form.name.data:
        query = query.filter(name__contains=form.name.data)
    if form.note.data:
        query = query.filter(note__contains=form.note.data)
    if form.location.data:
        query = query.filter(location=form.location.data)
    if form.type.data:
        query = query.filter(type=form.type.data)
    if form.protocol.data:
        query = query.filter(protocol=form.protocol.data)
    if form.createUserId.data:
        query = query.filter(_create_user=form.createUserId.data)
    if form.parentEquipmentId.data:
        query = query.filter(_parent_equipment=form.parentEquipmentId.data)
    if form.parentDeviceId.data:
        query = query.filter(_parent_device=form.parentDeviceId.data)
    if form.createdAtStart.data:
        query = query.filter(created_at__gte=form.createdAtStart.data)
    if form.createdAtEnd.data:
        query = query.filter(created_at__lt=form.createdAtEnd.data)

    current_user.update(inc__search_num=1)
    return build_order_by(query, form.orderBy.data), 200
Example #2
0
def config_func(config):
    global interfaces
    path_set = False

    for node in config.children:
        key = node.key.lower()
        val = node.values[0]

        if key == 'path':
            global PATH
            PATH = val
            path_set = True
        # elif key == 'all':
        #     global track_all
        #     track_all = True
        else:
            interfaces.append(Interface(iface=key, name=val))

    collectd.info('plugin_load: plugin "mwan3track" successfully loaded.')

    # if track_all:
    #     collectd.info('mwan3track: tacking all interfaces')
    for i in interfaces:
        collectd.info('mwan3track: collecting interface %s' % i)

    if path_set:
        collectd.info('mwan3track: Using overridden path %s' % PATH)
    else:
        collectd.info('mwan3track: Using default path %s' % PATH)
Example #3
0
def get_child(oid):
    device = Device.objects(id=oid).count()
    if not device:
        return jsonify(ok=True, msg='not found'), 404
    child_interface = Interface.objects(_parent_device=oid).count()
    child_cable = Cable.objects(Q(_start_device=oid) | Q(_end_device=oid)).count()
    return jsonify(ok=True, msg={'interface': child_interface, 'cable': child_cable})
Example #4
0
def get_child(oid):
    interface = Interface.objects(id=oid).count()
    if not interface:
        return jsonify(ok=True, msg='not found'), 404
    child_cable = Cable.objects(
        Q(_start_interface=oid) | Q(_end_interface=oid)).count()
    return jsonify(ok=True, msg={'cable': child_cable})
Example #5
0
    def load(self, cable):
        cable.name = self.name.data
        cable.signal_type = self.signalType.data
        cable.shield_type = self.shieldType.data
        cable.note = self.note.data
        cable.is_custom = self.isCustom.data
        cable.parameter_list = self.parameterList.data

        try:
            start_interface = Interface.objects().get(
                id=self.startInterfaceId.data)
            start_device = start_interface.parent_device
            start_equipment = start_interface.parent_equipment

        except Interface.DoesNotExist:
            raise FormLoadException('起始接口不存在,id: ' +
                                    str(self.startInterfaceId.data))
        except Device.DoesNotExist:
            raise FormLoadException('起始接口所属的设备不存在,接口id: ' +
                                    str(self.startInterfaceId.data))
        except Equipment.DoesNotExist:
            raise FormLoadException('起始接口所属设备的装置不存在,接口id: ' +
                                    str(self.startInterfaceId.data))
        else:
            cable.start_interface = start_interface.id
            cable.start_device = start_device.id
            cable.start_equipment = start_equipment.id

        try:
            end_interface = Interface.objects().get(
                id=self.endInterfaceId.data)
            end_device = end_interface.parent_device
            end_equipment = end_interface.parent_equipment

        except Interface.DoesNotExist:
            raise FormLoadException('结束接口不存在,id: ' +
                                    str(self.endInterfaceId.data))
        except Device.DoesNotExist:
            raise FormLoadException('结束接口所属的设备不存在,接口id: ' +
                                    str(self.endInterfaceId.data))
        except Equipment.DoesNotExist:
            raise FormLoadException('结束接口所属设备的装置不存在,接口id: ' +
                                    str(self.endInterfaceId.data))
        else:
            cable.end_interface = end_interface.id
            cable.end_device = end_device.id
            cable.end_equipment = end_equipment.id
Example #6
0
def get_interfaces_child():
    form = ObjectIdListForm(request.args)
    ids = form.ids.data
    interface = Interface.objects(id__in=ids).count()
    if not interface:
        return jsonify(ok=True, msg='not found'), 404
    child_cable = Cable.objects(
        Q(_start_interface__in=ids) | Q(_end_interface__in=ids)).count()
    return jsonify(ok=True, msg={'cable': child_cable})
Example #7
0
def get_equipments_child():
    form = ObjectIdListForm(request.args)
    ids = form.ids.data
    equipment = Equipment.objects(id__in=ids).count()
    if not equipment:
        return jsonify(ok=True, msg='not found'), 404
    child_device = Device.objects(_parent_equipment__in=ids).count()
    child_interface = Interface.objects(_parent_equipment__in=ids).count()
    child_cable = Cable.objects(Q(_start_equipment__in=ids) | Q(_end_equipment__in=ids)).count()
    return jsonify(ok=True, msg={'device': child_device, 'interface': child_interface,
                                 'cable': child_cable})
Example #8
0
def recover_cables_recycles(ids):
    cables = Cable.objects(Q(id__in=ids) & Q(is_template=False))
    cables.update(is_deleted=False)  # 恢复线缆自身

    interfaces = [
        interface.id for interface in cables.values_list(
            '_start_interface', '_end_interface')[0]
    ]
    devices = [
        device.id
        for device in cables.values_list('_start_device', '_end_interface')[0]
    ]
    equipments = [
        equipment.id for equipment in cables.values_list(
            '_start_equipment', '_end_interface')[0]
    ]

    Interface.objects(id__in=interfaces).update(is_deleted=False)
    Device.objects(id__in=devices).update(is_deleted=False)
    Equipment.objects(id__in=equipments).update(is_deleted=False)

    return jsonify(ok=True, msg='success')
Example #9
0
def get_nodes():
    return_value = ""
    threads = list()
    for device in json.loads(config['TARGETS']['devices']):
        with concurrent.futures.ThreadPoolExecutor() as executor:
            future = executor.submit(run_cmd, device, "cisco_ios",
                                     config['AUTH']['username'],
                                     config['AUTH']['password'],
                                     "show lldp neighbors detail")
            return_value = future.result()
        neighbors = json.loads(return_value,
                               object_hook=lambda d: SimpleNamespace(**d))
        for i in neighbors:
            nb = i.neighbor.split(".")[0].lower()
            if nb not in nodes:
                nodes[nb] = Node(i.neighbor, i.chassis_id, i.management_ip,
                                 i.capabilities)
            if i.local_interface != "" and i.neighbor_interface != "":
                links[device + "<->" + nb] = Link([
                    Interface(i.local_interface, "", "", "", "", device),
                    Interface(i.neighbor_interface, "", "", "", "", nb)
                ])
Example #10
0
def get_users_meta():
    data = Interface.objects(is_deleted=False,
                             is_template=False).fields(id=1,
                                                       name=1,
                                                       _parent_device=1).all()
    meta = [{
        'id':
        str(item.id),
        'name':
        item.name,
        'parentDeviceId':
        str(item._parent_device.id) if item._parent_device else None,
    } for item in data]
    return jsonify(ok=True, data=meta)
Example #11
0
def recover_interfaces_recycles(ids):
    interfaces = Interface.objects(Q(id__in=ids) & Q(is_template=False))
    interfaces.update(is_deleted=False)  # 恢复接口自身

    devices = [
        device.id for device in interfaces.values_list('_parent_device')
    ]
    equipments = [
        equipment.id
        for equipment in interfaces.values_list('_parent_equipment')
    ]

    Device.objects(id__in=devices).update(is_deleted=False)
    Equipment.objects(id__in=equipments).update(is_deleted=False)
    return jsonify(ok=True, msg='success')
Example #12
0
def get_interfaces():
    threads = list()
    for device in json.loads(config['TARGETS']['devices']):
        with concurrent.futures.ThreadPoolExecutor() as executor:
            future = executor.submit(run_cmd, device, "cisco_ios",
                                     config['AUTH']['username'],
                                     config['AUTH']['password'],
                                     "show interface")
            return_value = future.result()
        ints = json.loads(return_value,
                          object_hook=lambda d: SimpleNamespace(**d))
        for i in ints:
            nodes[device].add_interface(
                Interface(i.interface, i.link_status, i.protocol_status,
                          i.ip_address, i.address, device))
        set_vlan_for_interface(nodes[device])
Example #13
0
#!/usr/bin/env python2
import sys
from datetime import timedelta
from models.interface import Interface
import settings
from models.model import Feed, Entry
from helpers import seconds_to_upper_minutes

db = Interface(settings.DATABASE_ENGINE, settings.DATABASE_CONNECTION_STRING)

if __name__ == "__main__":
    for feed in db.get_all_feeds():
        print u"Feed: {0}".format(feed.title)
        entries = db.connection.get_items(Entry.TYPE, feed_id=feed.id)
        if len(entries):
            for entry in entries:
                entry = db.get_entry(entry['id'])   # cheating here should really convert to Entry object but meh
                print u" - {0}".format(entry.title)
        else:
            print u"   No entries found"
            
    all_feed = db.connection.get_items(Feed.TYPE)
    all_entries = db.connection.get_items(Entry.TYPE)
    print "There were {0} feeds and {1} entries".format(len(all_feed), len(all_entries))
    
Example #14
0
def recover_interfaces__templates_recycles(ids):
    Interface.objects(Q(id__in=ids)
                      & Q(is_template=True)).update(is_deleted=False)
    return jsonify(ok=True, msg='success')
Example #15
0
def update_device(new, old, response):
    if new.parent_equipment.id != old.parent_equipment.id:
        Interface.objects(_parent_device=new).update(_parent_equipment=new.parent_equipment)
        Cable.objects(_start_device=new).update(_start_equipment=new.parent_equipment)
        Cable.objects(_end_device=new).update(_end_equipment=new.parent_equipment)
    return response
Example #16
0
def delete_equipment(oid, response):
    Device.objects(_parent_equipment=oid).update(is_deleted=True)
    Interface.objects(_parent_equipment=oid).update(is_deleted=True)
    Cable.objects(Q(_start_equipment=oid) | Q(_end_equipment=oid)).update(is_deleted=True)
    return response
Example #17
0
#!/usr/bin/env python2
import sys
from datetime import timedelta
from models.interface import Interface
import settings
from models.model import Feed, Entry
from helpers import seconds_to_upper_minutes

db = Interface(settings.DATABASE_ENGINE, settings.DATABASE_CONNECTION_STRING)

if __name__ == "__main__":
    for feed in db.get_all_feeds():
        print u"Feed: {0}".format(feed.title)
        entries = db.connection.get_items(Entry.TYPE, feed_id=feed.id)
        if len(entries):
            for entry_id in entries:
                entry = db.get_entry(entry_id)
                print u" - {0}".format(entry.id)
        else:
            print u"   No entries found"
            
    all_feed = db.connection.get_items(Feed.TYPE)
    all_entries = db.connection.get_items(Entry.TYPE)
    print "There were {0} feeds and {1} entries".format(len(all_feed), len(all_entries))
        
Example #18
0
def delete_device(oid, response):
    Interface.objects(_parent_device=oid).update(is_deleted=True)
    Cable.objects(Q(_start_device=oid) | Q(_end_device=oid)).update(is_deleted=True)

    return response