diff --git a/apps/assets/const/types.py b/apps/assets/const/types.py index a73b967b2..cdf421296 100644 --- a/apps/assets/const/types.py +++ b/apps/assets/const/types.py @@ -270,7 +270,7 @@ class AllTypes(ChoicesMixin): return data @classmethod - def create_or_update_by_platform_data(cls, name, platform_data, platform_cls=None): + def create_or_update_by_platform_data(cls, platform_data, platform_cls=None): # 不直接用 Platform 是因为可能在 migrations 中使用 from assets.models import Platform if platform_cls is None: @@ -279,6 +279,7 @@ class AllTypes(ChoicesMixin): automation_data = platform_data.pop('automation', {}) protocols_data = platform_data.pop('protocols', []) + name = platform_data['name'] platform, created = platform_cls.objects.update_or_create( defaults=platform_data, name=name ) @@ -294,7 +295,6 @@ class AllTypes(ChoicesMixin): platform.protocols.all().delete() for p in protocols_data: - p.pop('primary', None) platform.protocols.create(**p) @classmethod @@ -335,7 +335,7 @@ class AllTypes(ChoicesMixin): 'automation': {**default_automation, **_automation}, 'protocols': protocols_data } - cls.create_or_update_by_platform_data(name, platform_data, platform_cls=platform_cls) + cls.create_or_update_by_platform_data(platform_data, platform_cls=platform_cls) @classmethod def update_user_create_platforms(cls, platform_cls): @@ -350,5 +350,5 @@ class AllTypes(ChoicesMixin): for platform in user_platforms: print("\t- Update platform: {}".format(platform.name)) platform_data = cls.get_type_default_platform(platform.category, platform.type) - cls.create_or_update_by_platform_data(platform.name, platform_data, platform_cls=platform_cls) + cls.create_or_update_by_platform_data(platform_data, platform_cls=platform_cls) user_platforms.update(internal=False) diff --git a/apps/assets/migrations/0097_auto_20220426_1558.py b/apps/assets/migrations/0097_auto_20220426_1558.py index 59d9726e7..5a91f566f 100644 --- a/apps/assets/migrations/0097_auto_20220426_1558.py +++ b/apps/assets/migrations/0097_auto_20220426_1558.py @@ -1,12 +1,1223 @@ # Generated by Django 3.1.14 on 2022-04-26 07:58 +import json + from django.db import migrations + from assets.const import AllTypes +platforms_data_json = '''[ + { + "category": "host", + "type": "linux", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": true, + "name": "Linux", + "automation": { + "ansible_enabled": true, + "ansible_config": { + "ansible_connection": "smart" + }, + "ping_enabled": true, + "gather_facts_enabled": true, + "gather_accounts_enabled": true, + "verify_account_enabled": true, + "change_secret_enabled": true, + "push_account_enabled": true, + "ansible_config_methods": [], + "ping_method": "posix_ping", + "gather_facts_method": "gather_facts_posix", + "gather_accounts_method": "gather_accounts_posix", + "verify_account_method": "verify_account_posix", + "change_secret_method": "change_secret_posix", + "push_account_method": "push_account_posix" + }, + "protocols": [ + { + "name": "ssh", + "port": 22, + "setting": { + "sftp_enabled": true, + "sftp_home": "/tmp" + }, + "primary": true, + "required": false, + "default": false + }, + { + "name": "telnet", + "port": 23, + "required": false, + "default": false, + "setting": {} + }, + { + "name": "vnc", + "port": 5900, + "required": false, + "default": false, + "setting": {} + }, + { + "name": "rdp", + "port": 3389, + "setting": { + "console": false, + "security": "any" + }, + "required": false, + "default": false + } + ] + } + { + "category": "host", + "type": "linux", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": true, + "name": "Gateway", + "automation": { + "ansible_enabled": true, + "ansible_config": { + "ansible_connection": "smart" + }, + "ping_enabled": true, + "gather_facts_enabled": true, + "gather_accounts_enabled": true, + "verify_account_enabled": true, + "change_secret_enabled": true, + "push_account_enabled": true, + "ansible_config_methods": [], + "ping_method": "posix_ping", + "gather_facts_method": "gather_facts_posix", + "gather_accounts_method": "gather_accounts_posix", + "verify_account_method": "verify_account_posix", + "change_secret_method": "change_secret_posix", + "push_account_method": "push_account_posix" + }, + "protocols": [ + { + "name": "ssh", + "port": 22, + "setting": { + "sftp_enabled": true, + "sftp_home": "/tmp" + }, + "primary": true, + "required": false, + "default": false + }, + { + "name": "telnet", + "port": 23, + "required": false, + "default": false, + "setting": {} + }, + { + "name": "vnc", + "port": 5900, + "required": false, + "default": false, + "setting": {} + }, + { + "name": "rdp", + "port": 3389, + "setting": { + "console": false, + "security": "any" + }, + "required": false, + "default": false + } + ] + } + { + "category": "host", + "type": "unix", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": true, + "name": "Unix", + "automation": { + "ansible_enabled": true, + "ansible_config": { + "ansible_connection": "smart" + }, + "ping_enabled": true, + "gather_facts_enabled": true, + "gather_accounts_enabled": true, + "verify_account_enabled": true, + "change_secret_enabled": true, + "push_account_enabled": true, + "ansible_config_methods": [], + "ping_method": "posix_ping", + "gather_facts_method": "gather_facts_posix", + "gather_accounts_method": "gather_accounts_posix", + "verify_account_method": "verify_account_posix", + "change_secret_method": "change_secret_posix", + "push_account_method": "push_account_posix" + }, + "protocols": [ + { + "name": "ssh", + "port": 22, + "setting": { + "sftp_enabled": true, + "sftp_home": "/tmp" + }, + "primary": true, + "required": false, + "default": false + }, + { + "name": "telnet", + "port": 23, + "required": false, + "default": false, + "setting": {} + }, + { + "name": "vnc", + "port": 5900, + "required": false, + "default": false, + "setting": {} + }, + { + "name": "rdp", + "port": 3389, + "setting": { + "console": false, + "security": "any" + }, + "required": false, + "default": false + } + ] + } + { + "category": "host", + "type": "unix", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": true, + "name": "macOS", + "automation": { + "ansible_enabled": true, + "ansible_config": { + "ansible_connection": "smart" + }, + "ping_enabled": true, + "gather_facts_enabled": true, + "gather_accounts_enabled": true, + "verify_account_enabled": true, + "change_secret_enabled": true, + "push_account_enabled": true, + "ansible_config_methods": [], + "ping_method": "posix_ping", + "gather_facts_method": "gather_facts_posix", + "gather_accounts_method": "gather_accounts_posix", + "verify_account_method": "verify_account_posix", + "change_secret_method": "change_secret_posix", + "push_account_method": "push_account_posix" + }, + "protocols": [ + { + "name": "ssh", + "port": 22, + "setting": { + "sftp_enabled": true, + "sftp_home": "/tmp" + }, + "primary": true, + "required": false, + "default": false + }, + { + "name": "telnet", + "port": 23, + "required": false, + "default": false, + "setting": {} + }, + { + "name": "vnc", + "port": 5900, + "required": false, + "default": false, + "setting": {} + }, + { + "name": "rdp", + "port": 3389, + "setting": { + "console": false, + "security": "any" + }, + "required": false, + "default": false + } + ] + } + { + "category": "host", + "type": "unix", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": true, + "name": "BSD", + "automation": { + "ansible_enabled": true, + "ansible_config": { + "ansible_connection": "smart" + }, + "ping_enabled": true, + "gather_facts_enabled": true, + "gather_accounts_enabled": true, + "verify_account_enabled": true, + "change_secret_enabled": true, + "push_account_enabled": true, + "ansible_config_methods": [], + "ping_method": "posix_ping", + "gather_facts_method": "gather_facts_posix", + "gather_accounts_method": "gather_accounts_posix", + "verify_account_method": "verify_account_posix", + "change_secret_method": "change_secret_posix", + "push_account_method": "push_account_posix" + }, + "protocols": [ + { + "name": "ssh", + "port": 22, + "setting": { + "sftp_enabled": true, + "sftp_home": "/tmp" + }, + "primary": true, + "required": false, + "default": false + }, + { + "name": "telnet", + "port": 23, + "required": false, + "default": false, + "setting": {} + }, + { + "name": "vnc", + "port": 5900, + "required": false, + "default": false, + "setting": {} + }, + { + "name": "rdp", + "port": 3389, + "setting": { + "console": false, + "security": "any" + }, + "required": false, + "default": false + } + ] + } + { + "category": "host", + "type": "unix", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": true, + "name": "AIX", + "automation": { + "ansible_enabled": true, + "ansible_config": { + "ansible_connection": "smart" + }, + "ping_enabled": true, + "gather_facts_enabled": true, + "gather_accounts_enabled": true, + "verify_account_enabled": true, + "change_secret_enabled": true, + "push_account_enabled": true, + "ansible_config_methods": [], + "ping_method": "posix_ping", + "gather_facts_method": "gather_facts_posix", + "gather_accounts_method": "gather_accounts_posix", + "verify_account_method": "verify_account_posix", + "change_secret_method": "change_secret_aix", + "push_account_method": "push_account_aix" + }, + "protocols": [ + { + "name": "ssh", + "port": 22, + "setting": { + "sftp_enabled": true, + "sftp_home": "/tmp" + }, + "primary": true, + "required": false, + "default": false + }, + { + "name": "telnet", + "port": 23, + "required": false, + "default": false, + "setting": {} + }, + { + "name": "vnc", + "port": 5900, + "required": false, + "default": false, + "setting": {} + }, + { + "name": "rdp", + "port": 3389, + "setting": { + "console": false, + "security": "any" + }, + "required": false, + "default": false + } + ] + } + { + "category": "host", + "type": "windows", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": false, + "name": "Windows", + "automation": { + "ansible_enabled": true, + "ansible_config": { + "ansible_shell_type": "cmd", + "ansible_connection": "ssh" + }, + "ping_enabled": true, + "gather_facts_enabled": true, + "gather_accounts_enabled": true, + "verify_account_enabled": true, + "change_secret_enabled": true, + "push_account_enabled": true, + "ansible_config_methods": [], + "ping_method": "win_ping", + "gather_facts_method": "gather_facts_windows", + "gather_accounts_method": "gather_accounts_windows", + "verify_account_method": "verify_account_windows", + "change_secret_method": "change_secret_local_windows", + "push_account_method": "push_account_local_windows" + }, + "protocols": [ + { + "name": "rdp", + "port": 3389, + "setting": { + "console": false, + "security": "any" + }, + "primary": true, + "required": false, + "default": false + }, + { + "name": "ssh", + "port": 22, + "setting": { + "sftp_enabled": true, + "sftp_home": "/tmp" + }, + "required": false, + "default": false + }, + { + "name": "vnc", + "port": 5900, + "required": false, + "default": false, + "setting": {} + } + ] + } + { + "category": "host", + "type": "windows", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": false, + "name": "Windows-TLS", + "automation": { + "ansible_enabled": true, + "ansible_config": { + "ansible_shell_type": "cmd", + "ansible_connection": "ssh" + }, + "ping_enabled": true, + "gather_facts_enabled": true, + "gather_accounts_enabled": true, + "verify_account_enabled": true, + "change_secret_enabled": true, + "push_account_enabled": true, + "ansible_config_methods": [], + "ping_method": "win_ping", + "gather_facts_method": "gather_facts_windows", + "gather_accounts_method": "gather_accounts_windows", + "verify_account_method": "verify_account_windows", + "change_secret_method": "change_secret_local_windows", + "push_account_method": "push_account_local_windows" + }, + "protocols": [ + { + "name": "rdp", + "port": 3389, + "setting": { + "console": false, + "security": "tls" + }, + "primary": true, + "required": false, + "default": false + }, + { + "name": "ssh", + "port": 22, + "setting": { + "sftp_enabled": true, + "sftp_home": "/tmp" + }, + "required": false, + "default": false + }, + { + "name": "vnc", + "port": 5900, + "required": false, + "default": false, + "setting": {} + } + ] + } + { + "category": "host", + "type": "windows", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": false, + "name": "Windows-RDP", + "automation": { + "ansible_enabled": true, + "ansible_config": { + "ansible_shell_type": "cmd", + "ansible_connection": "ssh" + }, + "ping_enabled": true, + "gather_facts_enabled": true, + "gather_accounts_enabled": true, + "verify_account_enabled": true, + "change_secret_enabled": true, + "push_account_enabled": true, + "ansible_config_methods": [], + "ping_method": "win_ping", + "gather_facts_method": "gather_facts_windows", + "gather_accounts_method": "gather_accounts_windows", + "verify_account_method": "verify_account_windows", + "change_secret_method": "change_secret_local_windows", + "push_account_method": "push_account_local_windows" + }, + "protocols": [ + { + "name": "rdp", + "port": 3389, + "setting": { + "console": false, + "security": "rdp" + }, + "primary": true, + "required": false, + "default": false + }, + { + "name": "ssh", + "port": 22, + "setting": { + "sftp_enabled": true, + "sftp_home": "/tmp" + }, + "required": false, + "default": false + }, + { + "name": "vnc", + "port": 5900, + "required": false, + "default": false, + "setting": {} + } + ] + } + { + "category": "host", + "type": "windows", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": false, + "name": "RemoteAppHost", + "automation": { + "ansible_enabled": true, + "ansible_config": { + "ansible_shell_type": "cmd", + "ansible_connection": "ssh" + }, + "ping_enabled": true, + "gather_facts_enabled": true, + "gather_accounts_enabled": true, + "verify_account_enabled": true, + "change_secret_enabled": true, + "push_account_enabled": true, + "ansible_config_methods": [], + "ping_method": "win_ping", + "gather_facts_method": "gather_facts_windows", + "gather_accounts_method": "gather_accounts_windows", + "verify_account_method": "verify_account_windows", + "change_secret_method": "change_secret_local_windows", + "push_account_method": "push_account_local_windows" + }, + "protocols": [ + { + "name": "rdp", + "port": 3389, + "setting": { + "console": false, + "security": "any" + }, + "primary": true, + "required": false, + "default": false + }, + { + "name": "ssh", + "port": 22, + "setting": { + "sftp_enabled": true, + "sftp_home": "/tmp" + }, + "required": true, + "default": false + } + ] + } + { + "category": "device", + "type": "general", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": false, + "name": "General", + "automation": { + "ansible_enabled": false, + "ansible_config": { + "ansible_connection": "local" + }, + "ping_enabled": false, + "gather_facts_enabled": false, + "gather_accounts_enabled": false, + "verify_account_enabled": false, + "change_secret_enabled": false, + "push_account_enabled": false, + "ansible_config_methods": [] + }, + "protocols": [ + { + "name": "ssh", + "port": 22, + "setting": { + "sftp_enabled": true, + "sftp_home": "/tmp" + }, + "primary": true, + "required": false, + "default": false + }, + { + "name": "telnet", + "port": 23, + "required": false, + "default": false, + "setting": {} + } + ] + } + { + "category": "device", + "type": "general", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": false, + "name": "Cisco", + "automation": { + "ansible_enabled": false, + "ansible_config": { + "ansible_connection": "local" + }, + "ping_enabled": false, + "gather_facts_enabled": false, + "gather_accounts_enabled": false, + "verify_account_enabled": false, + "change_secret_enabled": false, + "push_account_enabled": false, + "ansible_config_methods": [] + }, + "protocols": [ + { + "name": "ssh", + "port": 22, + "setting": { + "sftp_enabled": true, + "sftp_home": "/tmp" + }, + "primary": true, + "required": false, + "default": false + }, + { + "name": "telnet", + "port": 23, + "required": false, + "default": false, + "setting": {} + } + ] + } + { + "category": "device", + "type": "general", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": false, + "name": "Huawei", + "automation": { + "ansible_enabled": false, + "ansible_config": { + "ansible_connection": "local" + }, + "ping_enabled": false, + "gather_facts_enabled": false, + "gather_accounts_enabled": false, + "verify_account_enabled": false, + "change_secret_enabled": false, + "push_account_enabled": false, + "ansible_config_methods": [] + }, + "protocols": [ + { + "name": "ssh", + "port": 22, + "setting": { + "sftp_enabled": true, + "sftp_home": "/tmp" + }, + "primary": true, + "required": false, + "default": false + }, + { + "name": "telnet", + "port": 23, + "required": false, + "default": false, + "setting": {} + } + ] + } + { + "category": "device", + "type": "general", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": false, + "name": "H3C", + "automation": { + "ansible_enabled": false, + "ansible_config": { + "ansible_connection": "local" + }, + "ping_enabled": false, + "gather_facts_enabled": false, + "gather_accounts_enabled": false, + "verify_account_enabled": false, + "change_secret_enabled": false, + "push_account_enabled": false, + "ansible_config_methods": [] + }, + "protocols": [ + { + "name": "ssh", + "port": 22, + "setting": { + "sftp_enabled": true, + "sftp_home": "/tmp" + }, + "primary": true, + "required": false, + "default": false + }, + { + "name": "telnet", + "port": 23, + "required": false, + "default": false, + "setting": {} + } + ] + } + { + "category": "database", + "type": "mysql", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": false, + "name": "MySQL", + "automation": { + "ansible_enabled": true, + "ansible_config": { + "ansible_connection": "local" + }, + "ping_enabled": true, + "gather_facts_enabled": false, + "gather_accounts_enabled": true, + "verify_account_enabled": true, + "change_secret_enabled": true, + "push_account_enabled": true, + "ansible_config_methods": [], + "ping_method": "mysql_ping", + "gather_accounts_method": "gather_accounts_mysql", + "verify_account_method": "verify_account_mysql", + "change_secret_method": "change_secret_mysql", + "push_account_method": "push_account_mysql" + }, + "protocols": [ + { + "name": "mysql", + "port": 3306, + "setting": {}, + "required": false, + "primary": true, + "default": false + } + ] + } + { + "category": "database", + "type": "mariadb", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": false, + "name": "MariaDB", + "automation": { + "ansible_enabled": true, + "ansible_config": { + "ansible_connection": "local" + }, + "ping_enabled": true, + "gather_facts_enabled": false, + "gather_accounts_enabled": true, + "verify_account_enabled": true, + "change_secret_enabled": true, + "push_account_enabled": true, + "ansible_config_methods": [], + "ping_method": "mysql_ping", + "gather_accounts_method": "gather_accounts_mysql", + "verify_account_method": "verify_account_mysql", + "change_secret_method": "change_secret_mysql", + "push_account_method": "push_account_mysql" + }, + "protocols": [ + { + "name": "mariadb", + "port": 3306, + "required": false, + "primary": true, + "default": false, + "setting": {} + } + ] + } + { + "category": "database", + "type": "postgresql", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": false, + "name": "PostgreSQL", + "automation": { + "ansible_enabled": true, + "ansible_config": { + "ansible_connection": "local" + }, + "ping_enabled": true, + "gather_facts_enabled": false, + "gather_accounts_enabled": true, + "verify_account_enabled": true, + "change_secret_enabled": true, + "push_account_enabled": true, + "ansible_config_methods": [], + "ping_method": "ping_postgresql", + "gather_accounts_method": "gather_accounts_postgresql", + "verify_account_method": "verify_account_postgresql", + "change_secret_method": "change_secret_postgresql", + "push_account_method": "push_account_postgresql" + }, + "protocols": [ + { + "name": "postgresql", + "port": 5432, + "required": false, + "primary": true, + "default": false, + "setting": {} + } + ] + } + { + "category": "database", + "type": "oracle", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": false, + "name": "Oracle", + "automation": { + "ansible_enabled": true, + "ansible_config": { + "ansible_connection": "local" + }, + "ping_enabled": true, + "gather_facts_enabled": false, + "gather_accounts_enabled": true, + "verify_account_enabled": true, + "change_secret_enabled": true, + "push_account_enabled": true, + "ansible_config_methods": [], + "ping_method": "oracle_ping", + "gather_accounts_method": "gather_accounts_oracle", + "verify_account_method": "verify_account_oracle", + "change_secret_method": "change_secret_oracle", + "push_account_method": "push_account_oracle" + }, + "protocols": [ + { + "name": "oracle", + "port": 1521, + "required": false, + "primary": true, + "default": false, + "setting": {} + } + ] + } + { + "category": "database", + "type": "sqlserver", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": false, + "name": "SQLServer", + "automation": { + "ansible_enabled": true, + "ansible_config": { + "ansible_connection": "local" + }, + "ping_enabled": true, + "gather_facts_enabled": false, + "gather_accounts_enabled": true, + "verify_account_enabled": true, + "change_secret_enabled": true, + "push_account_enabled": true, + "ansible_config_methods": [], + "ping_method": "sqlserver_ping", + "verify_account_method": "verify_account_sqlserver", + "change_secret_method": "change_secret_sqlserver", + "push_account_method": "push_account_sqlserver" + }, + "protocols": [ + { + "name": "sqlserver", + "port": 1433, + "required": false, + "primary": true, + "default": false, + "setting": {} + } + ] + } + { + "category": "database", + "type": "clickhouse", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": false, + "name": "ClickHouse", + "automation": { + "ansible_enabled": false, + "ansible_config": { + "ansible_connection": "local" + }, + "ping_enabled": false, + "gather_facts_enabled": false, + "gather_accounts_enabled": false, + "verify_account_enabled": false, + "change_secret_enabled": false, + "push_account_enabled": false, + "ansible_config_methods": [] + }, + "protocols": [ + { + "name": "clickhouse", + "port": 9000, + "required": false, + "primary": true, + "default": false, + "setting": {} + } + ] + } + { + "category": "database", + "type": "mongodb", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": false, + "name": "MongoDB", + "automation": { + "ansible_enabled": true, + "ansible_config": { + "ansible_connection": "local" + }, + "ping_enabled": true, + "gather_facts_enabled": false, + "gather_accounts_enabled": true, + "verify_account_enabled": true, + "change_secret_enabled": true, + "push_account_enabled": true, + "ansible_config_methods": [], + "ping_method": "mongodb_ping", + "gather_accounts_method": "gather_accounts_mongodb", + "verify_account_method": "verify_account_mongodb", + "change_secret_method": "change_secret_mongodb", + "push_account_method": "push_account_mongodb" + }, + "protocols": [ + { + "name": "mongodb", + "port": 27017, + "required": false, + "primary": true, + "default": false, + "setting": {} + } + ] + } + { + "category": "database", + "type": "redis", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": false, + "name": "Redis", + "automation": { + "ansible_enabled": false, + "ansible_config": { + "ansible_connection": "local" + }, + "ping_enabled": false, + "gather_facts_enabled": false, + "gather_accounts_enabled": false, + "verify_account_enabled": false, + "change_secret_enabled": false, + "push_account_enabled": false, + "ansible_config_methods": [] + }, + "protocols": [ + { + "name": "redis", + "port": 6379, + "required": false, + "setting": { + "auth_username": false + }, + "primary": true, + "default": false + } + ] + } + { + "category": "database", + "type": "redis", + "internal": true, + "charset": "utf-8", + "domain_enabled": true, + "su_enabled": false, + "name": "Redis6+", + "automation": { + "ansible_enabled": false, + "ansible_config": { + "ansible_connection": "local" + }, + "ping_enabled": false, + "gather_facts_enabled": false, + "gather_accounts_enabled": false, + "verify_account_enabled": false, + "change_secret_enabled": false, + "push_account_enabled": false, + "ansible_config_methods": [] + }, + "protocols": [ + { + "name": "redis", + "port": 6379, + "required": false, + "setting": { + "auth_username": true + }, + "primary": true, + "default": false + } + ] + } + { + "category": "web", + "type": "website", + "internal": true, + "charset": "utf-8", + "domain_enabled": false, + "su_enabled": false, + "name": "Website", + "automation": { + "ansible_enabled": false, + "ping_enabled": false, + "gather_facts_enabled": false, + "verify_account_enabled": false, + "change_secret_enabled": false, + "push_account_enabled": false, + "gather_accounts_enabled": false + }, + "protocols": [ + { + "name": "http", + "port": 80, + "setting": { + "username_selector": "name=username", + "password_selector": "name=password", + "submit_selector": "id=longin_button" + }, + "primary": true, + "required": false, + "default": false + } + ] + } + { + "category": "cloud", + "type": "private", + "internal": true, + "charset": "utf-8", + "domain_enabled": false, + "su_enabled": false, + "name": "Vmware-vSphere", + "automation": { + "ansible_enabled": false, + "ansible_config": {}, + "gather_facts_enabled": false, + "verify_account_enabled": false, + "change_secret_enabled": false, + "push_account_enabled": false, + "gather_accounts_enabled": false + }, + "protocols": [ + { + "name": "http", + "port": 80, + "setting": { + "username_selector": "name=username", + "password_selector": "name=password", + "submit_selector": "id=longin_button" + }, + "primary": true, + "required": false, + "default": false + } + ] + } + { + "category": "cloud", + "type": "k8s", + "internal": true, + "charset": "utf-8", + "domain_enabled": false, + "su_enabled": false, + "name": "Kubernetes", + "automation": { + "ansible_enabled": false, + "ansible_config": {}, + "gather_facts_enabled": false, + "verify_account_enabled": false, + "change_secret_enabled": false, + "push_account_enabled": false, + "gather_accounts_enabled": false + }, + "protocols": [ + { + "name": "k8s", + "port": 443, + "required": false, + "primary": true, + "default": false, + "setting": {} + } + ] + } +]''' + def create_internal_platforms(apps, *args): platform_cls = apps.get_model('assets', 'Platform') - AllTypes.create_or_update_internal_platforms(platform_cls) + platforms_data = json.loads(platforms_data_json) + + for platform_data in platforms_data: + protocols = platform_data.pop('protocols', []) + platform_data['protocols'] = [p for p in protocols if p.pop('primary', True) is not None] + AllTypes.create_or_update_by_platform_data(platform_data, platform_cls=platform_cls) def update_user_platforms(apps, *args): diff --git a/apps/assets/migrations/0111_auto_20230321_1633.py b/apps/assets/migrations/0111_auto_20230321_1633.py index 52dbc1971..1acac984a 100644 --- a/apps/assets/migrations/0111_auto_20230321_1633.py +++ b/apps/assets/migrations/0111_auto_20230321_1633.py @@ -15,6 +15,9 @@ def migrate_platform_protocol_primary(apps, schema_editor): platforms = platform_model.objects.all() for platform in platforms: + p = platform.protocols.filter(primary=True).first() + if p: + continue p = platform.protocols.first() if not p: continue @@ -45,5 +48,4 @@ class Migration(migrations.Migration): ), migrations.RunPython(migrate_platform_charset), migrations.RunPython(migrate_platform_protocol_primary), - migrations.RunPython(migrate_internal_platforms), ]