Example #1
0
def switch_show_json(switch_id):
    switch = Switch.q.options(
        joinedload(Switch.ports).joinedload(SwitchPort.patch_port).joinedload(
            PatchPort.room)).get(switch_id)
    if not switch:
        abort(404)
    switch_port_list = switch.ports
    switch_port_list = net.sort_ports(switch_port_list)
    T = PortTable
    return jsonify(items=[{
            "switchport_name": port.name,
            "patchport_name": port.patch_port.name if port.patch_port else None,
            "room": T.room.value(
                href=url_for("facilities.room_show", room_id=port.patch_port.room.id),
                title=port.patch_port.room.short_name
            ) if port.patch_port else None,
            "edit_link": T.edit_link.value(
                href=url_for(".switch_port_edit",
                             switch_id=switch.host.id, switch_port_id=port.id),
                title="Bearbeiten",
                icon='fa-edit',
                btn_class='btn-link'
            ),
            "delete_link": T.delete_link.value(
                href=url_for(".switch_port_delete",
                             switch_id=switch.host.id, switch_port_id=port.id),
                title="Löschen",
                icon='fa-trash',
                btn_class='btn-link'
            ),
        } for port in switch_port_list])
Example #2
0
def room_patchpanel_json(room_id):
    room = Room.q.get(room_id)

    if not room:
        abort(404)

    if not room.is_switch_room:
        abort(400)

    patch_ports = PatchPort.q.filter_by(switch_room=room).all()
    patch_ports = sort_ports(patch_ports)

    return jsonify(items=[{
        "name": port.name,
        "room": {
            "href": url_for(".room_show", room_id=port.room.id),
            "title": port.room.short_name
        },
        "switch_port": {
            "href":
            url_for("infrastructure.switch_show",
                    switch_id=port.switch_port.switch.host_id),
            "title":
            "{}/{}".format(port.switch_port.switch.host.name, port.switch_port.
                           name)
        } if port.switch_port else None,
        "edit_link": {
            "href":
            url_for(".patch_port_edit",
                    switch_room_id=room.id,
                    patch_port_id=port.id),
            'title':
            "Bearbeiten",
            'icon':
            'fa-edit',
            'btn-class':
            'btn-link'
        },
        "delete_link": {
            "href":
            url_for(".patch_port_delete",
                    switch_room_id=room.id,
                    patch_port_id=port.id),
            'title':
            "Löschen",
            'icon':
            'fa-trash',
            'btn-class':
            'btn-link'
        },
    } for port in patch_ports])
Example #3
0
    def test_sort_ports(self):
        ports = [f"{let}{num}" for let in "ABCDEFG" for num in range(1, 24)]

        class fake_port(object):
            def __init__(self, name):
                self.name = name

        pool = list(ports)
        shuffled = []
        for selected in range(0, len(ports)):
            idx = randint(0, len(pool) - 1)
            shuffled.append(fake_port(pool[idx]))
            del pool[idx]
        resorted = [p.name for p in sort_ports(shuffled)]
        self.assertEqual(resorted, ports)
Example #4
0
def switch_show_json(switch_id):
    switch = Switch.q.get(switch_id)
    if not switch:
        abort(404)
    switch_port_list = switch.ports
    switch_port_list = net.sort_ports(switch_port_list)
    return jsonify(items=[{
        "portname": port.name,
        "room": {
            "href":
            url_for("facilities.room_show", room_id=port.patch_port.room.id),
            "title":
            "{}-{}".format(port.patch_port.room.level, port.patch_port.room.
                           number)
        } if port.patch_port else None
    } for port in switch_port_list])
Example #5
0
    def test_0010_sort_ports(self):
        ports = ["{0}{1:d}".format(letter, number)
                 for letter in ["A", "B", "C", "D", "E", "F", "G"]
                 for number in range(1, 24)]

        class fake_port(object):
            def __init__(self, name):
                self.name = name

        pool = list(ports)
        shuffled = []
        for selected in range(0, len(ports)):
            idx = randint(0, len(pool) - 1)
            shuffled.append(fake_port(pool[idx]))
            del pool[idx]
        resorted = [p.name for p in sort_ports(shuffled)]
        self.assertEqual(resorted, ports)
