1
0
Fork 0
Netbox-DNAC-Integration/dnac_integration/models.py

83 lines
2.5 KiB
Python
Raw Normal View History

2024-02-15 17:48:23 +00:00
from django.db import models
from django.urls import reverse
from netbox.models.features import ChangeLoggingMixin, TagsMixin
from netbox.models import NetBoxModel
class dnacServer(NetBoxModel):
# Change Logging Fields
created = models.DateTimeField(
auto_now_add=True,
blank=True,
null=True
)
last_updated = models.DateTimeField(
auto_now=True,
blank=True,
null=True
)
# DNAC Server Fields
hostname = models.CharField(max_length=2000, unique=True, blank=True, null=True)
username = models.CharField(max_length=100)
password = models.CharField(max_length=100)
version = models.CharField(max_length=10)
verify = models.BooleanField(default=False)
status = models.BooleanField(default=True)
# Filter options
## This action should be utilized when no matching filter is found in dnacFilters, given it's associated site
default_filter_action = models.BooleanField(default=False) # True=ALLOW | False=DENY
# Ordering of the data
class Meta:
ordering = ('hostname',)
# Required variables
def __str__(self):
return self.hostname
def get_absolute_url(self):
return reverse('plugins:dnac_integration:dnacServer', args=[self.pk])
class dnacSite(NetBoxModel):
_netbox_private = True
site = models.CharField(max_length=2000, unique=True)
parent = models.ForeignKey(
'self',
on_delete=models.CASCADE,
blank=True,
null=True
)
## TODO: allow generic models OR create ContentType of SITE,SITE_GROUP,REGION
#assocation = models.ForeignKey()
class Meta:
ordering = ('parent', 'site',)
def __str__(self):
return self.site
def get_absolute_url(self):
return reverse('plugins:dnac_integration:dnacSite', args=[self.pk])
class dnacFilter(NetBoxModel):
server = models.OneToOneField(
to=dnacServer,
on_delete=models.CASCADE,
unique=True
)
priority = models.PositiveSmallIntegerField()
action = models.BooleanField(default=False) # True=ALLOW | False=DENY
## TODO: Figure out how to define this, should be able to filter on DEVICE TYPE, DEVICE STATUS, ROLE
## This should allow allow actions, ie REGEX_MATCH charfield, EXISTS netbox object?
class Meta:
ordering = ('server', 'priority', )
def __str__(self):
return "FIXME! server:priority:rule:action"
def get_absolute_url(self):
return reverse('plugins:dnac_integration:dnacFilter', args=[self.pk])