From 6a0417c3b12442d1d10d167dd645773b6ead5c4d Mon Sep 17 00:00:00 2001 From: Kinn <168384805+kinn-edendev@users.noreply.github.com> Date: Wed, 25 Sep 2024 22:24:08 -0700 Subject: [PATCH 1/2] Update urls.py --- ocfweb/docs/urls.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ocfweb/docs/urls.py b/ocfweb/docs/urls.py index e6b834910..64f35e80d 100644 --- a/ocfweb/docs/urls.py +++ b/ocfweb/docs/urls.py @@ -16,6 +16,7 @@ from ocfweb.docs.views.account_policies import account_policies from ocfweb.docs.views.buster_upgrade import buster_upgrade from ocfweb.docs.views.commands import commands +from ocfweb.docs.views.desktop_upgrade import desktop_upgrade from ocfweb.docs.views.hosting_badges import hosting_badges from ocfweb.docs.views.index import docs_index from ocfweb.docs.views.lab import lab @@ -30,6 +31,7 @@ Document(name='/about/officers', title='Officers', render=officers), Document(name='/staff/backend/servers', title='Servers', render=servers), Document(name='/staff/backend/buster', title='Debian Buster upgrade', render=buster_upgrade), + Document(name='/staff/backend/buster', title='Debian Buster upgrade', render=buster_upgrade), Document(name='/services/account/account-policies', title='Account policies', render=account_policies), Document(name='/services/vhost/badges', title='Hosting badges', render=hosting_badges), Document(name='/services/lab', title='Computer lab', render=lab), From 9b2c117571330351c892810459e28bd1570a0782 Mon Sep 17 00:00:00 2001 From: Nicholas Perematko Date: Thu, 26 Sep 2024 11:21:15 -0700 Subject: [PATCH 2/2] NixOS upgrade tracker page, staff url directory added --- .../docs/templates/docs/desktop_upgrade.html | 43 ++++ ocfweb/docs/urls.py | 2 +- ocfweb/docs/views/desktop_upgrade.py | 199 ++++++++++++++++++ 3 files changed, 243 insertions(+), 1 deletion(-) create mode 100644 ocfweb/docs/templates/docs/desktop_upgrade.html create mode 100644 ocfweb/docs/views/desktop_upgrade.py diff --git a/ocfweb/docs/templates/docs/desktop_upgrade.html b/ocfweb/docs/templates/docs/desktop_upgrade.html new file mode 100644 index 000000000..6de2938d2 --- /dev/null +++ b/ocfweb/docs/templates/docs/desktop_upgrade.html @@ -0,0 +1,43 @@ +{% extends 'base.html' %} + +{% block content %} +
+

+ This table lists all desktops and whether they have been upgraded to NixOS. +

