Skip to content

Commit faf0bd5

Browse files
Add sync backups view and add button on VM Backups List View to sync it.
1 parent 3ceb1ec commit faf0bd5

File tree

6 files changed

+68
-5
lines changed

6 files changed

+68
-5
lines changed

netbox_proxbox/choices.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ class SyncTypeChoices(ChoiceSet):
1818
key = 'SyncProcess.sync_type'
1919

2020
VIRTUAL_MACHINES = 'virtual-machines'
21+
VIRTUAL_MACHINES_BACKUPS = 'vm-backups'
2122
DEVICES = 'devices'
2223
ALL = 'all'
2324

2425
CHOICES = [
2526
(VIRTUAL_MACHINES, _('Virtual Machines'), 'blue'),
27+
(VIRTUAL_MACHINES_BACKUPS, _('Virtual Machines Backups'), 'purple'),
2628
(DEVICES, _('Devices'), 'green'),
2729
(ALL, _('All'), 'red'),
2830
]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{% extends 'base/layout.html' %}
2+
3+
{% block content %}
4+
<div class="row mb-3">
5+
<div class="col col-md-6">
6+
<div class="card">
7+
<h5 class="card-header">Sync VM Backups</h5>
8+
<div class="card-body">
9+
<p>Syncing backups...</p>
10+
<p>To view Sync Process, please go to <a href="{% url 'plugins:netbox_proxbox:syncprocess_list' %}">Sync Process</a> page.</p>
11+
<p>If you want real-time updates of the sync process, consider enabling WebSocket in the <a href="{% url 'plugins:netbox_proxbox:fastapiendpoint_list' %}">FastAPI Endpoint</a> configuration.</p>
12+
</div>
13+
</div>
14+
</div>
15+
</div>
16+
17+
<br>
18+
19+
<button class="btn btn-primary" onclick="window.location.href='{% url 'plugins:netbox_proxbox:home' %}'">Return to Proxbox Homepage</button>
20+
{% endblock %}

netbox_proxbox/templates/netbox_proxbox/vmbackup_list.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
{% load helpers %}
44
{% load i18n %}
55

6+
{% block controls %}
7+
<div class="btn-group" role="group">
8+
{% if 'sync_backups' in actions %}
9+
<a href="{% url 'plugins:netbox_proxbox:sync_vm_backups' %}">
10+
<button type="submit" name="_sync_backups" {% formaction %}="{% url 'plugins:netbox_proxbox:sync_vm_backups' %}" class="btn btn-primary">
11+
<i class="mdi mdi-sync" aria-hidden="true"></i> {% trans "Sync Backups" %}
12+
</button>
13+
</a>
14+
{% endif %}
15+
</div>
16+
{% endblock %}
617
{% block bulk_buttons %}
718
<div class="btn-group" role="group">
819
{% if 'bulk_delete' in actions %}
@@ -11,4 +22,4 @@
1122
</button>
1223
{% endif %}
1324
</div>
14-
{% endblock %}
25+
{% endblock %}

netbox_proxbox/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@
8282
# Manual Sync (HTTP Request)
8383
path('sync/devices', views.sync_devices, name='sync_devices'),
8484
path('sync/virtual-machines', views.sync_virtual_machines, name='sync_virtual_machines'),
85+
path('sync/virtual-machines/backups', views.sync_vm_backups, name='sync_vm_backups'),
8586
path('sync/full-update', views.sync_full_update, name='sync_full_update'),
8687

88+
8789
path('keepalive-status/<str:service>/<int:pk>', views.get_service_status, name='keepalive_status'),
8890
path('proxmox-card/<int:pk>', views.get_proxmox_card, name='proxmox_card'),
8991
path('websocket/<str:message>', WebSocketView.as_view(), name='websocket'),

netbox_proxbox/views/sync.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,32 @@ def make_request():
6464

6565
@require_GET
6666
def sync_devices(request: HtmxHttpRequest) -> HttpResponse:
67-
return sync_resource(request, 'dcim/devices/create', 'netbox_proxbox/sync_devices.html')
67+
return sync_resource(
68+
request,
69+
path='dcim/devices/create',
70+
template_name='netbox_proxbox/sync_devices.html'
71+
)
6872

6973
@require_GET
7074
def sync_virtual_machines(request: HtmxHttpRequest) -> HttpResponse:
71-
return sync_resource(request, 'virtualization/virtual-machines/create', 'netbox_proxbox/sync_virtual_machines.html')
75+
return sync_resource(
76+
request,
77+
path='virtualization/virtual-machines/create',
78+
template_name='netbox_proxbox/sync_virtual_machines.html'
79+
)
7280

7381
@require_GET
7482
def sync_full_update(request: HtmxHttpRequest) -> HttpResponse:
75-
return sync_resource(request, 'full-update', 'netbox_proxbox/sync_full_update.html')
83+
return sync_resource(
84+
request,
85+
path='full-update',
86+
template_name='netbox_proxbox/sync_full_update.html'
87+
)
88+
89+
@require_GET
90+
def sync_vm_backups(request: HtmxHttpRequest) -> HttpResponse:
91+
return sync_resource(
92+
request,
93+
path='virtualization/virtual-machines/backups/all/create',
94+
template_name='netbox_proxbox/sync_vm_backups.html'
95+
)

netbox_proxbox/views/vm_backup.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44
from django.shortcuts import render
55
from virtualization.models import VirtualMachine
66

7+
import requests
8+
79
# Proxbox Imports
8-
from netbox_proxbox.models import VMBackup
10+
from netbox_proxbox.models import VMBackup, FastAPIEndpoint
911
from netbox_proxbox.tables import VMBackupTable
1012
from netbox_proxbox.filtersets import VMBackupFilterSet
1113
from netbox_proxbox.forms import VMBackupForm, VMBackupFilterForm
14+
from netbox_proxbox.utils import get_fastapi_url
15+
16+
import logging
17+
logger = logging.getLogger(__name__)
1218

1319
__all__ = (
1420
'VMBackupView',
@@ -19,6 +25,7 @@
1925
'VMBackupTabView',
2026
)
2127

28+
2229
@register_model_view(VirtualMachine, 'backups', path='backups')
2330
class VMBackupTabView(generic.ObjectView):
2431
"""
@@ -111,6 +118,7 @@ class VMBackupListView(generic.ObjectListView):
111118
actions = {
112119
'bulk_delete': {'delete'},
113120
'export': {'view'},
121+
'sync_backups': {'view'},
114122
}
115123

116124
def get_required_permission(self):

0 commit comments

Comments
 (0)