feat: 代码片段支持 oracle 和 mariadb

pull/11650/head
Aaron3S 2023-09-21 15:57:04 +08:00 committed by Bryan
parent 4cb499953c
commit 9892ff7dd6
4 changed files with 25 additions and 5 deletions

View File

@ -45,7 +45,7 @@ class RunasPolicies(models.TextChoices):
skip = 'skip', _('Skip')
class Modules(models.TextChoices):
class JobModules(models.TextChoices):
shell = 'shell', _('Shell')
winshell = 'win_shell', _('Powershell')
python = 'python', _('Python')
@ -55,6 +55,18 @@ class Modules(models.TextChoices):
raw = 'raw', _('Raw')
class AdHocModules(models.TextChoices):
shell = 'shell', _('Shell')
winshell = 'win_shell', _('Powershell')
python = 'python', _('Python')
mysql = 'mysql', _('MySQL')
mariadb = 'mariadb', _('MariaDB')
postgresql = 'postgresql', _('PostgreSQL')
sqlserver = 'sqlserver', _('SQLServer')
oracle = 'oracle', _('Oracle')
raw = 'raw', _('Raw')
class JobStatus(models.TextChoices):
running = 'running', _('Running')
success = 'success', _('Success')

View File

@ -36,4 +36,12 @@ class Migration(migrations.Migration):
name='summary',
field=models.JSONField(default=dict, encoder=common.db.encoder.ModelJSONFieldEncoder, verbose_name='Summary'),
),
migrations.AlterField(
model_name='adhoc',
name='module',
field=models.CharField(
choices=[('shell', 'Shell'), ('win_shell', 'Powershell'), ('python', 'Python'), ('mysql', 'MySQL'),
('mariadb', 'MariaDB'), ('postgresql', 'PostgreSQL'), ('sqlserver', 'SQLServer'),
('oracle', 'Oracle'), ('raw', 'Raw')], default='shell', max_length=128, verbose_name='Module'),
),
]

View File

@ -8,7 +8,7 @@ from common.utils import get_logger
__all__ = ["AdHoc"]
from ops.const import Modules
from ops.const import AdHocModules
from orgs.mixins.models import JMSOrgBaseModel
@ -19,7 +19,7 @@ class AdHoc(JMSOrgBaseModel):
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
name = models.CharField(max_length=128, verbose_name=_('Name'))
pattern = models.CharField(max_length=1024, verbose_name=_("Pattern"), default='all')
module = models.CharField(max_length=128, choices=Modules.choices, default=Modules.shell,
module = models.CharField(max_length=128, choices=AdHocModules.choices, default=AdHocModules.shell,
verbose_name=_('Module'))
args = models.CharField(max_length=8192, default='', verbose_name=_('Args'))
creator = models.ForeignKey('users.User', verbose_name=_("Creator"), on_delete=models.SET_NULL, null=True)

View File

@ -23,7 +23,7 @@ from common.db.encoder import ModelJSONFieldEncoder
from ops.ansible import JMSInventory, AdHocRunner, PlaybookRunner, CommandInBlackListException
from ops.mixin import PeriodTaskModelMixin
from ops.variables import *
from ops.const import Types, Modules, RunasPolicies, JobStatus
from ops.const import Types, RunasPolicies, JobStatus, JobModules
from orgs.mixins.models import JMSOrgBaseModel
from perms.models import AssetPermission
from perms.utils import UserPermAssetUtil
@ -127,7 +127,7 @@ class Job(JMSOrgBaseModel, PeriodTaskModelMixin):
instant = models.BooleanField(default=False)
args = models.CharField(max_length=8192, default='', verbose_name=_('Args'), null=True, blank=True)
module = models.CharField(max_length=128, choices=Modules.choices, default=Modules.shell, verbose_name=_('Module'),
module = models.CharField(max_length=128, choices=JobModules.choices, default=JobModules.shell, verbose_name=_('Module'),
null=True)
chdir = models.CharField(default="", max_length=1024, verbose_name=_('Chdir'), null=True, blank=True)
timeout = models.IntegerField(default=-1, verbose_name=_('Timeout (Seconds)'))