Skip to content

Commit 69b3c5d

Browse files
Initial version of VMBackup model and created its table to render it on GUI.
1 parent 04d236a commit 69b3c5d

File tree

5 files changed

+204
-4
lines changed

5 files changed

+204
-4
lines changed

netbox_proxbox/choices.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class SyncTypeChoices(ChoiceSet):
2727
(ALL, _('All'), 'red'),
2828
]
2929

30+
3031
class SyncStatusChoices(ChoiceSet):
3132
key = 'SyncProcess.status'
3233

@@ -39,3 +40,45 @@ class SyncStatusChoices(ChoiceSet):
3940
(SYNCING, _('Syncing'), 'blue'),
4041
(COMPLETED, _('Completed'), 'green'),
4142
]
43+
44+
45+
class ProxmoxBackupSubtypeChoices(ChoiceSet):
46+
key = 'VMBackup.subtype'
47+
48+
BACKUP_SUBTYPE_UNDEFINED = 'undefined'
49+
BACKUP_SUBTYPE_LXC = 'lxc'
50+
BACKUP_SUBTYPE_QEMU = 'qemu'
51+
52+
CHOICES = [
53+
(BACKUP_SUBTYPE_UNDEFINED, _('Undefined'), 'gray'),
54+
(BACKUP_SUBTYPE_LXC, _('LXC'), 'blue'),
55+
(BACKUP_SUBTYPE_QEMU, _('QEMU'), 'green'),
56+
]
57+
58+
59+
class ProxmoxBackupFormatChoices(ChoiceSet):
60+
key = 'VMBackup.format'
61+
62+
BACKUP_FORMAT_UNDEFINED = 'undefined'
63+
BACKUP_FORMAT_PBS_VM = 'pbs-vm'
64+
BACKUP_FORMAT_PBS_CT = 'pbs-ct'
65+
BACKUP_FORMAT_ISO = 'iso'
66+
BACKUP_FORMAT_TZST = 'tzst'
67+
BACKUP_FORMAT_TGZ = 'tgz'
68+
BACKUP_FORMAT_QCOW2 = 'qcow2'
69+
BACKUP_FORMAT_RAW = 'raw'
70+
BACKUP_FORMAT_TAR = 'tar'
71+
BACKUP_FORMAT_TBZ = 'tbz'
72+
73+
CHOICES = [
74+
(BACKUP_FORMAT_UNDEFINED, _('Undefined'), 'gray'),
75+
(BACKUP_FORMAT_PBS_VM, _('PBS VM'), 'blue'),
76+
(BACKUP_FORMAT_PBS_CT, _('PBS CT'), 'green'),
77+
(BACKUP_FORMAT_ISO, _('ISO'), 'yellow'),
78+
(BACKUP_FORMAT_TZST, _('TZST'), 'purple'),
79+
(BACKUP_FORMAT_TGZ, _('TGZ'), 'red'),
80+
(BACKUP_FORMAT_QCOW2, _('QCOW2'), 'orange'),
81+
(BACKUP_FORMAT_RAW, _('RAW'), 'pink'),
82+
(BACKUP_FORMAT_TAR, _('TAR'), 'brown'),
83+
(BACKUP_FORMAT_TBZ, _('TBZ'), 'gray'),
84+
]

netbox_proxbox/models.py renamed to netbox_proxbox/models/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
from netbox.models import NetBoxModel
77

8-
from .fields import DomainField
9-
from .choices import ProxmoxModeChoices, SyncTypeChoices, SyncStatusChoices
8+
from netbox_proxbox.fields import DomainField
9+
from netbox_proxbox.choices import ProxmoxModeChoices, SyncTypeChoices, SyncStatusChoices
10+
from netbox_proxbox.models.vm_backup import VMBackup
1011

