Skip to content

Commit 61d5237

Browse files
Bamboo: Add support for agents API (atlassian-api#717)
* Bamboo: add online agents filter Signed-off-by: Martin Rakovec <martinrakovec@gmail.com> * Bamboo: Check if agent is online Signed-off-by: Martin Rakovec <martinrakovec@gmail.com> * Bamboo: Add enable/disable agent Signed-off-by: Martin Rakovec <martinrakovec@gmail.com> * Bamboo: Add agent_remote Signed-off-by: Martin Rakovec <martinrakovec@gmail.com> * Bamboo: Get agent details Signed-off-by: Martin Rakovec <martinrakovec@gmail.com> * Bamboo: Get agent's capabilitis Signed-off-by: Martin Rakovec <martinrakovec@gmail.com> * Bamboo: Fix blacks Signed-off-by: Martin Rakovec <martinrakovec@gmail.com>
1 parent 88327f3 commit 61d5237

File tree

2 files changed

+98
-6
lines changed

2 files changed

+98
-6
lines changed

atlassian/bamboo.py

+69-3
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def results(
357357
elements_key="results",
358358
element_key="result",
359359
label=label,
360-
**params
360+
**params,
361361
)
362362

363363
def latest_results(
@@ -763,8 +763,74 @@ def get_build_queue(self, expand="queuedBuilds"):
763763
def server_info(self):
764764
return self.get(self.resource_url("info"))
765765

766-
def agent_status(self):
767-
return self.get(self.resource_url("agent"))
766+
def agent_status(self, online=False):
767+
"""
768+
Provides a list of all agents.
769+
770+
:param online: filter only online agents (default False = all)
771+
:return:
772+
"""
773+
return self.get(self.resource_url("agent"), params={"online": online})
774+
775+
def agent_is_online(self, agent_id):
776+
"""
777+
Get agent online status.
778+
779+
:param agent_id: Bamboo agent ID (integer number)
780+
:return: True/False
781+
"""
782+
response = self.get(self.resource_url(f"agent/{agent_id}/status"))
783+
return response["online"]
784+
785+
def agent_enable(self, agent_id):
786+
"""
787+
Enable agent
788+
789+
:param agent_id: Bamboo agent ID (integer number)
790+
:return: None
791+
"""
792+
self.put(self.resource_url(f"agent/{agent_id}/enable"))
793+
794+
def agent_disable(self, agent_id):
795+
"""
796+
Disable agent
797+
798+
:param agent_id: Bamboo agent ID (integer number)
799+
:return: None
800+
"""
801+
self.put(self.resource_url(f"agent/{agent_id}/disable"))
802+
803+
def agent_remote(self, online=False):
804+
"""
805+
Provides a list of all agent authentication statuses.
806+
807+
:param online: list only online agents (default False = all)
808+
:return: list of agent-describing dictionaries
809+
"""
810+
return self.get(self.resource_url("agent/remote"), params={"online": online})
811+
812+
def agent_details(self, agent_id, expand=None):
813+
"""
814+
Provides details of an agent with given id.
815+
816+
:param agent_id: Bamboo agent ID (integer number)
817+
:param expand: Expand fields (None, capabilities, executableEnvironments, executableJobs)
818+
:return:
819+
"""
820+
params = None
821+
if expand:
822+
params = {"expand": expand}
823+
return self.get(self.resource_url(f"agent/{agent_id}"), params=params)
824+
825+
def agent_capabilities(self, agent_id, include_shared=True):
826+
"""
827+
List agent's capabilities.
828+
829+
:param agent_id: Bamboo agent ID (integer number)
830+
:param include_shared: Include shared capabilities
831+
:return: agents
832+
"""
833+
return self.get(self.resource_url(f"agent/{agent_id}/capability"), params={"includeShared": include_shared})
768834

769835
def activity(self):
770836
return self.get("build/admin/ajax/getDashboardSummary.action")

docs/bamboo.rst

+29-3
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,35 @@ Users & Groups
152152
# Get users without Group
153153
get_users_not_in_group(group_name, filter_users='', start=0, limit=25)
154154
155+
Agents
156+
------
157+
158+
.. code-block:: python
159+
160+
# Get agents statuses
161+
agent_status(online=False)
162+
163+
# Get remote agents. Currently (version 7.2.2) output is the same as for
164+
# agent_status but uses different API
165+
agent_remote(online=False)
166+
167+
# Check if agent is online
168+
agent_is_online(agent_id=123456)
169+
170+
# Enable agent
171+
agent_enable(agent_id=123456)
172+
173+
# Disable agent
174+
agent_enable(agent_id=123456)
175+
176+
# Get agent details
177+
agent_details(agent_id=123456)
178+
agent_details(agent_id=123456, expand="capabilities,executableEnvironments,executableJobs")
179+
180+
# Get agent capabilities
181+
agent_capabilities(agent_id=123456):
182+
agent_capabilities(agent_id=123456, include_shared=False):
183+
155184
Other actions
156185
-------------
157186

@@ -163,9 +192,6 @@ Other actions
163192
# Get server information
164193
server_info()
165194
166-
# Get agents statuses
167-
agent_status()
168-
169195
# Get activity
170196
activity()
171197

0 commit comments

Comments
 (0)