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 NixOS Desktop Upgrade Tracker and Staff URL #844

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
43 changes: 43 additions & 0 deletions ocfweb/docs/templates/docs/desktop_upgrade.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{% extends 'base.html' %}

{% block content %}
<div class="ocf-content-block">
<p>
This table lists all desktops and whether they have been upgraded to NixOS.
</p>

</div>

<table class="table">
{% for server in servers %}
<tr {% if server.status == upgraded %}
style="background-color: #d3ffd3;"
{% elif server.status == blocked %}
style="background-color: #ffd3d3;"
{% endif %}>
<th>
{{server.host.hostname}}
{% if server.has_dev %}
<br />
dev-{{server.host.hostname}}
{% endif %}
</th>
<td>
{{server.host.description}}
{% if server.comments %}
<div style="background-color: #fffed3;">
<strong>Comments:</strong> {{server.comments}}
</div>
{% endif %}
</td>
<th>
{% if server.status == upgraded %}
Done!
{% elif server.status == blocked %}
Blocked
{% endif %}
</th>
</tr>
{% endfor %}
</table>
{% endblock %}
2 changes: 2 additions & 0 deletions ocfweb/docs/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down
199 changes: 199 additions & 0 deletions ocfweb/docs/views/desktop_upgrade.py
Original file line number Diff line number Diff line change
@@ -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,
},
)