pref: 添加各种 field

pull/8873/head
ibuler 2 years ago
parent d7d9fe2718
commit 81219e1e7c

@ -14,12 +14,13 @@ class PlatformMixin:
@classmethod @classmethod
def platform_constraints(cls): def platform_constraints(cls):
return { return {
'has_domain': False, 'domain_enabled': False,
'has_su': False, 'gather_facts_enabled': False,
'has_ping': False, 'su_enabled': False,
'has_change_password': False, 'change_password_enabled': False,
'has_verify_account': False, 'verify_account_enabled': False,
'has_create_account': False, 'create_account_enabled': False,
'gather_accounts_enabled': False,
'_protocols': [] '_protocols': []
} }
@ -35,26 +36,29 @@ class Category(PlatformMixin, ChoicesMixin, models.TextChoices):
def platform_constraints(cls) -> dict: def platform_constraints(cls) -> dict:
return { return {
cls.HOST: { cls.HOST: {
'has_domain': True, 'domain_enabled': True,
'has_ping': True, 'su_enabled': True,
'has_verify_account': True, 'ping_enabled': True,
'has_change_password': True, 'gather_facts_enabled': True,
'has_create_account': True, 'verify_account_enabled': True,
'change_password_enabled': True,
'create_account_enabled': True,
'gather_accounts_enabled': True,
'_protocols': ['ssh', 'telnet'] '_protocols': ['ssh', 'telnet']
}, },
cls.NETWORKING: { cls.NETWORKING: {
'has_domain': True, 'domain_enabled': True,
'_protocols': ['ssh', 'telnet'] '_protocols': ['ssh', 'telnet']
}, },
cls.DATABASE: { cls.DATABASE: {
'has_domain': True, 'domain_enabled': True,
}, },
cls.WEB: { cls.WEB: {
'has_domain': False, 'domain_enabled': False,
'_protocols': [] '_protocols': []
}, },
cls.CLOUD: { cls.CLOUD: {
'has_domain': False, 'domain_enabled': False,
'_protocols': [] '_protocols': []
} }
} }
@ -77,7 +81,7 @@ class HostTypes(PlatformMixin, ChoicesMixin, models.TextChoices):
}, },
cls.WINDOWS: { cls.WINDOWS: {
'_protocols': ['ssh', 'rdp', 'vnc'], '_protocols': ['ssh', 'rdp', 'vnc'],
'has_su': False 'su_enabled': False
}, },
cls.MACOS: { cls.MACOS: {
'_protocols': ['ssh', 'vnc'] '_protocols': ['ssh', 'vnc']

@ -0,0 +1,43 @@
# Generated by Django 3.2.14 on 2022-09-01 07:42
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assets', '0109_auto_20220901_1431'),
]
operations = [
migrations.AddField(
model_name='platform',
name='create_account_enabled',
field=models.BooleanField(default=False, verbose_name='Create account enabled'),
),
migrations.AddField(
model_name='platform',
name='create_account_method',
field=models.TextField(blank=True, max_length=32, null=True, verbose_name='Create account method'),
),
migrations.AddField(
model_name='platform',
name='gather_accounts_enabled',
field=models.BooleanField(default=False, verbose_name='Gather facts enabled'),
),
migrations.AddField(
model_name='platform',
name='gather_accounts_method',
field=models.TextField(blank=True, max_length=32, null=True, verbose_name='Gather facts method'),
),
migrations.AddField(
model_name='platform',
name='gather_facts_enabled',
field=models.BooleanField(default=False, verbose_name='Gather facts enabled'),
),
migrations.AddField(
model_name='platform',
name='gather_facts_method',
field=models.TextField(blank=True, max_length=32, null=True, verbose_name='Gather facts method'),
),
]

@ -26,20 +26,26 @@ class Platform(models.Model):
name = models.SlugField(verbose_name=_("Name"), unique=True, allow_unicode=True) name = models.SlugField(verbose_name=_("Name"), unique=True, allow_unicode=True)
category = models.CharField(default='host', max_length=32, verbose_name=_("Category")) category = models.CharField(default='host', max_length=32, verbose_name=_("Category"))
type = models.CharField(max_length=32, default='linux', verbose_name=_("Type")) type = models.CharField(max_length=32, default='linux', verbose_name=_("Type"))
charset = models.CharField(default='utf8', choices=CHARSET_CHOICES, max_length=8, verbose_name=_("Charset"))
meta = JsonDictTextField(blank=True, null=True, verbose_name=_("Meta")) meta = JsonDictTextField(blank=True, null=True, verbose_name=_("Meta"))
internal = models.BooleanField(default=False, verbose_name=_("Internal")) internal = models.BooleanField(default=False, verbose_name=_("Internal"))
comment = models.TextField(blank=True, null=True, verbose_name=_("Comment")) comment = models.TextField(blank=True, null=True, verbose_name=_("Comment"))
# 资产有关的
charset = models.CharField(default='utf8', choices=CHARSET_CHOICES, max_length=8, verbose_name=_("Charset"))
protocols_enabled = models.BooleanField(default=True, verbose_name=_("Protocols enabled")) protocols_enabled = models.BooleanField(default=True, verbose_name=_("Protocols enabled"))
protocols = models.ManyToManyField(PlatformProtocol, blank=True, verbose_name=_("Protocols")) protocols = models.ManyToManyField(PlatformProtocol, blank=True, verbose_name=_("Protocols"))
# Accounts gather_facts_enabled = models.BooleanField(default=False, verbose_name=_("Gather facts enabled"))
# 这应该和账号有关 gather_facts_method = models.TextField(max_length=32, blank=True, null=True, verbose_name=_("Gather facts method"))
# 账号有关的
su_enabled = models.BooleanField(default=False, verbose_name=_("Su enabled")) su_enabled = models.BooleanField(default=False, verbose_name=_("Su enabled"))
su_method = models.CharField(max_length=32, blank=True, null=True, verbose_name=_("SU method")) su_method = models.CharField(max_length=32, blank=True, null=True, verbose_name=_("SU method"))
verify_account_enabled = models.BooleanField(default=False, verbose_name=_("Verify account enabled")) create_account_enabled = models.BooleanField(default=False, verbose_name=_("Create account enabled"))
verify_account_method = models.TextField(max_length=32, blank=True, null=True, verbose_name=_("Verify account method")) create_account_method = models.TextField(max_length=32, blank=True, null=True, verbose_name=_("Create account method"))
change_password_enabled = models.BooleanField(default=False, verbose_name=_("Change password enabled")) change_password_enabled = models.BooleanField(default=False, verbose_name=_("Change password enabled"))
change_password_method = models.TextField(max_length=32, blank=True, null=True, verbose_name=_("Change password method")) change_password_method = models.TextField(max_length=32, blank=True, null=True, verbose_name=_("Change password method"))
verify_account_enabled = models.BooleanField(default=False, verbose_name=_("Verify account enabled"))
verify_account_method = models.TextField(max_length=32, blank=True, null=True, verbose_name=_("Verify account method"))
gather_accounts_enabled = models.BooleanField(default=False, verbose_name=_("Gather facts enabled"))
gather_accounts_method = models.TextField(max_length=32, blank=True, null=True, verbose_name=_("Gather facts method"))
@property @property
def type_constraints(self): def type_constraints(self):

@ -46,8 +46,11 @@ class PlatformSerializer(JMSWritableNestedModelSerializer):
'category', 'type', 'category', 'type',
] ]
fields = fields_small + [ fields = fields_small + [
'domain_enabled', 'domain_default', 'su_enabled', 'su_method', 'protocols_enabled', 'protocols',
'protocols_enabled', 'protocols', 'ping_enabled', 'ping_method', 'gather_facts_enabled', 'gather_facts_method',
'su_enabled', 'su_method',
'gather_accounts_enabled', 'gather_accounts_method',
'create_account_enabled', 'create_account_method',
'verify_account_enabled', 'verify_account_method', 'verify_account_enabled', 'verify_account_method',
'change_password_enabled', 'change_password_method', 'change_password_enabled', 'change_password_method',
'type_constraints', 'comment', 'charset', 'type_constraints', 'comment', 'charset',
@ -56,12 +59,16 @@ class PlatformSerializer(JMSWritableNestedModelSerializer):
'su_enabled': {'label': '启用切换账号'}, 'su_enabled': {'label': '启用切换账号'},
'domain_enabled': {'label': "启用网域"}, 'domain_enabled': {'label': "启用网域"},
'domain_default': {'label': "默认网域"}, 'domain_default': {'label': "默认网域"},
'gather_facts_enabled': {'label': '启用收集信息'},
'gather_facts_method': {'label': '收集信息方式'},
'verify_account_enabled': {'label': '启用校验账号'}, 'verify_account_enabled': {'label': '启用校验账号'},
'verify_account_method': {'label': '校验账号方式'}, 'verify_account_method': {'label': '校验账号方式'},
'create_account_enabled': {'label': '启用创建账号'}, 'create_account_enabled': {'label': '启用创建账号'},
'create_account_method': {'label': '创建账号方式'}, 'create_account_method': {'label': '创建账号方式'},
'change_password_enabled': {'label': '启用账号创建改密'}, 'change_password_enabled': {'label': '启用账号创建改密'},
'change_password_method': {'label': '账号创建改密方式'}, 'change_password_method': {'label': '账号创建改密方式'},
'gather_accounts_enabled': {'label': '启用账号收集'},
'gather_accounts_method': {'label': '收集账号方式'},
} }
def validate(self, attrs): def validate(self, attrs):

Loading…
Cancel
Save