pref: 添加 applet host actions

pull/9019/head
ibuler 2 years ago
parent cb57ae104b
commit 0d2bfaa768

@ -0,0 +1,53 @@
# Generated by Django 3.2.14 on 2022-11-02 12:17
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assets', '0108_auto_20221027_1053'),
]
operations = [
migrations.AddField(
model_name='account',
name='is_active',
field=models.BooleanField(default=True, verbose_name='Is active'),
),
migrations.AddField(
model_name='account',
name='updated_by',
field=models.CharField(blank=True, max_length=32, null=True, verbose_name='Updated by'),
),
migrations.AddField(
model_name='accounttemplate',
name='is_active',
field=models.BooleanField(default=True, verbose_name='Is active'),
),
migrations.AddField(
model_name='accounttemplate',
name='updated_by',
field=models.CharField(blank=True, max_length=32, null=True, verbose_name='Updated by'),
),
migrations.AddField(
model_name='gateway',
name='updated_by',
field=models.CharField(blank=True, max_length=32, null=True, verbose_name='Updated by'),
),
migrations.AlterField(
model_name='account',
name='date_created',
field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='Date created'),
),
migrations.AlterField(
model_name='accounttemplate',
name='date_created',
field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='Date created'),
),
migrations.AlterField(
model_name='gateway',
name='date_created',
field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='Date created'),
),
]

@ -6,7 +6,6 @@ import uuid
from hashlib import md5
import sshpubkeys
from django.core.cache import cache
from django.db import models
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
@ -19,7 +18,7 @@ from common.utils import (
)
from common.db import fields
from assets.const import Connectivity
from orgs.mixins.models import OrgModelMixin
from orgs.mixins.models import JMSOrgBaseModel
logger = get_logger(__file__)
@ -48,14 +47,13 @@ class AbsConnectivity(models.Model):
abstract = True
class BaseAccount(OrgModelMixin):
class BaseAccount(JMSOrgBaseModel):
class SecretType(models.TextChoices):
password = 'password', _('Password')
ssh_key = 'ssh_key', _('SSH key')
access_key = 'access_key', _('Access key')
token = 'token', _('Token')
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
name = models.CharField(max_length=128, verbose_name=_("Name"))
username = models.CharField(max_length=128, blank=True, verbose_name=_('Username'), db_index=True)
secret_type = models.CharField(
@ -63,9 +61,8 @@ class BaseAccount(OrgModelMixin):
)
secret = fields.EncryptTextField(blank=True, null=True, verbose_name=_('Secret'))
privileged = models.BooleanField(verbose_name=_("Privileged"), default=False)
is_active = models.BooleanField(default=True, verbose_name=_("Is active"))
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"))
created_by = models.CharField(max_length=128, null=True, verbose_name=_('Created by'))
@property

@ -14,6 +14,23 @@ class AppletHostViewSet(viewsets.ModelViewSet):
serializer_class = serializers.AppletHostSerializer
queryset = AppletHost.objects.all()
@action(methods=['post'], detail=True)
def report(self, request, *args, **kwargs):
# TODO:
# 1. 上报 安装的 Applets 每小时
# 2. Host 和 Terminal 关联
instance = self.get_object()
instance.sync()
return Response({'msg': 'ok'})
@action(methods=['get'], detail=True)
def accounts(self, request, *args, **kwargs):
# TODO:
# 1. 返回 host 上的所有用户, host 可以去创建和更新 每小时
# 2. 密码长度最少 8 位,包含大小写字母和数字和特殊字符
instance = self.get_object()
return Response(instance.get_accounts())
class AppletHostDeploymentViewSet(viewsets.ModelViewSet):
serializer_class = serializers.AppletHostDeploymentSerializer

@ -0,0 +1,24 @@
# Generated by Django 3.2.14 on 2022-11-02 11:41
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('terminal', '0056_auto_20221101_1353'),
]
operations = [
migrations.AddField(
model_name='applethost',
name='terminal',
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='applet_host', to='terminal.terminal', verbose_name='Terminal'),
),
migrations.AlterField(
model_name='appletpublication',
name='status',
field=models.CharField(default='ready', max_length=16, verbose_name='Status'),
),
]

@ -17,6 +17,10 @@ class AppletHost(Host):
date_inited = models.DateTimeField(null=True, blank=True, verbose_name=_('Date inited'))
date_synced = models.DateTimeField(null=True, blank=True, verbose_name=_('Date synced'))
status = models.CharField(max_length=16, verbose_name=_('Status'))
terminal = models.OneToOneField(
'terminal.Terminal', on_delete=models.PROTECT, null=True, blank=True,
related_name='applet_host', verbose_name=_('Terminal')
)
applets = models.ManyToManyField(
'Applet', verbose_name=_('Applet'),
through='AppletPublication', through_fields=('host', 'applet'),

@ -5,13 +5,12 @@ from itertools import groupby, chain
from django.conf import settings
from django.core.files.storage import default_storage
import jms_storage
from common.utils import get_logger
from tickets.models import TicketSession
from . import const
from .models import ReplayStorage
from tickets.models import TicketSession
logger = get_logger(__name__)

Loading…
Cancel
Save