mirror of
https://github.com/ansible/awx.git
synced 2026-02-27 15:58:45 -03:30
Jobs updates to start/cancel and prompt for passwords via the admin.
This commit is contained in:
@@ -89,6 +89,11 @@ class JobAdminForm(JobTemplateAdminForm):
|
||||
'''Custom admin form for creating Jobs.'''
|
||||
|
||||
start_job = forms.BooleanField(initial=False, required=False)
|
||||
ssh_password = forms.CharField(label=_('SSH password'), required=False)
|
||||
sudo_password = forms.CharField(required=False)
|
||||
ssh_key_unlock = forms.CharField(label=_('SSH key passphrase'),
|
||||
required=False)
|
||||
cancel_job = forms.BooleanField(initial=False, required=False)
|
||||
|
||||
class Meta:
|
||||
model = Job
|
||||
@@ -97,19 +102,45 @@ class JobAdminForm(JobTemplateAdminForm):
|
||||
super(JobAdminForm, self).__init__(*args, **kwargs)
|
||||
if self.instance.pk and self.instance.status != 'new':
|
||||
self.fields.pop('playbook', None)
|
||||
if (not self.data or self.data.get('start_job', '')) and \
|
||||
self.instance.credential and self.instance.status == 'new':
|
||||
for field in self.instance.get_passwords_needed_to_start():
|
||||
if field not in self.fields:
|
||||
continue
|
||||
self.fields[field].required = True
|
||||
|
||||
def clean_start_job(self):
|
||||
return self.cleaned_data.get('start_job', False)
|
||||
|
||||
def clean_cancel_job(self):
|
||||
return self.cleaned_data.get('cancel_job', False)
|
||||
|
||||
def clean(self):
|
||||
if self.instance.credential and self.instance.status == 'new':
|
||||
for field in self.instance.get_passwords_needed_to_start():
|
||||
if field in self.fields:
|
||||
self.fields[field].required = True
|
||||
return super(JobAdminForm, self).clean()
|
||||
|
||||
def save(self, commit=True):
|
||||
instance = super(JobAdminForm, self).save(commit)
|
||||
save_m2m = getattr(self, 'save_m2m', lambda: None)
|
||||
should_start = bool(self.cleaned_data.get('start_job', '') and
|
||||
instance.status == 'new')
|
||||
start_opts = {}
|
||||
for field in ('ssh_password', 'sudo_password', 'ssh_key_unlock'):
|
||||
value = self.cleaned_data.get(field, '')
|
||||
if value:
|
||||
start_opts[field] = value
|
||||
#print 'should_start', should_start
|
||||
should_cancel = bool(self.cleaned_data.get('cancel_job', '') and
|
||||
instance.status in ('new', 'pending'))
|
||||
def new_save_m2m():
|
||||
save_m2m()
|
||||
if should_start:
|
||||
instance.start()
|
||||
instance.start(**start_opts)
|
||||
if should_cancel:
|
||||
instance.cancel()
|
||||
if commit:
|
||||
new_save_m2m()
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user