1112
class ProxmoxEndpoint(NetBoxModel):
1213
name = models.CharField(

netbox_proxbox/models/vm_backup.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Django Imports
2+
from django.db import models
3+
from django.utils.translation import gettext_lazy as _
4+
5+
# NetBox Imports
6+
from netbox.models import NetBoxModel
7+
8+
# NetBox ProxBox Imports
9+
from netbox_proxbox.choices import ProxmoxBackupSubtypeChoices, ProxmoxBackupFormatChoices
10+
11+
class VMBackup(NetBoxModel):
12+
virtual_machine = models.ForeignKey(
13+
to='virtualization.VirtualMachine',
14+
on_delete=models.CASCADE,
15+
related_name='backups',
16+
)
17+
18+
subtype = models.CharField(
19+
max_length=255,
20+
choices=ProxmoxBackupSubtypeChoices,
21+
default=ProxmoxBackupSubtypeChoices.BACKUP_SUBTYPE_UNDEFINED,
22+
)
23+
24+
format = models.CharField(
25+
max_length=255,
26+
choices=ProxmoxBackupFormatChoices,
27+
default=ProxmoxBackupFormatChoices.BACKUP_FORMAT_UNDEFINED,
28+
)
29+
30+
creation_time = models.DateTimeField(
31+
null=True,
32+
blank=True,
33+
help_text=_('Creation time of the backup.'),
34+
)
35+
36+
size = models.BigIntegerField(
37+
null=True,
38+
blank=True,
39+
help_text=_('Size in bytes of the backup.'),
40+
)
41+
42+
notes = models.TextField(
43+
null=True,
44+
blank=True,
45+
help_text=_('Notes of the backup.'),
46+
)
47+
48+
volume_id = models.CharField(
49+
max_length=255,
50+
null=True,
51+
blank=True,
52+
help_text=_('Volume Identifier of the backup.'),
53+
)
54+
55+
vmid = models.IntegerField(
56+
null=True,
57+
blank=True,
58+
help_text=_('VM ID of the backup.'),
59+
)
60+
61+
used = models.BigIntegerField(
62+
null=True,
63+
blank=True,
64+
help_text=_('Used space of the backup.'),
65+
)
66+
67+
encrypted = models.BooleanField(
68+
default=False,
69+
help_text=_('Encrypted status of the backup.'),
70+
)
71+
72+
verification_state = models.CharField(
73+
max_length=255,
74+
null=True,
75+
blank=True,
76+
help_text=_('Verification state of the backup.'),
77+
)
78+
79+
verification_upid = models.CharField(
80+
max_length=255,
81+
null=True,
82+
blank=True,
83+
help_text=_('Verification UPID of the backup.'),
84+
)
85+
86+
87+
88+
89+
90+
91+
92+
93+
94+
95+
96+
97+
98+
99+

netbox_proxbox/tables.py renamed to netbox_proxbox/tables/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from netbox.tables import NetBoxTable, ChoiceFieldColumn
55
from netbox.tables.columns import BooleanColumn
66

7-
from .models import (
7+
from netbox_proxbox.models import (
88
ProxmoxEndpoint,
99
NetBoxEndpoint,
1010
FastAPIEndpoint,
@@ -70,7 +70,7 @@ class NetBoxEndpointTable(NetBoxTable):
7070
name = tables.Column(linkify=True)
7171
ip_address = tables.Column(linkify=True)
7272
verify_ssl = BooleanColumn()
73-
73+
token = tables.Column(linkify=True)
7474
class Meta(NetBoxTable.Meta):
7575
model = NetBoxEndpoint
7676
fields = (

netbox_proxbox/tables/vm_backup.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Django Imports
2+
from django_tables2 import tables
3+
from django.utils.translation import gettext as _
4+
5+
# NetBox Imports
6+
from netbox.tables import NetBoxTable, ChoiceFieldColumn
7+
from netbox.tables.columns import BooleanColumn
8+
9+
# Proxbox Imports
10+
from netbox_proxbox.models import VMBackup
11+
12+
13+
class VMBackupTable(NetBoxTable):
14+
virtual_machine = tables.Column(linkify=True)
15+
subtype = ChoiceFieldColumn(
16+
verbose_name=_('Subtype'),
17+
)
18+
format = ChoiceFieldColumn(
19+
verbose_name=_('Format'),
20+
)
21+
creation_time = tables.Column(
22+
verbose_name=_('Creation Time'),
23+
)
24+
size = tables.Column(
25+
verbose_name=_('Size in Bytes'),
26+
)
27+
used = tables.Column(
28+
verbose_name=_('Used in Bytes'),
29+
)
30+
encrypted = BooleanColumn(
31+
verbose_name=_('Encrypted'),
32+
)
33+
volume_id = tables.Column(
34+
verbose_name=_('Volume ID'),
35+
)
36+
vmid = tables.Column(
37+
verbose_name=_('VM ID'),
38+
)
39+
40+
41+
class Meta(NetBoxTable.Meta):
42+
model = VMBackup
43+
fields = (
44+
'pk', 'id', 'virtual_machine', 'subtype',
45+
'format', 'creation_time', 'size', 'used',
46+
'encrypted', 'volume_id', 'vmid',
47+
'verification_state', 'verification_upid',
48+
'notes', 'actions',
49+
)
50+
51+
default_columns = (
52+
'pk', 'virtual_machine', 'subtype', 'format',
53+
'creation_time', 'size', 'encrypted', 'volume_id',
54+
'vmid', 'verification_state', 'notes'
55+
)
56+
57+

0 commit comments

Comments
 (0)