mirror of https://github.com/jumpserver/jumpserver
perf: 优化平台
parent
e0e14a2fe1
commit
9b2acfe4a4
|
@ -1,13 +1,13 @@
|
||||||
|
|
||||||
from assets.serializers import HostSerializer
|
from assets.serializers import HostSerializer
|
||||||
from assets.models import Networking
|
from assets.models import Device
|
||||||
from .asset import AssetViewSet
|
from .asset import AssetViewSet
|
||||||
|
|
||||||
__all__ = ['NetworkViewSet']
|
__all__ = ['DeviceViewSet']
|
||||||
|
|
||||||
|
|
||||||
class NetworkViewSet(AssetViewSet):
|
class DeviceViewSet(AssetViewSet):
|
||||||
model = Networking
|
model = Device
|
||||||
|
|
||||||
def get_serializer_classes(self):
|
def get_serializer_classes(self):
|
||||||
serializer_classes = super().get_serializer_classes()
|
serializer_classes = super().get_serializer_classes()
|
||||||
|
|
|
@ -6,7 +6,7 @@ from common.tree import TreeNode
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'Category', 'HostTypes', 'NetworkingTypes', 'DatabaseTypes',
|
'Category', 'HostTypes', 'DeviceTypes', 'DatabaseTypes',
|
||||||
'WebTypes', 'CloudTypes', 'Protocol', 'AllTypes',
|
'WebTypes', 'CloudTypes', 'Protocol', 'AllTypes',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ class PlatformMixin:
|
||||||
return {
|
return {
|
||||||
'domain_enabled': False,
|
'domain_enabled': False,
|
||||||
'su_enabled': False,
|
'su_enabled': False,
|
||||||
'vendor_enabled': False,
|
'brand_enabled': False,
|
||||||
'ping_enabled': False,
|
'ping_enabled': False,
|
||||||
'gather_facts_enabled': False,
|
'gather_facts_enabled': False,
|
||||||
'change_password_enabled': False,
|
'change_password_enabled': False,
|
||||||
|
@ -30,9 +30,9 @@ class PlatformMixin:
|
||||||
|
|
||||||
class Category(PlatformMixin, ChoicesMixin, models.TextChoices):
|
class Category(PlatformMixin, ChoicesMixin, models.TextChoices):
|
||||||
HOST = 'host', _('Host')
|
HOST = 'host', _('Host')
|
||||||
NETWORKING = 'networking', _("NetworkDevice")
|
DEVICE = 'device', _("Device")
|
||||||
DATABASE = 'database', _("Database")
|
DATABASE = 'database', _("Database")
|
||||||
CLOUD = 'cloud', _("Clouding")
|
CLOUD = 'cloud', _("Cloud service")
|
||||||
WEB = 'web', _("Web")
|
WEB = 'web', _("Web")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -49,7 +49,7 @@ class Category(PlatformMixin, ChoicesMixin, models.TextChoices):
|
||||||
'gather_accounts_enabled': True, 'gather_accounts_method': 'gather_accounts_posix',
|
'gather_accounts_enabled': True, 'gather_accounts_method': 'gather_accounts_posix',
|
||||||
'_protocols': ['ssh', 'telnet'],
|
'_protocols': ['ssh', 'telnet'],
|
||||||
},
|
},
|
||||||
cls.NETWORKING: {
|
cls.DEVICE: {
|
||||||
'domain_enabled': True,
|
'domain_enabled': True,
|
||||||
'brand_enabled': True,
|
'brand_enabled': True,
|
||||||
'brands': [
|
'brands': [
|
||||||
|
@ -108,7 +108,7 @@ class HostTypes(PlatformMixin, ChoicesMixin, models.TextChoices):
|
||||||
LINUX = 'linux', 'Linux'
|
LINUX = 'linux', 'Linux'
|
||||||
WINDOWS = 'windows', 'Windows'
|
WINDOWS = 'windows', 'Windows'
|
||||||
UNIX = 'unix', 'Unix'
|
UNIX = 'unix', 'Unix'
|
||||||
OTHER_HOST = 'other_host', _("Other host")
|
OTHER_HOST = 'other', _("Other")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def platform_constraints(cls):
|
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")
|
GENERAL = 'general', _("General device")
|
||||||
SWITCH = 'switch', _("Switch")
|
SWITCH = 'switch', _("Switch")
|
||||||
ROUTER = 'router', _("Router")
|
ROUTER = 'router', _("Router")
|
||||||
|
@ -163,7 +163,7 @@ class DatabaseTypes(PlatformMixin, ChoicesMixin, models.TextChoices):
|
||||||
|
|
||||||
|
|
||||||
class WebTypes(PlatformMixin, ChoicesMixin, models.TextChoices):
|
class WebTypes(PlatformMixin, ChoicesMixin, models.TextChoices):
|
||||||
WEBSITE = 'website', _('General Website')
|
WEBSITE = 'website', _('General website')
|
||||||
|
|
||||||
|
|
||||||
class CloudTypes(PlatformMixin, ChoicesMixin, models.TextChoices):
|
class CloudTypes(PlatformMixin, ChoicesMixin, models.TextChoices):
|
||||||
|
@ -181,7 +181,7 @@ class CloudTypes(PlatformMixin, ChoicesMixin, models.TextChoices):
|
||||||
class AllTypes(ChoicesMixin, metaclass=IncludesTextChoicesMeta):
|
class AllTypes(ChoicesMixin, metaclass=IncludesTextChoicesMeta):
|
||||||
choices: list
|
choices: list
|
||||||
includes = [
|
includes = [
|
||||||
HostTypes, NetworkingTypes, DatabaseTypes,
|
HostTypes, DeviceTypes, DatabaseTypes,
|
||||||
WebTypes, CloudTypes
|
WebTypes, CloudTypes
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ class AllTypes(ChoicesMixin, metaclass=IncludesTextChoicesMeta):
|
||||||
def category_types(cls):
|
def category_types(cls):
|
||||||
return (
|
return (
|
||||||
(Category.HOST, HostTypes),
|
(Category.HOST, HostTypes),
|
||||||
(Category.NETWORKING, NetworkingTypes),
|
(Category.DEVICE, DeviceTypes),
|
||||||
(Category.DATABASE, DatabaseTypes),
|
(Category.DATABASE, DatabaseTypes),
|
||||||
(Category.WEB, WebTypes),
|
(Category.WEB, WebTypes),
|
||||||
(Category.CLOUD, CloudTypes)
|
(Category.CLOUD, CloudTypes)
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Migration(migrations.Migration):
|
||||||
bases=('assets.asset',),
|
bases=('assets.asset',),
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Networking',
|
name='Device',
|
||||||
fields=[
|
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')),
|
('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')),
|
||||||
],
|
],
|
||||||
|
|
|
@ -31,7 +31,7 @@ class Migration(migrations.Migration):
|
||||||
('date_created', models.DateTimeField(blank=True, editable=False, verbose_name='Date created')),
|
('date_created', models.DateTimeField(blank=True, editable=False, verbose_name='Date created')),
|
||||||
('date_updated', models.DateTimeField(blank=True, editable=False, verbose_name='Date updated')),
|
('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')),
|
('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')),
|
('version', models.IntegerField(default=0, verbose_name='Version')),
|
||||||
('history_id', models.AutoField(primary_key=True, serialize=False)),
|
('history_id', models.AutoField(primary_key=True, serialize=False)),
|
||||||
('history_date', models.DateTimeField(db_index=True)),
|
('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_created', models.DateTimeField(auto_now_add=True, verbose_name='Date created')),
|
||||||
('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
|
('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
|
||||||
('created_by', models.CharField(max_length=128, null=True, verbose_name='Created by')),
|
('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')),
|
('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')),
|
('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')),
|
('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')),
|
||||||
|
|
|
@ -28,7 +28,7 @@ class Migration(migrations.Migration):
|
||||||
('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
|
('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
|
||||||
('created_by', models.CharField(max_length=128, null=True, verbose_name='Created by')),
|
('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')),
|
('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={
|
options={
|
||||||
'verbose_name': 'Account template',
|
'verbose_name': 'Account template',
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from .common import *
|
from .common import *
|
||||||
from .host import *
|
from .host import *
|
||||||
from .database import *
|
from .database import *
|
||||||
from .networking import *
|
from .device import *
|
||||||
from .web import *
|
from .web import *
|
||||||
from .cloud import *
|
from .cloud import *
|
||||||
|
|
|
@ -2,6 +2,5 @@
|
||||||
from .common import Asset
|
from .common import Asset
|
||||||
|
|
||||||
|
|
||||||
class Networking(Asset):
|
class Device(Asset):
|
||||||
|
|
||||||
pass
|
pass
|
|
@ -62,7 +62,7 @@ class BaseAccount(OrgModelMixin):
|
||||||
private_key = fields.EncryptTextField(blank=True, null=True, verbose_name=_('SSH private key'))
|
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'))
|
public_key = fields.EncryptTextField(blank=True, null=True, verbose_name=_('SSH public key'))
|
||||||
token = fields.EncryptTextField(blank=True, null=True, verbose_name=_('Token'))
|
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'))
|
comment = models.TextField(blank=True, verbose_name=_('Comment'))
|
||||||
date_created = models.DateTimeField(auto_now_add=True, verbose_name=_("Date created"))
|
date_created = models.DateTimeField(auto_now_add=True, verbose_name=_("Date created"))
|
||||||
date_updated = models.DateTimeField(auto_now=True, verbose_name=_("Date updated"))
|
date_updated = models.DateTimeField(auto_now=True, verbose_name=_("Date updated"))
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
from .account import *
|
from .account import *
|
||||||
from .account_history import *
|
from .history import *
|
||||||
from .account_template import *
|
from .template import *
|
||||||
|
|
|
@ -10,12 +10,13 @@ from .common import AccountFieldsSerializerMixin
|
||||||
class AccountTemplateSerializer(AuthValidateMixin, BulkOrgResourceModelSerializer):
|
class AccountTemplateSerializer(AuthValidateMixin, BulkOrgResourceModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = AccountTemplate
|
model = AccountTemplate
|
||||||
fields_mini = ['id', 'privileged', 'username']
|
fields_mini = ['id', 'name', 'username', 'privileged']
|
||||||
fields_write_only = AccountFieldsSerializerMixin.Meta.fields_write_only
|
fields_write_only = AccountFieldsSerializerMixin.Meta.fields_write_only
|
||||||
fields_other = AccountFieldsSerializerMixin.Meta.fields_other
|
fields_other = AccountFieldsSerializerMixin.Meta.fields_other
|
||||||
fields = fields_mini + fields_write_only + fields_other
|
fields = fields_mini + fields_write_only + fields_other
|
||||||
extra_kwargs = {
|
extra_kwargs = {
|
||||||
'username': {'required': True},
|
'username': {'required': True},
|
||||||
|
'name': {'required': True},
|
||||||
'private_key': {'write_only': True},
|
'private_key': {'write_only': True},
|
||||||
'public_key': {'write_only': True},
|
'public_key': {'write_only': True},
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
from .common import *
|
from .common import *
|
||||||
from .host import *
|
from .host import *
|
||||||
from .database import *
|
from .database import *
|
||||||
from .networking import *
|
from .device import *
|
||||||
from .cloud import *
|
from .cloud import *
|
||||||
from .web import *
|
from .web import *
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from assets.models import Networking
|
from assets.models import Device
|
||||||
from .common import AssetSerializer
|
from .common import AssetSerializer
|
||||||
|
|
||||||
__all__ = ['NetworkingSerializer']
|
__all__ = ['NetworkingSerializer']
|
||||||
|
@ -6,4 +6,4 @@ __all__ = ['NetworkingSerializer']
|
||||||
|
|
||||||
class NetworkingSerializer(AssetSerializer):
|
class NetworkingSerializer(AssetSerializer):
|
||||||
class Meta(AssetSerializer.Meta):
|
class Meta(AssetSerializer.Meta):
|
||||||
model = Networking
|
model = Device
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
from assets.models import Networking
|
from assets.models import Device
|
||||||
from .common import AssetSerializer
|
from .common import AssetSerializer
|
||||||
|
|
||||||
__all__ = ['NetworkingSerializer']
|
__all__ = ['NetworkingSerializer']
|
||||||
|
@ -7,4 +7,4 @@ __all__ = ['NetworkingSerializer']
|
||||||
|
|
||||||
class NetworkingSerializer(AssetSerializer):
|
class NetworkingSerializer(AssetSerializer):
|
||||||
class Meta(AssetSerializer.Meta):
|
class Meta(AssetSerializer.Meta):
|
||||||
model = Networking
|
model = Device
|
|
@ -38,6 +38,8 @@ class PlatformAutomationSerializer(serializers.ModelSerializer):
|
||||||
'gather_accounts_enabled', 'gather_accounts_method',
|
'gather_accounts_enabled', 'gather_accounts_method',
|
||||||
]
|
]
|
||||||
extra_kwargs = {
|
extra_kwargs = {
|
||||||
|
'ping_enabled': {'label': '启用资产探测'},
|
||||||
|
'ping_method': {'label': '探测方式'},
|
||||||
'gather_facts_enabled': {'label': '启用收集信息'},
|
'gather_facts_enabled': {'label': '启用收集信息'},
|
||||||
'gather_facts_method': {'label': '收集信息方式'},
|
'gather_facts_method': {'label': '收集信息方式'},
|
||||||
'verify_account_enabled': {'label': '启用校验账号'},
|
'verify_account_enabled': {'label': '启用校验账号'},
|
||||||
|
@ -82,6 +84,7 @@ class PlatformSerializer(JMSWritableNestedModelSerializer):
|
||||||
]
|
]
|
||||||
extra_kwargs = {
|
extra_kwargs = {
|
||||||
'su_enabled': {'label': '启用切换账号'},
|
'su_enabled': {'label': '启用切换账号'},
|
||||||
|
'protocols_enabled': {'label': '启用协议'},
|
||||||
'domain_enabled': {'label': "启用网域"},
|
'domain_enabled': {'label': "启用网域"},
|
||||||
'domain_default': {'label': "默认网域"},
|
'domain_default': {'label': "默认网域"},
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,10 @@ app_name = 'assets'
|
||||||
router = BulkRouter()
|
router = BulkRouter()
|
||||||
router.register(r'assets', api.AssetViewSet, 'asset')
|
router.register(r'assets', api.AssetViewSet, 'asset')
|
||||||
router.register(r'hosts', api.HostViewSet, 'host')
|
router.register(r'hosts', api.HostViewSet, 'host')
|
||||||
|
router.register(r'devices', api.DeviceViewSet, 'device')
|
||||||
router.register(r'databases', api.DatabaseViewSet, 'database')
|
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'clouds', api.CloudViewSet, 'cloud')
|
||||||
router.register(r'networks', api.NetworkViewSet, 'network')
|
|
||||||
router.register(r'accounts', api.AccountViewSet, 'account')
|
router.register(r'accounts', api.AccountViewSet, 'account')
|
||||||
router.register(r'account-templates', api.AccountTemplateViewSet, 'account-template')
|
router.register(r'account-templates', api.AccountTemplateViewSet, 'account-template')
|
||||||
router.register(r'account-secrets', api.AccountSecretsViewSet, 'account-secret')
|
router.register(r'account-secrets', api.AccountSecretsViewSet, 'account-secret')
|
||||||
|
|
Loading…
Reference in New Issue