Skip to content

Commit

Permalink
Add active status/last seen
Browse files Browse the repository at this point in the history
  • Loading branch information
lutoma committed Dec 29, 2023
1 parent 361a89b commit 2487a68
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 2 additions & 4 deletions peeringmanager/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ class RouterAdmin(admin.ModelAdmin):

@admin.register(Peering)
class PeeringAdmin(admin.ModelAdmin):
list_display = ['asn', 'router', 'vpn_type', 'endpoint', 'endpoint_internal_v4',
'endpoint_internal_v6', 'router_endpoint_internal_v6', 'mbgp_enabled']

list_filter = ['router', 'vpn_type']
list_display = ['asn', 'router', 'active', 'mbgp_enabled', 'endpoint', 'last_up']
list_filter = ['active', 'mbgp_enabled', 'router']
3 changes: 3 additions & 0 deletions peeringmanager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class Peering(models.Model):
('wireguard', _('Wireguard')),
)

active = models.BooleanField(default=True, verbose_name=_('Active'))
last_up = models.DateTimeField(auto_now_add=True, verbose_name=_('Last seen up'))

owner = models.ForeignKey(get_user_model(), verbose_name=_('Owner'),
on_delete=models.SET_NULL, null=True, blank=True)

Expand Down
3 changes: 3 additions & 0 deletions peeringmanager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.views.generic.detail import DetailView
from django.views.generic import TemplateView
from django.utils.decorators import method_decorator
from django.utils import timezone
from django.contrib.auth.decorators import login_required
from django.core.exceptions import ValidationError
from autopeer.mixins import AuthenticatedRedirectMixin
Expand Down Expand Up @@ -111,6 +112,8 @@ def get_form_kwargs(self):
return kwargs

def form_valid(self, form):
form.instance.active = True
form.instance.last_up = timezone.now()
form.instance.owner = self.request.user

if not form.instance.wg_privkey or not form.instance.wg_pubkey:
Expand Down

0 comments on commit 2487a68

Please sign in to comment.