diff --git a/ocfweb/docs/templates/docs/desktop_upgrade.html b/ocfweb/docs/templates/docs/desktop_upgrade.html new file mode 100644 index 00000000..6de2938d --- /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 e6b83491..82d9be02 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/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 00000000..2b81e38e --- /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, + }, + )