mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 08:25:17 -06:00
Move config_template field to RenderConfigMixin
This commit is contained in:
parent
c0fae30684
commit
e53c4fac47
@ -13,7 +13,7 @@ class Migration(migrations.Migration):
|
|||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='device',
|
model_name='device',
|
||||||
name='config_template',
|
name='config_template',
|
||||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='devices', to='extras.configtemplate'),
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='%(class)ss', to='extras.configtemplate'),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='devicerole',
|
model_name='devicerole',
|
||||||
|
@ -24,7 +24,7 @@ from utilities.choices import ColorChoices
|
|||||||
from utilities.fields import ColorField, CounterCacheField, NaturalOrderingField
|
from utilities.fields import ColorField, CounterCacheField, NaturalOrderingField
|
||||||
from utilities.tracking import TrackingModelMixin
|
from utilities.tracking import TrackingModelMixin
|
||||||
from .device_components import *
|
from .device_components import *
|
||||||
from .mixins import WeightMixin
|
from .mixins import RenderConfigMixin, WeightMixin
|
||||||
|
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@ -525,7 +525,14 @@ def update_interface_bridges(device, interface_templates, module=None):
|
|||||||
interface.save()
|
interface.save()
|
||||||
|
|
||||||
|
|
||||||
class Device(ContactsMixin, ImageAttachmentsMixin, PrimaryModel, ConfigContextModel, TrackingModelMixin):
|
class Device(
|
||||||
|
ContactsMixin,
|
||||||
|
ImageAttachmentsMixin,
|
||||||
|
RenderConfigMixin,
|
||||||
|
ConfigContextModel,
|
||||||
|
TrackingModelMixin,
|
||||||
|
PrimaryModel
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
A Device represents a piece of physical hardware mounted within a Rack. Each Device is assigned a DeviceType,
|
A Device represents a piece of physical hardware mounted within a Rack. Each Device is assigned a DeviceType,
|
||||||
DeviceRole, and (optionally) a Platform. Device names are not required, however if one is set it must be unique.
|
DeviceRole, and (optionally) a Platform. Device names are not required, however if one is set it must be unique.
|
||||||
@ -686,13 +693,6 @@ class Device(ContactsMixin, ImageAttachmentsMixin, PrimaryModel, ConfigContextMo
|
|||||||
validators=[MaxValueValidator(255)],
|
validators=[MaxValueValidator(255)],
|
||||||
help_text=_('Virtual chassis master election priority')
|
help_text=_('Virtual chassis master election priority')
|
||||||
)
|
)
|
||||||
config_template = models.ForeignKey(
|
|
||||||
to='extras.ConfigTemplate',
|
|
||||||
on_delete=models.PROTECT,
|
|
||||||
related_name='devices',
|
|
||||||
blank=True,
|
|
||||||
null=True
|
|
||||||
)
|
|
||||||
latitude = models.DecimalField(
|
latitude = models.DecimalField(
|
||||||
verbose_name=_('latitude'),
|
verbose_name=_('latitude'),
|
||||||
max_digits=8,
|
max_digits=8,
|
||||||
@ -1070,17 +1070,6 @@ class Device(ContactsMixin, ImageAttachmentsMixin, PrimaryModel, ConfigContextMo
|
|||||||
def interfaces_count(self):
|
def interfaces_count(self):
|
||||||
return self.vc_interfaces().count()
|
return self.vc_interfaces().count()
|
||||||
|
|
||||||
def get_config_template(self):
|
|
||||||
"""
|
|
||||||
Return the appropriate ConfigTemplate (if any) for this Device.
|
|
||||||
"""
|
|
||||||
if self.config_template:
|
|
||||||
return self.config_template
|
|
||||||
if self.role.config_template:
|
|
||||||
return self.role.config_template
|
|
||||||
if self.platform and self.platform.config_template:
|
|
||||||
return self.platform.config_template
|
|
||||||
|
|
||||||
def get_vc_master(self):
|
def get_vc_master(self):
|
||||||
"""
|
"""
|
||||||
If this Device is a VirtualChassis member, return the VC master. Otherwise, return None.
|
If this Device is a VirtualChassis member, return the VC master. Otherwise, return None.
|
||||||
|
@ -4,6 +4,11 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
from dcim.choices import *
|
from dcim.choices import *
|
||||||
from utilities.utils import to_grams
|
from utilities.utils import to_grams
|
||||||
|
|
||||||
|
__all__ = (
|
||||||
|
'RenderConfigMixin',
|
||||||
|
'WeightMixin',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class WeightMixin(models.Model):
|
class WeightMixin(models.Model):
|
||||||
weight = models.DecimalField(
|
weight = models.DecimalField(
|
||||||
@ -44,3 +49,27 @@ class WeightMixin(models.Model):
|
|||||||
# Validate weight and weight_unit
|
# Validate weight and weight_unit
|
||||||
if self.weight and not self.weight_unit:
|
if self.weight and not self.weight_unit:
|
||||||
raise ValidationError(_("Must specify a unit when setting a weight"))
|
raise ValidationError(_("Must specify a unit when setting a weight"))
|
||||||
|
|
||||||
|
|
||||||
|
class RenderConfigMixin(models.Model):
|
||||||
|
config_template = models.ForeignKey(
|
||||||
|
to='extras.ConfigTemplate',
|
||||||
|
on_delete=models.PROTECT,
|
||||||
|
related_name='%(class)ss',
|
||||||
|
blank=True,
|
||||||
|
null=True
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
|
||||||
|
def get_config_template(self):
|
||||||
|
"""
|
||||||
|
Return the appropriate ConfigTemplate (if any) for this Device.
|
||||||
|
"""
|
||||||
|
if self.config_template:
|
||||||
|
return self.config_template
|
||||||
|
if self.role.config_template:
|
||||||
|
return self.role.config_template
|
||||||
|
if self.platform and self.platform.config_template:
|
||||||
|
return self.platform.config_template
|
||||||
|
@ -15,6 +15,6 @@ class Migration(migrations.Migration):
|
|||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='virtualmachine',
|
model_name='virtualmachine',
|
||||||
name='config_template',
|
name='config_template',
|
||||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='virtual_machines', to='extras.configtemplate'),
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='%(class)ss', to='extras.configtemplate'),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
@ -8,6 +8,7 @@ from django.urls import reverse
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from dcim.models import BaseInterface
|
from dcim.models import BaseInterface
|
||||||
|
from dcim.models.mixins import RenderConfigMixin
|
||||||
from extras.models import ConfigContextModel
|
from extras.models import ConfigContextModel
|
||||||
from extras.querysets import ConfigContextModelQuerySet
|
from extras.querysets import ConfigContextModelQuerySet
|
||||||
from netbox.config import get_config
|
from netbox.config import get_config
|
||||||
@ -25,7 +26,7 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class VirtualMachine(ContactsMixin, PrimaryModel, ConfigContextModel):
|
class VirtualMachine(ContactsMixin, RenderConfigMixin, ConfigContextModel, PrimaryModel):
|
||||||
"""
|
"""
|
||||||
A virtual machine which runs inside a Cluster.
|
A virtual machine which runs inside a Cluster.
|
||||||
"""
|
"""
|
||||||
@ -123,13 +124,6 @@ class VirtualMachine(ContactsMixin, PrimaryModel, ConfigContextModel):
|
|||||||
null=True,
|
null=True,
|
||||||
verbose_name=_('disk (GB)')
|
verbose_name=_('disk (GB)')
|
||||||
)
|
)
|
||||||
config_template = models.ForeignKey(
|
|
||||||
to='extras.ConfigTemplate',
|
|
||||||
on_delete=models.PROTECT,
|
|
||||||
related_name='virtual_machines',
|
|
||||||
blank=True,
|
|
||||||
null=True
|
|
||||||
)
|
|
||||||
|
|
||||||
# Counter fields
|
# Counter fields
|
||||||
interface_count = CounterCacheField(
|
interface_count = CounterCacheField(
|
||||||
@ -241,17 +235,6 @@ class VirtualMachine(ContactsMixin, PrimaryModel, ConfigContextModel):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_config_template(self):
|
|
||||||
"""
|
|
||||||
Return the appropriate ConfigTemplate (if any) for this Device.
|
|
||||||
"""
|
|
||||||
if self.config_template:
|
|
||||||
return self.config_template
|
|
||||||
if self.role.config_template:
|
|
||||||
return self.role.config_template
|
|
||||||
if self.platform and self.platform.config_template:
|
|
||||||
return self.platform.config_template
|
|
||||||
|
|
||||||
|
|
||||||
class VMInterface(NetBoxModel, BaseInterface, TrackingModelMixin):
|
class VMInterface(NetBoxModel, BaseInterface, TrackingModelMixin):
|
||||||
virtual_machine = models.ForeignKey(
|
virtual_machine = models.ForeignKey(
|
||||||
|
Loading…
Reference in New Issue
Block a user