Example #6
0
def room_patchpanel_json(room_id):
    room = Room.get(room_id)

    if not room:
        abort(404)

    if not room.is_switch_room:
        abort(400)

    patch_ports = PatchPort.q.filter_by(switch_room=room).all()
    patch_ports = sort_ports(patch_ports)
    T = PatchPortTable

    return jsonify(items=[
        {
            "name":
            port.name,
            "room":
            T.room.value(href=url_for(".room_show", room_id=port.room.id),
                         title=port.room.short_name),
            "switch_port":
            T.switch_port.value(
                href=url_for("infrastructure.switch_show",
                             switch_id=port.switch_port.switch.host_id),
                title=
                f"{port.switch_port.switch.host.name}/{port.switch_port.name}"
            ) if port.switch_port else None,
            'edit_link':
            T.edit_link.value(
                hef=url_for(".patch_port_edit",
                            switch_room_id=room.id,
                            patch_port_id=port.id),
                title="Bearbeiten",
                icon='fa-edit',
                # TODO decide on a convention here
                btn_class='btn-link',
            ),
            'delete_link':
            T.delete_link.value(href=url_for(".patch_port_delete",
                                             switch_room_id=room.id,
                                             patch_port_id=port.id),
                                title="Löschen",
                                icon='fa-trash',
                                btn_class='btn-link'),
        } for port in patch_ports
    ])
Example #7
0
    def test_0010_sort_ports(self):
        ports = ["{0}{1:d}".format(letter, number)
                 for letter in ["A", "B", "C", "D", "E", "F", "G"]
                 for number in range(1, 24)]

        class fake_port(object):
            def __init__(self, name):
                self.name = name

        pool = list(ports)
        shuffled = []
        for selected in range(0, len(ports)):
            idx = randint(0, len(pool) - 1)
            shuffled.append(fake_port(pool[idx]))
            del pool[idx]
        resorted = [p.name for p in sort_ports(shuffled)]
        self.assertEqual(resorted, ports)
Example #8
0
def switch_show_json(switch_id):
    switch = Switch.q.options(
        joinedload(Switch.ports).joinedload(SwitchPort.patch_port).joinedload(
            PatchPort.room)).get(switch_id)
    if not switch:
        abort(404)
    switch_port_list = switch.ports
    switch_port_list = net.sort_ports(switch_port_list)
    return jsonify(items=[{
        "switchport_name":
        port.name,
        "patchport_name":
        port.patch_port.name if port.patch_port else None,
        "room": {
            "href":
            url_for("facilities.room_show", room_id=port.patch_port.room.id),
            "title":
            port.patch_port.room.short_name
        } if port.patch_port else None,
        "edit_link": {
            "href":
            url_for(".switch_port_edit",
                    switch_id=switch.host.id,
                    switch_port_id=port.id),
            'title':
            "Bearbeiten",
            'icon':
            'glyphicon-pencil',
            'btn-class':
            'btn-link'
        },
        "delete_link": {
            "href":
            url_for(".switch_port_delete",
                    switch_id=switch.host.id,
                    switch_port_id=port.id),
            'title':
            "Löschen",
            'icon':
            'glyphicon-trash',
            'btn-class':
            'btn-link'
        },
    } for port in switch_port_list])
Example #9
0
def switch_show_json(switch_id):
    switch = Switch.q.get(switch_id)
    if not switch:
        abort(404)
    switch_port_list = switch.ports
    switch_port_list = net.sort_ports(switch_port_list)
    return jsonify(items=[{
            "portname": port.name,
            "room": {
                "href": url_for(
                    "facilities.room_show",
                    room_id=port.patch_port.room.id
                ),
                "title": "{}-{}".format(
                    port.patch_port.room.level,
                    port.patch_port.room.number
                )
            } if port.patch_port else None
        } for port in switch_port_list])