mirror of https://github.com/jumpserver/jumpserver
perf: 优化提示
parent
180ded1773
commit
ba076f6612
|
@ -8,7 +8,7 @@ def migrate_platform_charset(apps, schema_editor):
|
||||||
platform_model.objects.filter(charset='utf8').update(charset='utf-8')
|
platform_model.objects.filter(charset='utf8').update(charset='utf-8')
|
||||||
|
|
||||||
|
|
||||||
def migrate_platform_protocol_required(apps, schema_editor):
|
def migrate_platform_protocol_primary(apps, schema_editor):
|
||||||
platform_model = apps.get_model('assets', 'Platform')
|
platform_model = apps.get_model('assets', 'Platform')
|
||||||
platforms = platform_model.objects.all()
|
platforms = platform_model.objects.all()
|
||||||
|
|
||||||
|
@ -31,5 +31,5 @@ class Migration(migrations.Migration):
|
||||||
field=models.BooleanField(default=False, verbose_name='Primary'),
|
field=models.BooleanField(default=False, verbose_name='Primary'),
|
||||||
),
|
),
|
||||||
migrations.RunPython(migrate_platform_charset),
|
migrations.RunPython(migrate_platform_charset),
|
||||||
migrations.RunPython(migrate_platform_protocol_required),
|
migrations.RunPython(migrate_platform_protocol_primary),
|
||||||
]
|
]
|
||||||
|
|
|
@ -132,6 +132,7 @@ class PlatformSerializer(WritableNestedModelSerializer):
|
||||||
if not primary:
|
if not primary:
|
||||||
protocols[0]['primary'] = True
|
protocols[0]['primary'] = True
|
||||||
protocols[0]['default'] = False
|
protocols[0]['default'] = False
|
||||||
|
# 这里不设置不行,write_nested 不使用 validated 中的
|
||||||
self.initial_data['protocols'] = protocols
|
self.initial_data['protocols'] = protocols
|
||||||
return protocols
|
return protocols
|
||||||
|
|
||||||
|
|
|
@ -100,9 +100,17 @@ class JMSInventory:
|
||||||
host.update(self.make_proxy_command(gateway))
|
host.update(self.make_proxy_command(gateway))
|
||||||
|
|
||||||
def asset_to_host(self, asset, account, automation, protocols, platform):
|
def asset_to_host(self, asset, account, automation, protocols, platform):
|
||||||
if protocols:
|
primary_protocol = [p for p in protocols if p.primary]
|
||||||
protocol = protocols[0].name
|
if len(primary_protocol) >= 1:
|
||||||
port = protocol[0].port
|
primary = primary_protocol[0]
|
||||||
|
elif protocols:
|
||||||
|
primary = protocols[0]
|
||||||
|
else:
|
||||||
|
primary = None
|
||||||
|
|
||||||
|
if primary:
|
||||||
|
protocol = primary.name
|
||||||
|
port = primary.port
|
||||||
else:
|
else:
|
||||||
protocol = 'null'
|
protocol = 'null'
|
||||||
port = 0
|
port = 0
|
||||||
|
|
Loading…
Reference in New Issue