mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-23 07:56:44 -06:00
8356 add virtual disk model
This commit is contained in:
parent
7efbfabc0b
commit
5bcf351bdc
54
netbox/virtualization/migrations/0037_virtualdisk.py
Normal file
54
netbox/virtualization/migrations/0037_virtualdisk.py
Normal file
@ -0,0 +1,54 @@
|
||||
# Generated by Django 4.2.5 on 2023-10-18 22:49
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import taggit.managers
|
||||
import utilities.fields
|
||||
import utilities.json
|
||||
import utilities.ordering
|
||||
import utilities.tracking
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('extras', '0098_webhook_custom_field_data_webhook_tags'),
|
||||
('virtualization', '0036_virtualmachine_config_template'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='VirtualDisk',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
|
||||
('created', models.DateTimeField(auto_now_add=True, null=True)),
|
||||
('last_updated', models.DateTimeField(auto_now=True, null=True)),
|
||||
(
|
||||
'custom_field_data',
|
||||
models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder),
|
||||
),
|
||||
('name', models.CharField(max_length=64)),
|
||||
(
|
||||
'_name',
|
||||
utilities.fields.NaturalOrderingField(
|
||||
'name', blank=True, max_length=100, naturalize_function=utilities.ordering.naturalize
|
||||
),
|
||||
),
|
||||
('size', models.PositiveIntegerField(blank=True, null=True)),
|
||||
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
|
||||
(
|
||||
'virtual_machine',
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name='%(class)ss',
|
||||
to='virtualization.virtualmachine',
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'virtual disk',
|
||||
'verbose_name_plural': 'virtual disks',
|
||||
'ordering': ('_name', 'pk'),
|
||||
},
|
||||
bases=(models.Model, utilities.tracking.TrackingModelMixin),
|
||||
),
|
||||
]
|
@ -371,3 +371,42 @@ class VMInterface(NetBoxModel, BaseInterface, TrackingModelMixin):
|
||||
@property
|
||||
def l2vpn_termination(self):
|
||||
return self.l2vpn_terminations.first()
|
||||
|
||||
|
||||
class VirtualDisk(NetBoxModel, TrackingModelMixin):
|
||||
virtual_machine = models.ForeignKey(
|
||||
to=VirtualMachine,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='%(class)ss'
|
||||
)
|
||||
name = models.CharField(
|
||||
verbose_name=_('name'),
|
||||
max_length=64
|
||||
)
|
||||
_name = NaturalOrderingField(
|
||||
target_field='name',
|
||||
max_length=100,
|
||||
blank=True
|
||||
)
|
||||
size = models.PositiveIntegerField(
|
||||
verbose_name=_('size'),
|
||||
blank=True,
|
||||
null=True,
|
||||
help_text=_("Size")
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ('_name', 'pk') # Name may be non-unique
|
||||
verbose_name = _('virtual disk')
|
||||
verbose_name_plural = _('virtual disks')
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('virtualization:virtualdisk', args=[self.pk])
|
||||
|
||||
def to_objectchange(self, action):
|
||||
objectchange = super().to_objectchange(action)
|
||||
objectchange.related_object = self.virtual_machine
|
||||
return objectchange
|
||||
|
Loading…
Reference in New Issue
Block a user