mirror of https://github.com/jumpserver/jumpserver
perf: 修改 models
parent
1d1b252e58
commit
a86d5c1456
|
@ -9,19 +9,16 @@ def migrate_to_host(apps, schema_editor):
|
|||
host_model = apps.get_model("assets", 'Host')
|
||||
db_alias = schema_editor.connection.alias
|
||||
|
||||
created = 0
|
||||
count = 0
|
||||
batch_size = 1000
|
||||
|
||||
while True:
|
||||
start = created
|
||||
end = created + batch_size
|
||||
assets = asset_model.objects.using(db_alias).all()[start:end]
|
||||
assets = asset_model.objects.using(db_alias).all()[count:count+batch_size]
|
||||
if not assets:
|
||||
break
|
||||
|
||||
count += len(assets)
|
||||
hosts = [host_model(asset_ptr=asset) for asset in assets]
|
||||
host_model.objects.using(db_alias).bulk_create(hosts, ignore_conflicts=True)
|
||||
created += len(hosts)
|
||||
|
||||
|
||||
def migrate_hardware_info(apps, *args):
|
||||
|
@ -36,15 +33,14 @@ def migrate_hardware_info(apps, *args):
|
|||
]
|
||||
|
||||
while True:
|
||||
start = count
|
||||
end = count + batch_size
|
||||
assets = asset_model.objects.all()[start:end]
|
||||
assets = asset_model.objects.all()[count:count+batch_size]
|
||||
if not assets:
|
||||
break
|
||||
count += len(assets)
|
||||
|
||||
updated = []
|
||||
for asset in assets:
|
||||
info = {getattr(asset, field) for field in hardware_fields if getattr(asset, field)}
|
||||
info = {field: getattr(asset, field) for field in hardware_fields if getattr(asset, field)}
|
||||
if not info:
|
||||
continue
|
||||
asset.info = info
|
||||
|
|
|
@ -39,7 +39,6 @@ class Migration(migrations.Migration):
|
|||
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
|
||||
('asset', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='assets.asset', verbose_name='Asset')),
|
||||
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
|
||||
('su_from', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='assets.account', verbose_name='Su from')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'historical Account',
|
||||
|
@ -67,7 +66,6 @@ class Migration(migrations.Migration):
|
|||
('privileged', models.BooleanField(default=False, verbose_name='Privileged')),
|
||||
('version', models.IntegerField(default=0, verbose_name='Version')),
|
||||
('asset', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='accounts', to='assets.asset', verbose_name='Asset')),
|
||||
('su_from', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='su_to', to='assets.account', verbose_name='Su from')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Account',
|
||||
|
@ -75,4 +73,14 @@ class Migration(migrations.Migration):
|
|||
'unique_together': {('username', 'asset'), ('name', 'asset')},
|
||||
},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='account',
|
||||
name='su_from',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='su_to', to='assets.account', verbose_name='Su from'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='historicalaccount',
|
||||
name='su_from',
|
||||
field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='assets.account', verbose_name='Su from'),
|
||||
),
|
||||
]
|
||||
|
|
|
@ -36,9 +36,20 @@ def update_internal_platforms(platform_model):
|
|||
'change_password_method': 'change_password_aix',
|
||||
},
|
||||
{'name': 'Windows', 'category': 'host', 'type': 'windows'},
|
||||
{'name': 'Windows-TLS', 'category': 'host', 'type': 'windows'},
|
||||
{'name': 'Windows-RDP', 'category': 'host', 'type': 'windows'},
|
||||
|
||||
{
|
||||
'name': 'Windows-TLS', 'category': 'host', 'type': 'windows',
|
||||
'protocols': [
|
||||
{'name': 'rdp', 'port': 3389, 'setting': {'security': 'tls'}},
|
||||
{'name': 'ssh', 'port': 22},
|
||||
]
|
||||
},
|
||||
{
|
||||
'name': 'Windows-RDP', 'category': 'host', 'type': 'windows',
|
||||
'protocols': [
|
||||
{'name': 'rdp', 'port': 3389, 'setting': {'security': 'rdp'}},
|
||||
{'name': 'ssh', 'port': 22},
|
||||
]
|
||||
},
|
||||
# 数据库
|
||||
{'name': 'MySQL', 'category': 'database', 'type': 'mysql'},
|
||||
{'name': 'PostgreSQL', 'category': 'database', 'type': 'postgresql'},
|
||||
|
@ -48,10 +59,10 @@ def update_internal_platforms(platform_model):
|
|||
{'name': 'Redis', 'category': 'database', 'type': 'redis'},
|
||||
|
||||
# 网络设备
|
||||
{'name': 'Generic', 'category': 'networking', 'type': 'general'},
|
||||
{'name': 'Huawei', 'category': 'networking', 'type': 'general'},
|
||||
{'name': 'Cisco', 'category': 'networking', 'type': 'general'},
|
||||
{'name': 'H3C', 'category': 'networking', 'type': 'general'},
|
||||
{'name': 'Generic', 'category': 'networking', 'type': 'general', 'brand': 'other'},
|
||||
{'name': 'Huawei', 'category': 'networking', 'type': 'general', 'brand': 'huawei'},
|
||||
{'name': 'Cisco', 'category': 'networking', 'type': 'general', 'brand': 'cisco'},
|
||||
{'name': 'H3C', 'category': 'networking', 'type': 'general', 'brand': 'h3c'},
|
||||
|
||||
# Web
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
vars:
|
||||
connection_type: ssh
|
||||
password:
|
||||
value: {{ password}}
|
||||
value: {{ password }}
|
||||
public_key:
|
||||
value: {{ jms_key }}
|
||||
exclusive: {{ exclusive }}
|
||||
|
|
Loading…
Reference in New Issue