Verified Commit aa3ef40e authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Use Django model without NOCModel.

parent 79377b7d
......@@ -11,14 +11,19 @@ import operator
from typing import Optional, TYPE_CHECKING
# Third-party modules
from noc.core.translation import ugettext as _
from django.contrib.postgres.fields import ArrayField
from django.db import models
from django.db.models import Model
from django.db.models import (
CharField,
TextField,
ForeignKey,
BigIntegerField,
CASCADE,
)
import cachetools
# NOC modules
from noc.config import config
from noc.core.model.base import NOCModel
from noc.main.models.pool import Pool
from noc.main.models.template import Template
from noc.main.models.remotesystem import RemoteSystem
......@@ -27,6 +32,7 @@ from noc.core.model.fields import DocumentReferenceField
from noc.core.model.decorator import on_delete_check, on_init, tree
from noc.core.bi.decorator import bi_sync
from noc.core.change.decorator import change
from noc.core.translation import ugettext as _
id_lock = Lock()
_path_cache = cachetools.TTLCache(maxsize=1000, ttl=60)
......@@ -53,7 +59,7 @@ _path_cache = cachetools.TTLCache(maxsize=1000, ttl=60)
],
clean_lazy_labels="adm_domain",
)
class AdministrativeDomain(NOCModel):
class AdministrativeDomain(Model):
"""
Administrative Domain
"""
......@@ -65,16 +71,12 @@ class AdministrativeDomain(NOCModel):
app_label = "sa"
ordering = ["name"]
name = models.CharField(_("Name"), max_length=255, unique=True)
parent = models.ForeignKey(
"self", verbose_name="Parent", null=True, blank=True, on_delete=models.CASCADE
)
description = models.TextField(_("Description"), null=True, blank=True)
name = CharField(_("Name"), max_length=255, unique=True)
parent = ForeignKey("self", verbose_name="Parent", null=True, blank=True, on_delete=CASCADE)
description = TextField(_("Description"), null=True, blank=True)
default_pool = DocumentReferenceField(Pool, null=True, blank=True)
# Biosegmentation settings
bioseg_floating_name_template = models.ForeignKey(
Template, null=True, blank=True, on_delete=models.CASCADE
)
bioseg_floating_name_template = ForeignKey(Template, null=True, blank=True, on_delete=CASCADE)
bioseg_floating_parent_segment = DocumentReferenceField(
"inv.NetworkSegment", null=True, blank=True
)
......@@ -82,14 +84,12 @@ class AdministrativeDomain(NOCModel):
# Reference to remote system object has been imported from
remote_system = DocumentReferenceField(RemoteSystem, null=True, blank=True)
# Object id in remote system
remote_id = models.CharField(max_length=64, null=True, blank=True)
remote_id = CharField(max_length=64, null=True, blank=True)
# Object id in BI
bi_id = models.BigIntegerField(unique=True)
bi_id = BigIntegerField(unique=True)
labels = ArrayField(models.CharField(max_length=250), blank=True, null=True, default=list)
effective_labels = ArrayField(
models.CharField(max_length=250), blank=True, null=True, default=list
)
labels = ArrayField(CharField(max_length=250), blank=True, null=True, default=list)
effective_labels = ArrayField(CharField(max_length=250), blank=True, null=True, default=list)
_id_cache = cachetools.TTLCache(maxsize=1000, ttl=60)
_bi_id_cache = cachetools.TTLCache(maxsize=1000, ttl=60)
......
......@@ -10,12 +10,18 @@ import operator
from threading import Lock
# Third-party modules
from django.db.models.base import Model
from django.contrib.postgres.fields import ArrayField
from django.db import models
from django.db.models import (
CharField,
TextField,
ForeignKey,
BigIntegerField,
CASCADE,
)
import cachetools
# NOC modules
from noc.core.model.base import NOCModel
from noc.main.models.remotesystem import RemoteSystem
from noc.main.models.label import Label
from noc.core.model.decorator import on_save
......@@ -38,7 +44,7 @@ id_lock = Lock()
("sa.ManagedObjectProfile", "cpe_auth_profile"),
]
)
class AuthProfile(NOCModel):
class AuthProfile(Model):
class Meta(object):
verbose_name = "Auth Profile"
verbose_name_plural = "Auth Profiles"
......@@ -46,9 +52,9 @@ class AuthProfile(NOCModel):
app_label = "sa"
ordering = ["name"]
name = models.CharField("Name", max_length=64, unique=True)
description = models.TextField("Description", null=True, blank=True)
type = models.CharField(
name = CharField("Name", max_length=64, unique=True)
description = TextField("Description", null=True, blank=True)
type = CharField(
"Name",
max_length=1,
choices=[
......@@ -59,23 +65,21 @@ class AuthProfile(NOCModel):
("S", "Suggest"),
],
)
user = models.CharField("User", max_length=32, blank=True, null=True)
password = models.CharField("Password", max_length=32, blank=True, null=True)
super_password = models.CharField("Super Password", max_length=32, blank=True, null=True)
snmp_ro = models.CharField("RO Community", blank=True, null=True, max_length=64)
snmp_rw = models.CharField("RW Community", blank=True, null=True, max_length=64)
user = CharField("User", max_length=32, blank=True, null=True)
password = CharField("Password", max_length=32, blank=True, null=True)
super_password = CharField("Super Password", max_length=32, blank=True, null=True)
snmp_ro = CharField("RO Community", blank=True, null=True, max_length=64)
snmp_rw = CharField("RW Community", blank=True, null=True, max_length=64)
# Integration with external NRI systems
# Reference to remote system object has been imported from
remote_system = DocumentReferenceField(RemoteSystem, null=True, blank=True)
# Object id in remote system
remote_id = models.CharField(max_length=64, null=True, blank=True)
remote_id = CharField(max_length=64, null=True, blank=True)
# Object id in BI
bi_id = models.BigIntegerField(unique=True)
bi_id = BigIntegerField(unique=True)
labels = ArrayField(models.CharField(max_length=250), blank=True, null=True, default=list)
effective_labels = ArrayField(
models.CharField(max_length=250), blank=True, null=True, default=list
)
labels = ArrayField(CharField(max_length=250), blank=True, null=True, default=list)
effective_labels = ArrayField(CharField(max_length=250), blank=True, null=True, default=list)
_id_cache = cachetools.TTLCache(maxsize=100, ttl=60)
......@@ -126,36 +130,32 @@ class AuthProfile(NOCModel):
return Label.get_effective_setting(label, setting="enable_authprofile")
class AuthProfileSuggestSNMP(NOCModel):
class AuthProfileSuggestSNMP(Model):
class Meta(object):
verbose_name = "Auth Profile Suggest SNMP"
verbose_name_plural = "Auth Profile Suggest SNMP"
db_table = "sa_authprofilesuggestsnmp"
app_label = "sa"
auth_profile = models.ForeignKey(
AuthProfile, verbose_name="Auth Profile", on_delete=models.CASCADE
)
snmp_ro = models.CharField("RO Community", blank=True, null=True, max_length=64)
snmp_rw = models.CharField("RW Community", blank=True, null=True, max_length=64)
auth_profile = ForeignKey(AuthProfile, verbose_name="Auth Profile", on_delete=CASCADE)
snmp_ro = CharField("RO Community", blank=True, null=True, max_length=64)
snmp_rw = CharField("RW Community", blank=True, null=True, max_length=64)
def __str__(self):
return self.auth_profile.name
class AuthProfileSuggestCLI(NOCModel):
class AuthProfileSuggestCLI(Model):
class Meta(object):
verbose_name = "Auth Profile Suggest CLI"
verbose_name_plural = "Auth Profile Suggest CLI"
db_table = "sa_authprofilesuggestcli"
app_label = "sa"
auth_profile = models.ForeignKey(
AuthProfile, verbose_name="Auth Profile", on_delete=models.CASCADE
)
user = models.CharField("User", max_length=32, blank=True, null=True)
password = models.CharField("Password", max_length=32, blank=True, null=True)
super_password = models.CharField("Super Password", max_length=32, blank=True, null=True)
auth_profile = ForeignKey(AuthProfile, verbose_name="Auth Profile", on_delete=CASCADE)
user = CharField("User", max_length=32, blank=True, null=True)
password = CharField("Password", max_length=32, blank=True, null=True)
super_password = CharField("Super Password", max_length=32, blank=True, null=True)
def __str__(self):
return self.auth_profile.name
......@@ -21,6 +21,7 @@ from typing import Tuple, Iterable, List, Any, Dict, Set
# Third-party modules
import orjson
from django.contrib.postgres.fields import ArrayField
from django.db.models.base import Model
from django.db.models import (
Q,
CharField,
......@@ -175,7 +176,7 @@ logger = logging.getLogger(__name__)
],
clean=[("ip.Address", "managed_object"), ("sa.Service", "managed_object")],
)
class ManagedObject(NOCModel):
class ManagedObject(Model):
"""
Managed Object
"""
......
......@@ -13,14 +13,13 @@ from dataclasses import dataclass
from typing import Optional, List, Dict
# Third-party modules
import cachetools
from django.contrib.postgres.fields import ArrayField
from django.db import models
import cachetools
from django.db.models.base import Model
from pydantic import BaseModel, validator
# NOC modules
from noc.core.translation import ugettext as _
from noc.core.model.base import NOCModel
from noc.config import config
from noc.main.models.style import Style
from noc.core.stencil import stencil_registry
......@@ -50,6 +49,7 @@ from noc.pm.models.thresholdprofile import ThresholdProfile
from .authprofile import AuthProfile
from .capsprofile import CapsProfile
from noc.vc.models.vlanfilter import VLANFilter
from noc.core.translation import ugettext as _
metrics_lock = Lock()
......@@ -127,7 +127,7 @@ id_lock = Lock()
],
clean_lazy_labels="managedobjectprofile",
)
class ManagedObjectProfile(NOCModel):
class ManagedObjectProfile(Model):
class Meta(object):
verbose_name = _("Managed Object Profile")
verbose_name_plural = _("Managed Object Profiles")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment