perf: 优化平台

pull/8873/head
ibuler 2022-09-15 21:20:56 +08:00
parent e0e14a2fe1
commit 9b2acfe4a4
16 changed files with 35 additions and 32 deletions

View File

@ -1,13 +1,13 @@
from assets.serializers import HostSerializer
from assets.models import Networking
from assets.models import Device
from .asset import AssetViewSet
__all__ = ['NetworkViewSet']
__all__ = ['DeviceViewSet']
class NetworkViewSet(AssetViewSet):
model = Networking
class DeviceViewSet(AssetViewSet):
model = Device
def get_serializer_classes(self):
serializer_classes = super().get_serializer_classes()

View File

@ -6,7 +6,7 @@ from common.tree import TreeNode
__all__ = [
'Category', 'HostTypes', 'NetworkingTypes', 'DatabaseTypes',
'Category', 'HostTypes', 'DeviceTypes', 'DatabaseTypes',
'WebTypes', 'CloudTypes', 'Protocol', 'AllTypes',
]
@ -17,7 +17,7 @@ class PlatformMixin:
return {
'domain_enabled': False,
'su_enabled': False,
'vendor_enabled': False,
'brand_enabled': False,
'ping_enabled': False,
'gather_facts_enabled': False,
'change_password_enabled': False,
@ -30,9 +30,9 @@ class PlatformMixin:
class Category(PlatformMixin, ChoicesMixin, models.TextChoices):
HOST = 'host', _('Host')
NETWORKING = 'networking', _("NetworkDevice")
DEVICE = 'device', _("Device")
DATABASE = 'database', _("Database")
CLOUD = 'cloud', _("Clouding")
CLOUD = 'cloud', _("Cloud service")
WEB = 'web', _("Web")
@classmethod
@ -49,7 +49,7 @@ class Category(PlatformMixin, ChoicesMixin, models.TextChoices):
'gather_accounts_enabled': True, 'gather_accounts_method': 'gather_accounts_posix',
'_protocols': ['ssh', 'telnet'],
},
cls.NETWORKING: {
cls.DEVICE: {
'domain_enabled': True,
'brand_enabled': True,
'brands': [
@ -108,7 +108,7 @@ class HostTypes(PlatformMixin, ChoicesMixin, models.TextChoices):
LINUX = 'linux', 'Linux'
WINDOWS = 'windows', 'Windows'
UNIX = 'unix', 'Unix'
OTHER_HOST = 'other_host', _("Other host")
OTHER_HOST = 'other', _("Other")
@classmethod
def platform_constraints(cls):
@ -131,7 +131,7 @@ class HostTypes(PlatformMixin, ChoicesMixin, models.TextChoices):
}
class NetworkingTypes(PlatformMixin, ChoicesMixin, models.TextChoices):
class DeviceTypes(PlatformMixin, ChoicesMixin, models.TextChoices):
GENERAL = 'general', _("General device")
SWITCH = 'switch', _("Switch")
ROUTER = 'router', _("Router")
@ -163,7 +163,7 @@ class DatabaseTypes(PlatformMixin, ChoicesMixin, models.TextChoices):
class WebTypes(PlatformMixin, ChoicesMixin, models.TextChoices):
WEBSITE = 'website', _('General Website')
WEBSITE = 'website', _('General website')
class CloudTypes(PlatformMixin, ChoicesMixin, models.TextChoices):
@ -181,7 +181,7 @@ class CloudTypes(PlatformMixin, ChoicesMixin, models.TextChoices):
class AllTypes(ChoicesMixin, metaclass=IncludesTextChoicesMeta):
choices: list
includes = [
HostTypes, NetworkingTypes, DatabaseTypes,
HostTypes, DeviceTypes, DatabaseTypes,
WebTypes, CloudTypes
]
@ -210,7 +210,7 @@ class AllTypes(ChoicesMixin, metaclass=IncludesTextChoicesMeta):
def category_types(cls):
return (
(Category.HOST, HostTypes),
(Category.NETWORKING, NetworkingTypes),
(Category.DEVICE, DeviceTypes),
(Category.DATABASE, DatabaseTypes),
(Category.WEB, WebTypes),
(Category.CLOUD, CloudTypes)

View File

@ -23,7 +23,7 @@ class Migration(migrations.Migration):
bases=('assets.asset',),
),
migrations.CreateModel(
name='Networking',
name='Device',
fields=[
('asset_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='assets.asset')),
],

View File

@ -31,7 +31,7 @@ class Migration(migrations.Migration):
('date_created', models.DateTimeField(blank=True, editable=False, verbose_name='Date created')),
('date_updated', models.DateTimeField(blank=True, editable=False, verbose_name='Date updated')),
('created_by', models.CharField(max_length=128, null=True, verbose_name='Created by')),
('privileged', models.BooleanField(default=False, verbose_name='Privileged account')),
('privileged', models.BooleanField(default=False, verbose_name='Privileged')),
('version', models.IntegerField(default=0, verbose_name='Version')),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField(db_index=True)),
@ -64,7 +64,7 @@ class Migration(migrations.Migration):
('date_created', models.DateTimeField(auto_now_add=True, verbose_name='Date created')),
('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
('created_by', models.CharField(max_length=128, null=True, verbose_name='Created by')),
('privileged', models.BooleanField(default=False, verbose_name='Privileged account')),
('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')),

View File

@ -28,7 +28,7 @@ class Migration(migrations.Migration):
('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
('created_by', models.CharField(max_length=128, null=True, verbose_name='Created by')),
('token', common.db.fields.EncryptTextField(blank=True, null=True, verbose_name='Token')),
('privileged', models.BooleanField(default=False, verbose_name='Privileged account')),
('privileged', models.BooleanField(default=False, verbose_name='Privileged')),
],
options={
'verbose_name': 'Account template',

View File

@ -1,6 +1,6 @@
from .common import *
from .host import *
from .database import *
from .networking import *
from .device import *
from .web import *
from .cloud import *

View File

@ -2,6 +2,5 @@
from .common import Asset
class Networking(Asset):
class Device(Asset):
pass

View File

@ -62,7 +62,7 @@ class BaseAccount(OrgModelMixin):
private_key = fields.EncryptTextField(blank=True, null=True, verbose_name=_('SSH private key'))
public_key = fields.EncryptTextField(blank=True, null=True, verbose_name=_('SSH public key'))
token = fields.EncryptTextField(blank=True, null=True, verbose_name=_('Token'))
privileged = models.BooleanField(verbose_name=_("Privileged account"), default=False)
privileged = models.BooleanField(verbose_name=_("Privileged"), default=False)
comment = models.TextField(blank=True, verbose_name=_('Comment'))
date_created = models.DateTimeField(auto_now_add=True, verbose_name=_("Date created"))
date_updated = models.DateTimeField(auto_now=True, verbose_name=_("Date updated"))

View File

@ -1,3 +1,3 @@
from .account import *
from .account_history import *
from .account_template import *
from .history import *
from .template import *

View File

@ -10,12 +10,13 @@ from .common import AccountFieldsSerializerMixin
class AccountTemplateSerializer(AuthValidateMixin, BulkOrgResourceModelSerializer):
class Meta:
model = AccountTemplate
fields_mini = ['id', 'privileged', 'username']
fields_mini = ['id', 'name', 'username', 'privileged']
fields_write_only = AccountFieldsSerializerMixin.Meta.fields_write_only
fields_other = AccountFieldsSerializerMixin.Meta.fields_other
fields = fields_mini + fields_write_only + fields_other
extra_kwargs = {
'username': {'required': True},
'name': {'required': True},
'private_key': {'write_only': True},
'public_key': {'write_only': True},
}

View File

@ -1,6 +1,6 @@
from .common import *
from .host import *
from .database import *
from .networking import *
from .device import *
from .cloud import *
from .web import *

View File

@ -1,4 +1,4 @@
from assets.models import Networking
from assets.models import Device
from .common import AssetSerializer
__all__ = ['NetworkingSerializer']
@ -6,4 +6,4 @@ __all__ = ['NetworkingSerializer']
class NetworkingSerializer(AssetSerializer):
class Meta(AssetSerializer.Meta):
model = Networking
model = Device

View File

@ -1,5 +1,5 @@
from assets.models import Networking
from assets.models import Device
from .common import AssetSerializer
__all__ = ['NetworkingSerializer']
@ -7,4 +7,4 @@ __all__ = ['NetworkingSerializer']
class NetworkingSerializer(AssetSerializer):
class Meta(AssetSerializer.Meta):
model = Networking
model = Device

View File

@ -38,6 +38,8 @@ class PlatformAutomationSerializer(serializers.ModelSerializer):
'gather_accounts_enabled', 'gather_accounts_method',
]
extra_kwargs = {
'ping_enabled': {'label': '启用资产探测'},
'ping_method': {'label': '探测方式'},
'gather_facts_enabled': {'label': '启用收集信息'},
'gather_facts_method': {'label': '收集信息方式'},
'verify_account_enabled': {'label': '启用校验账号'},
@ -82,6 +84,7 @@ class PlatformSerializer(JMSWritableNestedModelSerializer):
]
extra_kwargs = {
'su_enabled': {'label': '启用切换账号'},
'protocols_enabled': {'label': '启用协议'},
'domain_enabled': {'label': "启用网域"},
'domain_default': {'label': "默认网域"},
}

View File

@ -9,10 +9,10 @@ app_name = 'assets'
router = BulkRouter()
router.register(r'assets', api.AssetViewSet, 'asset')
router.register(r'hosts', api.HostViewSet, 'host')
router.register(r'devices', api.DeviceViewSet, 'device')
router.register(r'databases', api.DatabaseViewSet, 'database')
router.register(r'web', api.WebViewSet, 'web')
router.register(r'webs', api.WebViewSet, 'web')
router.register(r'clouds', api.CloudViewSet, 'cloud')
router.register(r'networks', api.NetworkViewSet, 'network')
router.register(r'accounts', api.AccountViewSet, 'account')
router.register(r'account-templates', api.AccountTemplateViewSet, 'account-template')
router.register(r'account-secrets', api.AccountSecretsViewSet, 'account-secret')