Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

Commit

Permalink
If old credential field specified, add to JT
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCoding committed Oct 24, 2019
1 parent 31fd5d8 commit 761bad1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tower_cli/resources/job_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,22 @@ class Resource(models.SurveyResource):
labels = models.ManyToManyField('label')
instance_groups = models.ManyToManyField('instance_group', method_name='ig')

def write(self, *args, **kwargs):
def write(self, pk=None, *args, **kwargs):
# Provide a default value for job_type, but only in creation of JT
if (kwargs.get('create_on_missing', False) and
(not kwargs.get('job_type', None))):
kwargs['job_type'] = 'run'
return super(Resource, self).write(*args, **kwargs)
mcred = kwargs.get('credential', None)
ret = super(Resource, self).write(pk=pk, **kwargs)
cred_ids = [c['id'] for c in ret.get('summary_fields', {}).get('credentials', [])]
if mcred and mcred not in cred_ids:
new_pk = ret['id']
debug.log('Processing deprecated credential field via another request.', header='details')
self._assoc('credentials', new_pk, mcred)
ret = self.read(new_pk)
ret['id'] = new_pk
ret['changed'] = True
return ret

@resources.command(use_fields_as_options=False)
@click.option('--job-template', type=types.Related('job_template'))
Expand Down

0 comments on commit 761bad1

Please sign in to comment.