Skip to content

Commit

Permalink
Merge pull request #122 from konono/add_workflow_nodes
Browse files Browse the repository at this point in the history
Addition of the workflow_nodes for WorkflowRunJob
  • Loading branch information
costastf authored Sep 13, 2023
2 parents 42658db + 1b494a6 commit 5a0df49
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
3 changes: 2 additions & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ Contributors
* Octavian Balas <octavian.balas@gmail.com>
* Philipp Hoffmann <phoffmann@spirit21.com>
* Iqbal Nazir <iqbalnazirsumon@gmail.com>
* Jeremy Shade <jeremy.shade@outlook.com>
* Jeremy Shade <jeremy.shade@outlook.com>
* Yuki Yamashita <kono@ms1.kononet.jp>
4 changes: 3 additions & 1 deletion towerlib/entities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
SystemJob,
ProjectUpdateJob,
AdHocCommandJob,
Job)
Job,
WorkflowNodes)
from towerlib.entities.role import Role, ObjectRole
from towerlib.entities.core import (Entity,
Config,
Expand Down Expand Up @@ -141,3 +142,4 @@
assert Settings
assert Saml
assert Label
assert WorkflowNodes
63 changes: 62 additions & 1 deletion towerlib/entities/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
__docformat__ = '''google'''
__date__ = '''2018-01-03'''
__copyright__ = '''Copyright 2018, Costas Tyfoxylos'''
__credits__ = ["Costas Tyfoxylos"]
__credits__ = ["Costas Tyfoxylos", "Yuki Yamashita"]
__license__ = '''MIT'''
__maintainer__ = '''Costas Tyfoxylos'''
__email__ = '''<ctyfoxylos@schubergphilis.com>'''
Expand Down Expand Up @@ -715,6 +715,17 @@ def _get_dynamic_value(self, variable):
response = self._tower.session.get(url)
return response.json().get(variable) if response.ok else None

@property
def workflow_nodes(self):
"""Workflow nodes is resouce belonging to a Workflow job.
Returns:
WorkflowNodes: This resouce belonging to a Workflow job.
"""
url = self._data.get('related', {}).get('workflow_nodes')
return self._tower._get_object_by_url('WorkflowNodes', url) # pylint: disable=protected-access

def cancel(self):
"""Cancels the running or pending job.
Expand Down Expand Up @@ -1986,6 +1997,56 @@ def module_name(self):
"""
return self._data.get('module_name')


class WorkflowNodes(Entity):
"""Models the Workflow nodes entity of ansible tower."""


def __init__(self, tower_instance, data):
Entity.__init__(self, tower_instance, data)

@property
def count(self):
"""Number of workflow nodes.
Returns:
integer: Number of workflow nodes.
"""
return self._data.get('count')

@property
def next(self):
"""The `next` and `previous` fields provides links to
additional results if there are more than will fit on a single page.
Returns:
string: url of next page.
"""
return self._data.get('next')

@property
def previous(self):
"""The `next` and `previous` fields provides links to
additional results if there are more than will fit on a single page.
Returns:
string: url of previous page.
"""
return self._data.get('previous')

@property
def results(self):
"""Results for workflow nodes.
Returns:
list: Results for workflow nodes.
"""
return self._data.get('results')

#
# u'related': {u'activity_stream': u'/api/v2/ad_hoc_commands/4979/activity_stream/',
# u'cancel': u'/api/v2/ad_hoc_commands/4979/cancel/',
Expand Down

0 comments on commit 5a0df49

Please sign in to comment.