Merge pull request #6933 from rooftopcellist/diff_mode_feature

Diff mode feature
This commit is contained in:
Christian Adams
2017-07-07 16:04:40 -04:00
committed by GitHub
5 changed files with 52 additions and 11 deletions

View File

@@ -2388,9 +2388,9 @@ class JobTemplateSerializer(JobTemplateMixin, UnifiedJobTemplateSerializer, JobO
class Meta:
model = JobTemplate
fields = ('*', 'host_config_key', 'ask_variables_on_launch', 'ask_limit_on_launch', 'ask_tags_on_launch',
fields = ('*', 'host_config_key', 'ask_diff_mode_on_launch', 'ask_variables_on_launch', 'ask_limit_on_launch', 'ask_tags_on_launch',
'ask_skip_tags_on_launch', 'ask_job_type_on_launch', 'ask_verbosity_on_launch', 'ask_inventory_on_launch',
'ask_credential_on_launch', 'survey_enabled', 'become_enabled',
'ask_credential_on_launch', 'survey_enabled', 'become_enabled', 'diff_mode',
'allow_simultaneous')
def get_related(self, obj):
@@ -2438,6 +2438,7 @@ class JobTemplateSerializer(JobTemplateMixin, UnifiedJobTemplateSerializer, JobO
class JobSerializer(UnifiedJobSerializer, JobOptionsSerializer):
passwords_needed_to_start = serializers.ReadOnlyField()
ask_diff_mode_on_launch = serializers.ReadOnlyField()
ask_variables_on_launch = serializers.ReadOnlyField()
ask_limit_on_launch = serializers.ReadOnlyField()
ask_skip_tags_on_launch = serializers.ReadOnlyField()
@@ -2450,11 +2451,11 @@ class JobSerializer(UnifiedJobSerializer, JobOptionsSerializer):
class Meta:
model = Job
fields = ('*', 'job_template', 'passwords_needed_to_start', 'ask_variables_on_launch',
'ask_limit_on_launch', 'ask_tags_on_launch', 'ask_skip_tags_on_launch',
fields = ('*', 'job_template', 'passwords_needed_to_start', 'ask_diff_mode_on_launch',
'ask_variables_on_launch', 'ask_limit_on_launch', 'ask_tags_on_launch', 'ask_skip_tags_on_launch',
'ask_job_type_on_launch', 'ask_verbosity_on_launch', 'ask_inventory_on_launch',
'ask_credential_on_launch', 'allow_simultaneous', 'artifacts', 'scm_revision',
'instance_group')
'instance_group', 'diff_mode')
def get_related(self, obj):
res = super(JobSerializer, self).get_related(obj)
@@ -2585,7 +2586,7 @@ class AdHocCommandSerializer(UnifiedJobSerializer):
model = AdHocCommand
fields = ('*', 'job_type', 'inventory', 'limit', 'credential',
'module_name', 'module_args', 'forks', 'verbosity', 'extra_vars',
'become_enabled', '-unified_job_template', '-description')
'become_enabled', 'diff_mode', '-unified_job_template', '-description')
extra_kwargs = {
'name': {
'read_only': True,
@@ -3058,12 +3059,12 @@ class JobLaunchSerializer(BaseSerializer):
fields = ('can_start_without_user_input', 'passwords_needed_to_start',
'extra_vars', 'limit', 'job_tags', 'skip_tags', 'job_type', 'inventory',
'credential', 'extra_credentials', 'ask_variables_on_launch', 'ask_tags_on_launch',
'ask_skip_tags_on_launch', 'ask_job_type_on_launch', 'ask_limit_on_launch',
'ask_diff_mode_on_launch', 'ask_skip_tags_on_launch', 'ask_job_type_on_launch', 'ask_limit_on_launch',
'ask_verbosity_on_launch', 'ask_inventory_on_launch', 'ask_credential_on_launch',
'survey_enabled', 'variables_needed_to_start', 'credential_needed_to_start',
'inventory_needed_to_start', 'job_template_data', 'defaults', 'verbosity')
read_only_fields = (
'ask_variables_on_launch', 'ask_limit_on_launch', 'ask_tags_on_launch',
'ask_diff_mode_on_launch', 'ask_variables_on_launch', 'ask_limit_on_launch', 'ask_tags_on_launch',
'ask_skip_tags_on_launch', 'ask_job_type_on_launch', 'ask_verbosity_on_launch',
'ask_inventory_on_launch', 'ask_credential_on_launch',)
extra_kwargs = {

View File

@@ -331,4 +331,24 @@ class Migration(migrations.Migration):
name='timeout',
field=models.IntegerField(default=0, help_text='The amount of time (in seconds) to run before the task is canceled.', blank=True),
),
migrations.AddField(
model_name='job',
name='diff_mode',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='jobtemplate',
name='diff_mode',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='adhoccommand',
name='diff_mode',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='jobtemplate',
name='ask_diff_mode_on_launch',
field=models.BooleanField(default=False),
),
]

View File

@@ -34,6 +34,9 @@ class AdHocCommand(UnifiedJob, JobNotificationMixin):
class Meta(object):
app_label = 'main'
diff_mode = models.BooleanField(
default=False,
)
job_type = models.CharField(
max_length=64,
choices=AD_HOC_JOB_TYPE_CHOICES,
@@ -195,7 +198,7 @@ class AdHocCommand(UnifiedJob, JobNotificationMixin):
data = {}
for field in ('job_type', 'inventory_id', 'limit', 'credential_id',
'module_name', 'module_args', 'forks', 'verbosity',
'extra_vars', 'become_enabled'):
'extra_vars', 'become_enabled', 'diff_mode'):
data[field] = getattr(self, field)
return AdHocCommand.objects.create(**data)

View File

@@ -60,6 +60,9 @@ class JobOptions(BaseModel):
class Meta:
abstract = True
diff_mode = models.BooleanField(
default=False,
)
job_type = models.CharField(
max_length=64,
choices=JOB_TYPE_CHOICES,
@@ -237,7 +240,10 @@ class JobTemplate(UnifiedJobTemplate, JobOptions, SurveyJobTemplateMixin, Resour
blank=True,
default='',
)
ask_diff_mode_on_launch = models.BooleanField(
blank=True,
default=False,
)
ask_variables_on_launch = models.BooleanField(
blank=True,
default=False,
@@ -293,7 +299,7 @@ class JobTemplate(UnifiedJobTemplate, JobOptions, SurveyJobTemplateMixin, Resour
'job_tags', 'extra_vars', 'launch_type', 'force_handlers',
'skip_tags', 'start_at_task', 'become_enabled', 'labels',
'survey_passwords', 'allow_simultaneous', 'timeout',
'use_fact_cache',]
'use_fact_cache', 'diff_mode',]
def resource_validation_data(self):
'''
@@ -361,6 +367,7 @@ class JobTemplate(UnifiedJobTemplate, JobOptions, SurveyJobTemplateMixin, Resour
def _ask_for_vars_dict(self):
return dict(
diff_mode=self.ask_diff_mode_on_launch,
extra_vars=self.ask_variables_on_launch,
limit=self.ask_limit_on_launch,
job_tags=self.ask_tags_on_launch,
@@ -522,6 +529,12 @@ class Job(UnifiedJob, JobOptions, SurveyJobMixin, JobNotificationMixin):
h = hmac.new(settings.SECRET_KEY, self.created.isoformat(), digestmod=hashlib.sha1)
return '%d-%s' % (self.pk, h.hexdigest())
@property
def ask_diff_mode_on_launch(self):
if self.job_template is not None:
return self.job_template.ask_diff_mode_on_launch
return False
@property
def ask_variables_on_launch(self):
if self.job_template is not None:

View File

@@ -1012,6 +1012,8 @@ class RunJob(BaseTask):
args.append('--ask-pass')
if job.become_enabled:
args.append('--become')
if job.diff_mode:
args.append('--diff')
if become_method:
args.extend(['--become-method', become_method])
if become_username:
@@ -2009,6 +2011,8 @@ class RunAdHocCommand(BaseTask):
if ad_hoc_command.forks: # FIXME: Max limit?
args.append('--forks=%d' % ad_hoc_command.forks)
if ad_hoc_command.diff_mode:
args.append('--diff')
if ad_hoc_command.verbosity:
args.append('-%s' % ('v' * min(5, ad_hoc_command.verbosity)))