Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add router and interface poll feature #88

Merged
merged 8 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion src/howitz/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from datetime import datetime, timezone

from werkzeug.exceptions import BadRequest, MethodNotAllowed
from werkzeug.exceptions import BadRequest, InternalServerError, MethodNotAllowed
from zinolib.controllers.zino1 import Zino1EventManager, RetryError, EventClosedError, UpdateHandler
from zinolib.event_types import Event, AdmState, PortState, BFDState, ReachabilityState, LogEntry, HistoryEntry
from zinolib.compat import StrEnum
Expand Down Expand Up @@ -499,6 +499,49 @@ def show_update_events_status_modal():
return render_template('/components/popups/modals/update-event-status-modal.html', current_state='open')


@main.route('/event/<i>/poll', methods=["POST"])
def poll(i):
selected_events = session.get("selected_events", {})
event_id = int(i)

poll_res = current_app.event_manager.poll(event_id)

if poll_res:
event_attr, event_logs, event_history, event_msgs = get_event_details(event_id)
event = create_table_event(current_app.event_manager.create_event_from_id(event_id))["event"]

return render_template('/responses/update-event-response.html', event=event, id=event_id, event_attr=event_attr,
event_logs=event_logs,
event_history=event_history, event_msgs=event_msgs,
is_selected=str(event_id) in selected_events)
else:
raise InternalServerError(description=f"Unexpected error when polling event #{event_id}")


@main.route('/event/bulk_poll', methods=['POST'])
def bulk_poll():
selected_events = session.get("selected_events", {})
expanded_events = session.get("expanded_events", {})
current_app.logger.debug('SELECTED EVENTS %s', selected_events)
current_app.logger.debug('EXPANDED EVENTS %s', expanded_events)

# Update each selected event with new values
for event_id in selected_events:
poll_res = current_app.event_manager.poll(int(event_id))

if not poll_res:
raise InternalServerError(description=f"Unexpected error when polling event #{event_id}")

# Clear selected events
session["selected_events"] = {}
session.modified = True # Necessary when modifying arrays/dicts/etc in flask session
current_app.logger.debug("SELECTED EVENTS %s", session["selected_events"])

# Rerender whole events table
event_list = get_current_events()
return render_template('/responses/bulk-update-events-status.html', event_list=event_list)


@main.route('/event/<event_id>/unselect', methods=["POST"])
def unselect_event(event_id):
session["selected_events"].pop(event_id, None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
{% include "/components/accordion/update-state-btn.html" %}

<button
disabled
id="poll-event-{{ id }}"
class="text-white bg-blue-500 cursor-not-allowed font-medium rounded-lg text-sm px-3 py-2 mr-2 mb-2 text-center"
hx-post="/event/{{ id }}/poll"
hx-target="#event-accordion-row-{{ id }}"
hx-swap="outerHTML show:#event-msg-feed-{{ id }}:bottom"
hx-indicator="#row-{{ id }}-indicator"
class="text-white focus:ring-4 font-medium rounded-lg text-sm px-3 py-2 mr-2 mb-2 bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-blue-800"
>
Poll
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
</button>

<button
disabled
hx-post="/event/bulk_poll"
hx-target="#eventlist-list"
hx-swap="innerHTML"
hx-trigger="click"
id="bulk-poll-events"
class="text-white bg-blue-500 cursor-not-allowed font-medium rounded-lg text-sm px-3 py-2 mr-2 text-center"
>
hx-indicator="#bulk-poll-indicator"
class="text-white focus:ring-4 font-medium rounded-lg text-sm px-3 py-2 mr-2 bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-blue-800">
Poll
</button>

Expand Down
Loading