mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-25 08:46:10 -06:00
6347 fix tracking mixin to tracked-classes
This commit is contained in:
parent
8b8e9a44e5
commit
4156fb31b8
@ -9,10 +9,7 @@ class DCIMConfig(AppConfig):
|
||||
|
||||
def ready(self):
|
||||
from . import signals, search
|
||||
from .models import (
|
||||
CableTermination, ConsolePort, ConsoleServerPort, DeviceBay, FrontPort,
|
||||
Interface, InventoryItem, PowerOutlet, PowerPort, RearPort,
|
||||
)
|
||||
from .models import CableTermination, Device
|
||||
|
||||
from utilities.counter import connect_counters
|
||||
|
||||
@ -30,4 +27,4 @@ class DCIMConfig(AppConfig):
|
||||
'_site': 'site',
|
||||
})
|
||||
|
||||
connect_counters(self)
|
||||
connect_counters([Device,])
|
||||
|
@ -470,7 +470,7 @@ class PowerOutlet(ModularComponentModel, CabledObjectModel, PathEndpoint, Tracki
|
||||
# Interfaces
|
||||
#
|
||||
|
||||
class BaseInterface(models.Model, TrackingModelMixin):
|
||||
class BaseInterface(models.Model):
|
||||
"""
|
||||
Abstract base class for fields shared by dcim.Interface and virtualization.VMInterface.
|
||||
"""
|
||||
@ -538,7 +538,7 @@ class BaseInterface(models.Model, TrackingModelMixin):
|
||||
return self.fhrp_group_assignments.count()
|
||||
|
||||
|
||||
class Interface(ModularComponentModel, BaseInterface, CabledObjectModel, PathEndpoint):
|
||||
class Interface(ModularComponentModel, BaseInterface, CabledObjectModel, PathEndpoint, TrackingModelMixin):
|
||||
"""
|
||||
A network interface within a Device. A physical Interface can connect to exactly one other Interface.
|
||||
"""
|
||||
|
@ -78,13 +78,11 @@ class Counter:
|
||||
return self.set_counter_field(parent_id, F(self.counter_name) + amount)
|
||||
|
||||
|
||||
def connect_counters(app_config):
|
||||
models = app_config.get_models()
|
||||
def connect_counters(models):
|
||||
for model in models:
|
||||
if issubclass(model, TrackingModelMixin):
|
||||
fields = model._meta.get_fields()
|
||||
for field in fields:
|
||||
if type(field) is CounterCacheField:
|
||||
to_model = apps.get_model(field.to_model_name)
|
||||
to_field = getattr(to_model, field.to_field_name)
|
||||
Counter(field.name, to_field)
|
||||
fields = model._meta.get_fields()
|
||||
for field in fields:
|
||||
if type(field) is CounterCacheField:
|
||||
to_model = apps.get_model(field.to_model_name)
|
||||
to_field = getattr(to_model, field.to_field_name)
|
||||
Counter(field.name, to_field)
|
||||
|
@ -26,7 +26,7 @@ class CountersTest(TestCase):
|
||||
|
||||
def test_interface_count_addition(self):
|
||||
"""
|
||||
When a new Cable is created, it must be cached on either termination point.
|
||||
When a tracked object (Interface) is added the tracking counter should be updated.
|
||||
"""
|
||||
device1 = Device.objects.get(name='TestDevice1')
|
||||
device2 = Device.objects.get(name='TestDevice2')
|
||||
@ -43,8 +43,7 @@ class CountersTest(TestCase):
|
||||
|
||||
def test_interface_count_deletion(self):
|
||||
"""
|
||||
When a Cable is deleted, the `cable` field on its termination points must be nullified. The str() method
|
||||
should still return the PK of the string even after being nullified.
|
||||
When a tracked object (Interface) is deleted the tracking counter should be updated.
|
||||
"""
|
||||
device1 = Device.objects.get(name='TestDevice1')
|
||||
device2 = Device.objects.get(name='TestDevice2')
|
||||
|
@ -6,6 +6,7 @@ class VirtualizationConfig(AppConfig):
|
||||
|
||||
def ready(self):
|
||||
from . import search
|
||||
from .models import VirtualMachine
|
||||
from utilities.counter import connect_counters
|
||||
|
||||
connect_counters(self)
|
||||
connect_counters([VirtualMachine,])
|
||||
|
Loading…
Reference in New Issue
Block a user