mirror of https://github.com/jumpserver/jumpserver
parent
ce13b194a5
commit
1b9efff6c7
@ -0,0 +1,26 @@
|
||||
# Generated by Django 3.1.14 on 2022-04-06 07:41
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('assets', '0094_auto_20220402_1736'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='asset',
|
||||
name='category',
|
||||
field=models.CharField(choices=[('host', 'Host'), ('network', 'Networking'), ('database', 'Database'), ('remote_app', 'Remote app'), ('cloud', 'Clouding')], default='host', max_length=16, verbose_name='Category'),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='asset',
|
||||
name='type',
|
||||
field=models.CharField(default='linux', max_length=128, verbose_name='Type'),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
@ -0,0 +1,53 @@
|
||||
# Generated by Django 3.1.14 on 2022-04-06 07:46
|
||||
from itertools import groupby
|
||||
|
||||
from django.db import migrations
|
||||
from django.db.models import F
|
||||
|
||||
|
||||
# ('Linux', 'Linux'),
|
||||
# ('Unix', 'Unix'),
|
||||
# ('MacOS', 'MacOS'),
|
||||
# ('BSD', 'BSD'),
|
||||
# ('Windows', 'Windows'),
|
||||
# ('Other', 'Other'),
|
||||
|
||||
category_mapper = {
|
||||
'Linux': ('host', 'linux'),
|
||||
'Unix': ('host', 'unix'),
|
||||
'MacOS': ('host', 'macos'),
|
||||
'BSD': ('host', 'unix'),
|
||||
'Windows': ('host', 'windows'),
|
||||
'Other': ('host', 'other_host'),
|
||||
}
|
||||
|
||||
|
||||
def migrate_category_and_type(apps, *args):
|
||||
asset_model = apps.get_model('assets', 'Asset')
|
||||
assets_bases = asset_model.objects.all()\
|
||||
.annotate(base=F("platform__base"))\
|
||||
.values_list('id', 'base')\
|
||||
.order_by('base')
|
||||
base_assets = groupby(assets_bases, lambda a: a[1])
|
||||
|
||||
print("")
|
||||
for base, grouper in base_assets:
|
||||
asset_ids = [g[0] for g in grouper]
|
||||
category_type = category_mapper.get(base)
|
||||
if not category_type:
|
||||
continue
|
||||
print("Migrate {} to => {}".format(base, category_type))
|
||||
category, tp = category_type
|
||||
assets = asset_model.objects.filter(id__in=asset_ids)
|
||||
assets.update(category=category, type=tp)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('assets', '0095_auto_20220406_1541'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(migrate_category_and_type)
|
||||
]
|
@ -0,0 +1,73 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class Category(models.TextChoices):
|
||||
HOST = 'host', _('Host')
|
||||
NETWORK = 'network', _("Networking")
|
||||
DATABASE = 'database', _("Database")
|
||||
REMOTE_APP = 'remote_app', _("Remote app")
|
||||
CLOUD = 'cloud', _("Clouding")
|
||||
|
||||
|
||||
class HostTypes(models.TextChoices):
|
||||
LINUX = 'linux', 'Linux'
|
||||
UNIX = 'unix', 'Unix'
|
||||
WINDOWS = 'windows', 'Windows'
|
||||
MACOS = 'macos', 'MacOS'
|
||||
MAINFRAME = 'mainframe', _("Mainframe")
|
||||
OTHER_HOST = 'other_host', _("Other host")
|
||||
|
||||
def __new__(cls, value):
|
||||
"""
|
||||
添加 Category
|
||||
:param value:
|
||||
"""
|
||||
obj = str.__new__(cls)
|
||||
obj.category = Category.HOST
|
||||
return obj
|
||||
|
||||
|
||||
class NetworkTypes(models.TextChoices):
|
||||
SWITCH = 'switch', _("Switch")
|
||||
ROUTER = 'router', _("Router")
|
||||
FIREWALL = 'firewall', _("Firewall")
|
||||
OTHER_NETWORK = 'other_network', _("Other device")
|
||||
|
||||
|
||||
class DatabaseTypes(models.TextChoices):
|
||||
MYSQL = 'mysql', 'MySQL'
|
||||
MARIADB = 'mariadb', 'MariaDB'
|
||||
POSTGRESQL = 'postgresql', 'PostgreSQL'
|
||||
ORACLE = 'oracle', 'Oracle'
|
||||
SQLSERVER = 'sqlserver', 'SQLServer'
|
||||
MONGODB = 'mongodb', 'MongoDB'
|
||||
REDIS = 'redis', 'Redis'
|
||||
|
||||
|
||||
class RemoteAppTypes(models.TextChoices):
|
||||
CHROME = 'chrome', 'Chrome'
|
||||
VSPHERE = 'vsphere', 'vSphere client'
|
||||
MYSQL_WORKBENCH = 'mysql_workbench', 'MySQL workbench'
|
||||
CUSTOM_REMOTE_APP = 'custom_remote_app', _("Custom")
|
||||
|
||||
|
||||
class CloudTypes(models.TextChoices):
|
||||
K8S = 'k8s', 'Kubernetes'
|
||||
|
||||
|
||||
class AllTypes:
|
||||
includes = [
|
||||
HostTypes, NetworkTypes, DatabaseTypes,
|
||||
RemoteAppTypes, CloudTypes
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def choices(cls):
|
||||
choices = []
|
||||
for tp in cls.includes:
|
||||
choices.extend(tp.choices)
|
||||
return choices
|
||||
|
||||
|
||||
|
@ -1,5 +1,9 @@
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.db import models
|
||||
|
||||
from .common import Asset
|
||||
|
||||
|
||||
class RemoteApp(Asset):
|
||||
pass
|
||||
app_path = models.CharField(max_length=1024, verbose_name=_("App path"))
|
||||
attrs = models.JSONField(default=dict, verbose_name=_('Attrs'))
|
||||
|
@ -1 +0,0 @@
|
||||
Subproject commit 244ace5a95503ffaf41b73037692e1121f7c066f
|
Loading…
Reference in new issue