mirror of https://github.com/jumpserver/jumpserver
perf: 修改 base
parent
832228e184
commit
54e772741b
|
@ -15,6 +15,10 @@ class Migration(migrations.Migration):
|
|||
migrations.CreateModel(
|
||||
name='DeviceInfo',
|
||||
fields=[
|
||||
('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
|
||||
('created_by', models.CharField(blank=True, max_length=32, null=True, verbose_name='Created by')),
|
||||
('date_created', models.DateTimeField(auto_now_add=True, null=True, verbose_name='Date created')),
|
||||
('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
|
||||
('vendor', models.CharField(blank=True, max_length=64, null=True, verbose_name='Vendor')),
|
||||
('model', models.CharField(blank=True, max_length=54, null=True, verbose_name='Model')),
|
||||
('sn', models.CharField(blank=True, max_length=128, null=True, verbose_name='Serial number')),
|
||||
|
@ -29,10 +33,7 @@ class Migration(migrations.Migration):
|
|||
('os_version', models.CharField(blank=True, max_length=16, null=True, verbose_name='OS version')),
|
||||
('os_arch', models.CharField(blank=True, max_length=16, null=True, verbose_name='OS arch')),
|
||||
('hostname_raw', models.CharField(blank=True, max_length=128, null=True, verbose_name='Hostname raw')),
|
||||
('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
|
||||
('created_by', models.CharField(blank=True, max_length=32, null=True, verbose_name='Created by')),
|
||||
('date_created', models.DateTimeField(auto_now_add=True, null=True, verbose_name='Date created')),
|
||||
('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
|
||||
('host', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='assets.host', verbose_name='Host')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'DeviceInfo',
|
||||
|
|
|
@ -27,6 +27,7 @@ def migrate_hardware(apps, *args):
|
|||
if not hosts:
|
||||
break
|
||||
|
||||
hardware_infos = []
|
||||
for host in hosts:
|
||||
hardware = hardware_model()
|
||||
asset = asset_mapper[host.asset_ptr_id]
|
||||
|
@ -34,9 +35,10 @@ def migrate_hardware(apps, *args):
|
|||
hardware.date_updated = timezone.now()
|
||||
for name in fields:
|
||||
setattr(hardware, name, getattr(asset, name))
|
||||
hardware.save()
|
||||
host.device_info = hardware
|
||||
host.save()
|
||||
hardware_infos.append(hardware)
|
||||
|
||||
hardware_model.objects.bulk_create(hardware_infos, ignore_conflicts=True)
|
||||
created += len(hardware_infos)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
@ -46,10 +48,5 @@ class Migration(migrations.Migration):
|
|||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='host',
|
||||
name='device_info',
|
||||
field=models.ForeignKey(null=True, on_delete=models.deletion.SET_NULL, to='assets.deviceinfo', verbose_name='Device info'),
|
||||
),
|
||||
migrations.RunPython(migrate_hardware)
|
||||
]
|
||||
|
|
|
@ -4,14 +4,6 @@ from itertools import groupby
|
|||
from django.db import migrations
|
||||
from django.db.models import F
|
||||
|
||||
|
||||
# ('Linux', 'Linux'),
|
||||
# ('Unix', 'Unix'),
|
||||
# ('MacOS', 'MacOS'),
|
||||
# ('BSD', 'BSD'),
|
||||
# ('Windows', 'Windows'),
|
||||
# ('Other', 'Other'),
|
||||
|
||||
category_mapper = {
|
||||
'Linux': ('host', 'linux'),
|
||||
'Unix': ('host', 'unix'),
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
# Generated by Django 3.1.14 on 2022-04-12 11:07
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('assets', '0097_auto_20220407_1726'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='deviceinfo',
|
||||
name='host',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='host',
|
||||
name='device_info',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='assets.deviceinfo', verbose_name='Device info'),
|
||||
),
|
||||
]
|
|
@ -1,3 +1,2 @@
|
|||
from .common import *
|
||||
from .device_info import *
|
||||
from .host import *
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
from django.utils.translation import gettext_lazy as _
|
||||
from django.db import models
|
||||
|
||||
from common.mixins.models import CommonModelMixin
|
||||
|
||||
__all__ = ['DeviceInfo']
|
||||
|
||||
|
||||
class DeviceInfo(CommonModelMixin):
|
||||
# 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'))
|
||||
|
||||
@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):
|
||||
return '{} of {}'.format(self.hardware_info, self.host.hostname)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("DeviceInfo")
|
|
@ -1,9 +1,9 @@
|
|||
# from django.db import models
|
||||
# from django.utils.translation import gettext_lazy as _
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from common.mixins.models import CommonModelMixin
|
||||
from assets.const import Category
|
||||
from .common import Asset
|
||||
# from .device_info import DeviceInfo
|
||||
|
||||
|
||||
class Host(Asset):
|
||||
|
@ -12,3 +12,48 @@ class Host(Asset):
|
|||
return super().save(*args, **kwargs)
|
||||
|
||||
|
||||
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'))
|
||||
|
||||
@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):
|
||||
return '{} of {}'.format(self.hardware_info, self.host.hostname)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("DeviceInfo")
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ from django.utils.translation import gettext_lazy as _
|
|||
from assets.const import Category, AllTypes
|
||||
from common.fields.model import JsonDictTextField
|
||||
|
||||
|
||||
__all__ = ['Platform']
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
from common.db.models import JMSBaseModel
|
||||
|
||||
|
||||
class Protocol(JMSBaseModel):
|
||||
pass
|
Loading…
Reference in New Issue