Add ability to monitor jobs and workflow_jobs via awx cli, fixes #6165

Signed-off-by: Francois Herbert <francois@herbert.org.nz>

Fixup linting

Remove timeout option, not really required and it's making the api test fail
This commit is contained in:
Francois Herbert 2020-04-22 15:21:51 +12:00 committed by Ryan Petrello
parent 17702c94f7
commit d0384799fd
No known key found for this signature in database
GPG Key ID: F2AA5F2122351777

View File

@ -552,3 +552,41 @@ class SettingsModify(CustomAction):
except json.decoder.JSONDecodeError:
return False
return True
class HasMonitor(object):
action = 'monitor'
def add_arguments(self, parser, resource_options_parser):
from .options import pk_or_name
parser.choices[self.action].add_argument(
'id',
type=functools.partial(
pk_or_name, None, self.resource, page=self.page
),
help=''
)
def perform(self, **kwargs):
response = self.page.get()
mon = monitor_workflow if response.type == 'workflow_job' else monitor
if not response.failed and response.status != 'successful':
status = mon(
response,
self.page.connection.session,
)
if status:
response.json['status'] = status
if status in ('failed', 'error'):
setattr(response, 'rc', 1)
else:
return 'Unable to monitor finished job'
class JobMonitor(HasMonitor, CustomAction):
resource = 'jobs'
class WorkflowJobMonitor(HasMonitor, CustomAction):
resource = 'workflow_jobs'