mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-18 16:39:28 +00:00
feat: 增加运行的内置变量,优化self资源的代码
This commit is contained in:
@@ -14,6 +14,7 @@ __all__ = ["Job", "JobExecution"]
|
||||
from common.db.models import JMSBaseModel
|
||||
from ops.ansible import JMSInventory, AdHocRunner, PlaybookRunner
|
||||
from ops.mixin import PeriodTaskModelMixin
|
||||
from ops.variables import *
|
||||
|
||||
|
||||
class Job(JMSBaseModel, PeriodTaskModelMixin):
|
||||
@@ -128,6 +129,9 @@ class JobExecution(JMSBaseModel):
|
||||
else:
|
||||
extra_vars = {}
|
||||
|
||||
static_variables = self.gather_static_variables()
|
||||
extra_vars.update(static_variables)
|
||||
|
||||
if self.job.type == 'adhoc':
|
||||
args = self.compile_shell()
|
||||
runner = AdHocRunner(
|
||||
@@ -142,6 +146,14 @@ class JobExecution(JMSBaseModel):
|
||||
raise Exception("unsupported job type")
|
||||
return runner
|
||||
|
||||
def gather_static_variables(self):
|
||||
default = {
|
||||
JMS_USERNAME: self.creator.username,
|
||||
JMS_JOB_ID: self.job.id,
|
||||
JMS_JOB_NAME: self.job.name,
|
||||
}
|
||||
return default
|
||||
|
||||
@property
|
||||
def short_id(self):
|
||||
return str(self.id).split('-')[-1]
|
||||
|
Reference in New Issue
Block a user