jumpserver/apps/assets/models/asset/host.py

61 lines
2.5 KiB
Python
Raw Normal View History

2022-04-20 02:15:20 +00:00
from django.db import models
from django.utils.translation import gettext_lazy as _
2022-04-02 10:35:46 +00:00
2022-04-20 02:15:20 +00:00
from common.mixins.models import CommonModelMixin
2022-04-07 10:51:35 +00:00
from assets.const import Category
2022-04-02 10:35:46 +00:00
from .common import Asset
class Host(Asset):
2022-04-07 10:51:35 +00:00
def save(self, *args, **kwargs):
self.category = Category.HOST
return super().save(*args, **kwargs)
2022-04-02 10:35:46 +00:00
2022-04-20 02:15:20 +00:00
class DeviceInfo(CommonModelMixin):
host = models.ForeignKey(Host, on_delete=models.CASCADE, verbose_name=_("Host"))
# 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'))
cpu_count = models.IntegerField(null=True, verbose_name=_('CPU count'))
cpu_cores = models.IntegerField(null=True, verbose_name=_('CPU cores'))
cpu_vcpus = models.IntegerField(null=True, verbose_name=_('CPU vcpus'))
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'))
2022-08-11 07:45:03 +00:00
number = models.CharField(max_length=128, null=True, blank=True, verbose_name=_('Asset number'))
2022-04-20 02:15:20 +00:00
@property
def cpu_info(self):
info = ""
if self.cpu_model:
info += self.cpu_model
if self.cpu_count and self.cpu_cores:
info += "{}*{}".format(self.cpu_count, self.cpu_cores)
return info
@property
def hardware_info(self):
if self.cpu_count:
return '{} Core {} {}'.format(
self.cpu_vcpus or self.cpu_count * self.cpu_cores,
self.memory, self.disk_total
)
else:
return ''
def __str__(self):
2022-08-11 07:45:03 +00:00
return '{} of {}'.format(self.hardware_info, self.host.name)
2022-04-20 02:15:20 +00:00
class Meta:
verbose_name = _("DeviceInfo")