|
|
|
@ -59,42 +59,70 @@ class Asset(models.Model):
|
|
|
|
|
('Other', 'Other'), |
|
|
|
|
) |
|
|
|
|
id = models.UUIDField(default=uuid.uuid4, primary_key=True) |
|
|
|
|
ip = models.GenericIPAddressField(max_length=32, verbose_name=_('IP'), db_index=True) |
|
|
|
|
hostname = models.CharField(max_length=128, unique=True, verbose_name=_('Hostname')) |
|
|
|
|
ip = models.GenericIPAddressField(max_length=32, verbose_name=_('IP'), |
|
|
|
|
db_index=True) |
|
|
|
|
hostname = models.CharField(max_length=128, unique=True, |
|
|
|
|
verbose_name=_('Hostname')) |
|
|
|
|
port = models.IntegerField(default=22, verbose_name=_('Port')) |
|
|
|
|
platform = models.CharField(max_length=128, choices=PLATFORM_CHOICES, default='Linux', verbose_name=_('Platform')) |
|
|
|
|
domain = models.ForeignKey("assets.Domain", null=True, blank=True, related_name='assets', verbose_name=_("Domain"), on_delete=models.SET_NULL) |
|
|
|
|
nodes = models.ManyToManyField('assets.Node', default=default_node, related_name='assets', verbose_name=_("Nodes")) |
|
|
|
|
platform = models.CharField(max_length=128, choices=PLATFORM_CHOICES, |
|
|
|
|
default='Linux', verbose_name=_('Platform')) |
|
|
|
|
domain = models.ForeignKey("assets.Domain", null=True, blank=True, |
|
|
|
|
related_name='assets', verbose_name=_("Domain"), |
|
|
|
|
on_delete=models.SET_NULL) |
|
|
|
|
nodes = models.ManyToManyField('assets.Node', default=default_node, |
|
|
|
|
related_name='assets', |
|
|
|
|
verbose_name=_("Nodes")) |
|
|
|
|
is_active = models.BooleanField(default=True, verbose_name=_('Is active')) |
|
|
|
|
|
|
|
|
|
# Auth |
|
|
|
|
admin_user = models.ForeignKey('assets.AdminUser', on_delete=models.PROTECT, null=True, verbose_name=_("Admin user")) |
|
|
|
|
admin_user = models.ForeignKey('assets.AdminUser', on_delete=models.PROTECT, |
|
|
|
|
null=True, verbose_name=_("Admin user")) |
|
|
|
|
|
|
|
|
|
# Some information |
|
|
|
|
public_ip = models.GenericIPAddressField(max_length=32, blank=True, null=True, verbose_name=_('Public IP')) |
|
|
|
|
number = models.CharField(max_length=32, null=True, blank=True, verbose_name=_('Asset number')) |
|
|
|
|
public_ip = models.GenericIPAddressField(max_length=32, blank=True, |
|
|
|
|
null=True, |
|
|
|
|
verbose_name=_('Public IP')) |
|
|
|
|
number = models.CharField(max_length=32, null=True, blank=True, |
|
|
|
|
verbose_name=_('Asset number')) |
|
|
|
|
|
|
|
|
|
# Collect |
|
|
|
|
vendor = models.CharField(max_length=64, null=True, blank=True, verbose_name=_('Vendor')) |
|
|
|
|
model = models.CharField(max_length=54, null=True, blank=True, verbose_name=_('Model')) |
|
|
|
|
sn = models.CharField(max_length=128, null=True, blank=True, verbose_name=_('Serial number')) |
|
|
|
|
|
|
|
|
|
cpu_model = models.CharField(max_length=64, null=True, blank=True, verbose_name=_('CPU model')) |
|
|
|
|
vendor = models.CharField(max_length=64, null=True, blank=True, |
|
|
|
|
verbose_name=_('Vendor')) |
|
|
|
|
model = models.CharField(max_length=54, null=True, blank=True, |
|
|
|
|
verbose_name=_('Model')) |
|
|
|
|
sn = models.CharField(max_length=128, null=True, blank=True, |
|
|
|
|
verbose_name=_('Serial number')) |
|
|
|
|
|
|
|
|
|
cpu_model = models.CharField(max_length=64, null=True, blank=True, |
|
|
|
|
verbose_name=_('CPU model')) |
|
|
|
|
cpu_count = models.IntegerField(null=True, verbose_name=_('CPU count')) |
|
|
|
|
cpu_cores = models.IntegerField(null=True, verbose_name=_('CPU cores')) |
|
|
|
|
memory = models.CharField(max_length=64, null=True, blank=True, verbose_name=_('Memory')) |
|
|
|
|
disk_total = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('Disk total')) |
|
|
|
|
disk_info = models.CharField(max_length=1024, null=True, blank=True, verbose_name=_('Disk info')) |
|
|
|
|
|
|
|
|
|
os = models.CharField(max_length=128, null=True, blank=True, verbose_name=_('OS')) |
|
|
|
|
os_version = models.CharField(max_length=16, null=True, blank=True, verbose_name=_('OS version')) |
|
|
|
|
os_arch = models.CharField(max_length=16, blank=True, null=True, verbose_name=_('OS arch')) |
|
|
|
|
hostname_raw = models.CharField(max_length=128, blank=True, null=True, verbose_name=_('Hostname raw')) |
|
|
|
|
|
|
|
|
|
labels = models.ManyToManyField('assets.Label', blank=True, related_name='assets', verbose_name=_("Labels")) |
|
|
|
|
created_by = models.CharField(max_length=32, null=True, blank=True, verbose_name=_('Created by')) |
|
|
|
|
date_created = models.DateTimeField(auto_now_add=True, null=True, blank=True, verbose_name=_('Date created')) |
|
|
|
|
comment = models.TextField(max_length=128, default='', blank=True, verbose_name=_('Comment')) |
|
|
|
|
memory = models.CharField(max_length=64, null=True, blank=True, |
|
|
|
|
verbose_name=_('Memory')) |
|
|
|
|
disk_total = models.CharField(max_length=1024, null=True, blank=True, |
|
|
|
|
verbose_name=_('Disk total')) |
|
|
|
|
disk_info = models.CharField(max_length=1024, null=True, blank=True, |
|
|
|
|
verbose_name=_('Disk info')) |
|
|
|
|
|
|
|
|
|
os = models.CharField(max_length=128, null=True, blank=True, |
|
|
|
|
verbose_name=_('OS')) |
|
|
|
|
os_version = models.CharField(max_length=16, null=True, blank=True, |
|
|
|
|
verbose_name=_('OS version')) |
|
|
|
|
os_arch = models.CharField(max_length=16, blank=True, null=True, |
|
|
|
|
verbose_name=_('OS arch')) |
|
|
|
|
hostname_raw = models.CharField(max_length=128, blank=True, null=True, |
|
|
|
|
verbose_name=_('Hostname raw')) |
|
|
|
|
|
|
|
|
|
labels = models.ManyToManyField('assets.Label', blank=True, |
|
|
|
|
related_name='assets', |
|
|
|
|
verbose_name=_("Labels")) |
|
|
|
|
created_by = models.CharField(max_length=32, null=True, blank=True, |
|
|
|
|
verbose_name=_('Created by')) |
|
|
|
|
date_created = models.DateTimeField(auto_now_add=True, null=True, |
|
|
|
|
blank=True, |
|
|
|
|
verbose_name=_('Date created')) |
|
|
|
|
comment = models.TextField(max_length=128, default='', blank=True, |
|
|
|
|
verbose_name=_('Comment')) |
|
|
|
|
|
|
|
|
|
objects = AssetManager() |
|
|
|
|
|
|
|
|
@ -121,6 +149,22 @@ class Asset(models.Model):
|
|
|
|
|
nodes = self.nodes.all() or [Node.root()] |
|
|
|
|
return nodes |
|
|
|
|
|
|
|
|
|
@property |
|
|
|
|
def nodes_cache_key(self): |
|
|
|
|
key = "NODES_OF_{}".format(str(self.id)) |
|
|
|
|
return key |
|
|
|
|
|
|
|
|
|
def get_nodes_or_cache(self): |
|
|
|
|
cached = cache.get(self.nodes_cache_key) |
|
|
|
|
if cached is not None: |
|
|
|
|
return cached |
|
|
|
|
nodes = list(self.get_nodes()) |
|
|
|
|
cache.set(self.nodes_cache_key, nodes, 3600) |
|
|
|
|
return nodes |
|
|
|
|
|
|
|
|
|
def expire_nodes_cache(self): |
|
|
|
|
cache.delete(self.nodes_cache_key) |
|
|
|
|
|
|
|
|
|
@property |
|
|
|
|
def hardware_info(self): |
|
|
|
|
if self.cpu_count: |
|
|
|
|