+ +
+ + + {% for server in servers %} + + + + + + {% endfor %} +
+ {{server.host.hostname}} + {% if server.has_dev %} +
+ dev-{{server.host.hostname}} + {% endif %} +
+ {{server.host.description}} + {% if server.comments %} +
+ Comments: {{server.comments}} +
+ {% endif %} +
+ {% if server.status == upgraded %} + Done! + {% elif server.status == blocked %} + Blocked + {% endif %} +
+{% endblock %} diff --git a/ocfweb/docs/urls.py b/ocfweb/docs/urls.py index 64f35e80d..82d9be02b 100644 --- a/ocfweb/docs/urls.py +++ b/ocfweb/docs/urls.py @@ -31,7 +31,7 @@ Document(name='/about/officers', title='Officers', render=officers), Document(name='/staff/backend/servers', title='Servers', render=servers), Document(name='/staff/backend/buster', title='Debian Buster upgrade', render=buster_upgrade), - Document(name='/staff/backend/buster', title='Debian Buster upgrade', render=buster_upgrade), + Document(name='/staff/backend/nixos', title='NixOS upgrade', render=desktop_upgrade), Document(name='/services/account/account-policies', title='Account policies', render=account_policies), Document(name='/services/vhost/badges', title='Hosting badges', render=hosting_badges), Document(name='/services/lab', title='Computer lab', render=lab), diff --git a/ocfweb/docs/views/desktop_upgrade.py b/ocfweb/docs/views/desktop_upgrade.py new file mode 100644 index 000000000..2b81e38e9 --- /dev/null +++ b/ocfweb/docs/views/desktop_upgrade.py @@ -0,0 +1,199 @@ +''' +STATUS EXAMPLE +- Follow the formats to list the desktop + +* For a desktop thats not upgraded yet. + ThingToUpgrade.from_hostname( + 'death', + comments='same time as all login servers', + status=ThingToUpgrade.NEEDS_UPGRADE, + ), + +* For a desktop that has been upgraded. + ThingToUpgrade.from_hostname( + 'maelstrom', + comments="Scanner", + status=ThingToUpgrade.UPGRADED, + ), + +* For a desktop that has been blocked from upgrading. + ThingToUpgrade.from_hostname( + 'venom', + status=ThingToUpgrade.BLOCKED, + ), + +''' +from collections import namedtuple +from typing import Any +from typing import Optional +from typing import Tuple + +from django.http import HttpRequest +from django.http import HttpResponse +from django.shortcuts import render +from ocflib.misc.validators import host_exists + +from ocfweb.caching import cache +from ocfweb.docs.doc import Document +from ocfweb.docs.views.servers import Host + + +class ThingToUpgrade( + namedtuple( + 'ThingToUpgrade', ( + 'host', + 'status', + 'comments', + 'has_dev', + ), + ), +): + NEEDS_UPGRADE = 1 + BLOCKED = 2 + UPGRADED = 3 + + @classmethod + def from_hostname(cls: Any, hostname: str, status: int = NEEDS_UPGRADE, comments: Optional[str] = None) -> Any: + has_dev = host_exists('dev-' + hostname + '.ocf.berkeley.edu') + return cls( + host=Host.from_ldap(hostname), + status=status, + has_dev=has_dev, + comments=comments, + ) + + +@cache() +def _get_servers() -> Tuple[Any, ...]: + return ( + # Desktops + ThingToUpgrade.from_hostname( + 'bandit', + status=ThingToUpgrade.UPGRADED, + ), + ThingToUpgrade.from_hostname( + 'blight', + comments='Old PC', + status=ThingToUpgrade.NEEDS_UPGRADE, + ), + ThingToUpgrade.from_hostname( + 'bolt', + status=ThingToUpgrade.UPGRADED, + ), + ThingToUpgrade.from_hostname( + 'callie', + status=ThingToUpgrade.UPGRADED, + ), + ThingToUpgrade.from_hostname( + 'chaos', + comments='Scanner', + status=ThingToUpgrade.NEEDS_UPGRADE, + ), + ThingToUpgrade.from_hostname( + 'cyanide', + comments='Old PC', + status=ThingToUpgrade.NEEDS_UPGRADE, + ), + ThingToUpgrade.from_hostname( + 'drought', + comments='Old PC', + status=ThingToUpgrade.NEEDS_UPGRADE, + ), + ThingToUpgrade.from_hostname( + 'fred', + status=ThingToUpgrade.UPGRADED, + ), + ThingToUpgrade.from_hostname( + 'gabriel', + status=ThingToUpgrade.UPGRADED, + ), + ThingToUpgrade.from_hostname( + 'hailstorm', + comments='Old PC', + status=ThingToUpgrade.NEEDS_UPGRADE, + ), + ThingToUpgrade.from_hostname( + 'heatwave', + comments='Old PC', + status=ThingToUpgrade.NEEDS_UPGRADE, + ), + ThingToUpgrade.from_hostname( + 'lexy', + status=ThingToUpgrade.UPGRADED, + ), + ThingToUpgrade.from_hostname( + 'madcow', + comments='Old PC', + status=ThingToUpgrade.NEEDS_UPGRADE, + ), + ThingToUpgrade.from_hostname( + 'maelstrom', + comments='Scanner', + status=ThingToUpgrade.NEEDS_UPGRADE, + ), + ThingToUpgrade.from_hostname( + 'misty', + status=ThingToUpgrade.UPGRADED, + ), + ThingToUpgrade.from_hostname( + 'pickles', + status=ThingToUpgrade.UPGRADED, + ), + ThingToUpgrade.from_hostname( + 'pumpkin', + status=ThingToUpgrade.UPGRADED, + ), + ThingToUpgrade.from_hostname( + 'shadow', + status=ThingToUpgrade.UPGRADED, + ), + ThingToUpgrade.from_hostname( + 'smokey', + status=ThingToUpgrade.UPGRADED, + ), + ThingToUpgrade.from_hostname( + 'socks', + status=ThingToUpgrade.UPGRADED, + ), + ThingToUpgrade.from_hostname( + 'spots', + status=ThingToUpgrade.UPGRADED, + ), + ThingToUpgrade.from_hostname( + 'sunny', + comments='Old PC', + status=ThingToUpgrade.NEEDS_UPGRADE, + ), + ThingToUpgrade.from_hostname( + 'surge', + comments='Scanner', + status=ThingToUpgrade.NEEDS_UPGRADE, + ), + ThingToUpgrade.from_hostname( + 'tabitha', + status=ThingToUpgrade.UPGRADED, + ), + ThingToUpgrade.from_hostname( + 'venom', + comments='Old PC', + status=ThingToUpgrade.NEEDS_UPGRADE, + ), + ThingToUpgrade.from_hostname( + 'volcano', + comments='Old PC', + status=ThingToUpgrade.NEEDS_UPGRADE, + ), + ) + + +def desktop_upgrade(doc: Document, request: HttpRequest) -> HttpResponse: + return render( + request, + 'docs/desktop_upgrade.html', + { + 'title': doc.title, + 'servers': _get_servers(), + 'blocked': ThingToUpgrade.BLOCKED, + 'upgraded': ThingToUpgrade.UPGRADED, + }, + )