2016-12-20 16:43:52 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
|
2017-12-11 09:08:43 +00:00
|
|
|
from django.core.exceptions import ValidationError
|
2019-06-24 06:23:29 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
2017-12-11 09:08:43 +00:00
|
|
|
from common.utils import validate_ssh_private_key
|
|
|
|
|
2016-12-20 16:43:52 +00:00
|
|
|
|
2019-06-24 06:23:29 +00:00
|
|
|
__all__ = [
|
2022-08-17 03:54:18 +00:00
|
|
|
'private_key_validator',
|
2019-06-24 06:23:29 +00:00
|
|
|
]
|
2016-12-20 16:43:52 +00:00
|
|
|
|
|
|
|
|
2017-12-11 09:08:43 +00:00
|
|
|
def private_key_validator(value):
|
|
|
|
if not validate_ssh_private_key(value):
|
|
|
|
raise ValidationError(
|
|
|
|
_('%(value)s is not an even number'),
|
|
|
|
params={'value': value},
|
|
|
|
)
|
2022-09-14 12:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
def update_internal_platforms(platform_model):
|
|
|
|
from assets.const import AllTypes
|
|
|
|
|
|
|
|
platforms = [
|
|
|
|
{'name': 'Linux', 'category': 'host', 'type': 'linux'},
|
|
|
|
{'name': 'BSD', 'category': 'host', 'type': 'unix'},
|
|
|
|
{'name': 'Unix', 'category': 'host', 'type': 'unix'},
|
|
|
|
{'name': 'MacOS', 'category': 'host', 'type': 'unix'},
|
|
|
|
{'name': 'Windows', 'category': 'host', 'type': 'unix'},
|
|
|
|
{
|
|
|
|
'name': 'AIX', 'category': 'host', 'type': 'unix',
|
2022-10-19 03:39:11 +00:00
|
|
|
'push_account_method': 'create_account_aix',
|
2022-10-13 09:47:29 +00:00
|
|
|
'change_secret_method': 'change_secret_aix',
|
2022-09-14 12:55:14 +00:00
|
|
|
},
|
|
|
|
{'name': 'Windows', 'category': 'host', 'type': 'windows'},
|
2022-09-16 03:45:50 +00:00
|
|
|
{
|
|
|
|
'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},
|
|
|
|
]
|
|
|
|
},
|
2022-09-14 12:55:14 +00:00
|
|
|
# 数据库
|
|
|
|
{'name': 'MySQL', 'category': 'database', 'type': 'mysql'},
|
|
|
|
{'name': 'PostgreSQL', 'category': 'database', 'type': 'postgresql'},
|
|
|
|
{'name': 'Oracle', 'category': 'database', 'type': 'oracle'},
|
|
|
|
{'name': 'SQLServer', 'category': 'database', 'type': 'sqlserver'},
|
|
|
|
{'name': 'MongoDB', 'category': 'database', 'type': 'mongodb'},
|
|
|
|
{'name': 'Redis', 'category': 'database', 'type': 'redis'},
|
|
|
|
|
|
|
|
# 网络设备
|
2022-09-22 07:24:32 +00:00
|
|
|
{'name': 'Generic', 'category': 'device', 'type': 'general'},
|
|
|
|
{'name': 'Huawei', 'category': 'device', 'type': 'general'},
|
|
|
|
{'name': 'Cisco', 'category': 'device', 'type': 'general'},
|
|
|
|
{'name': 'H3C', 'category': 'device', 'type': 'general'},
|
2022-09-14 12:55:14 +00:00
|
|
|
|
|
|
|
# Web
|
2022-09-19 01:52:09 +00:00
|
|
|
{'name': 'Website', 'category': 'web', 'type': 'general'},
|
2022-09-14 12:55:14 +00:00
|
|
|
|
|
|
|
# Cloud
|
2022-09-19 01:52:09 +00:00
|
|
|
{'name': 'Kubernetes', 'category': 'cloud', 'type': 'k8s'},
|
2022-09-22 07:24:32 +00:00
|
|
|
{'name': 'VMware vSphere', 'category': 'cloud', 'type': 'private'},
|
2022-09-14 12:55:14 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
platforms = platform_model.objects.all()
|
|
|
|
|
|
|
|
updated = []
|
|
|
|
for p in platforms:
|
|
|
|
attrs = platform_ops_map.get((p.category, p.type), {})
|
|
|
|
if not attrs:
|
|
|
|
continue
|
|
|
|
for k, v in attrs.items():
|
|
|
|
setattr(p, k, v)
|
|
|
|
updated.append(p)
|
|
|
|
platform_model.objects.bulk_update(updated, list(default_ok.keys()))
|