Skip to content

Commit a524db8

Browse files
Add docstrings for api/ tree
Does what it says. Partial-Bug 1367915 Change-Id: Id1a718d652f6d98e6acb1d667f42d9c3cc82aef5
1 parent cdd9839 commit a524db8

3 files changed

Lines changed: 59 additions & 3 deletions

File tree

ironic_python_agent/api/app.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020

2121
class AgentHook(hooks.PecanHook):
22+
"""Hook to attach agent instance to API requests."""
2223
def __init__(self, agent, *args, **kwargs):
2324
super(AgentHook, self).__init__(*args, **kwargs)
2425
self.agent = agent
@@ -28,12 +29,22 @@ def before(self, state):
2829

2930

3031
def get_pecan_config():
31-
# Set up the pecan configuration
32+
"""Set up the pecan configuration.
33+
34+
:returns: pecan configuration object.
35+
"""
3236
filename = config.__file__.replace('.pyc', '.py')
3337
return pecan.configuration.conf_from_file(filename)
3438

3539

36-
def setup_app(pecan_config=None, extra_hooks=None, agent=None):
40+
def setup_app(pecan_config=None, agent=None):
41+
"""Set up the API app.
42+
43+
:param pecan_config: a pecan configuration object.
44+
:param agent: an :class:`ironic_python_agent.agent.IronicPythonAgent`
45+
instance.
46+
:returns: wsgi app object.
47+
"""
3748
app_hooks = [AgentHook(agent)]
3849

3950
if not pecan_config:
@@ -53,6 +64,8 @@ def setup_app(pecan_config=None, extra_hooks=None, agent=None):
5364

5465

5566
class VersionSelectorApplication(object):
67+
"""WSGI application that handles multiple API versions."""
68+
5669
def __init__(self, agent):
5770
pc = get_pecan_config()
5871
self.v1 = setup_app(pecan_config=pc, agent=agent)

ironic_python_agent/api/controllers/v1/command.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323

2424
class CommandResult(base.APIBase):
25+
"""Object representing the result of a given command."""
26+
2527
id = types.text
2628
command_name = types.text
2729
command_params = types.DictType(types.text, base.json_type)
@@ -31,6 +33,13 @@ class CommandResult(base.APIBase):
3133

3234
@classmethod
3335
def from_result(cls, result):
36+
"""Convert a BaseCommandResult object to a CommandResult object.
37+
38+
:param result: a :class:`ironic_python_agent.extensions.base.
39+
BaseCommandResult` object.
40+
:returns: a :class:`ironic_python_agent.api.controllers.v1.command.
41+
CommandResult` object.
42+
"""
3443
instance = cls()
3544
for field in ('id', 'command_name', 'command_params', 'command_status',
3645
'command_error', 'command_result'):
@@ -39,18 +48,26 @@ def from_result(cls, result):
3948

4049

4150
class CommandResultList(base.APIBase):
51+
"""An object representing a list of CommandResult objects."""
4252
commands = [CommandResult]
4353

4454
@classmethod
4555
def from_results(cls, results):
56+
"""Convert a list of BaseCommandResult objects to a CommandResultList.
57+
58+
:param results: a list of :class:`ironic_python_agent.extensions.base.
59+
BaseCommandResult` objects.
60+
:returns: a :class:`ironic_python_agent.api.controllers.v1.command.
61+
CommandResultList` object.
62+
"""
4663
instance = cls()
4764
instance.commands = [CommandResult.from_result(result)
4865
for result in results]
4966
return instance
5067

5168

5269
class Command(base.APIBase):
53-
"""A command representation."""
70+
"""A representation of a command."""
5471
name = types.wsattr(types.text, mandatory=True)
5572
params = types.wsattr(base.MultiType(dict), mandatory=True)
5673

@@ -60,12 +77,20 @@ class CommandController(rest.RestController):
6077

6178
@wsme_pecan.wsexpose(CommandResultList)
6279
def get_all(self):
80+
"""Get all command results."""
6381
agent = pecan.request.agent
6482
results = agent.list_command_results()
6583
return CommandResultList.from_results(results)
6684

6785
@wsme_pecan.wsexpose(CommandResult, types.text, types.text)
6886
def get_one(self, result_id, wait=None):
87+
"""Get a command result by ID.
88+
89+
:param result_id: the ID of the result to get.
90+
:param wait: if 'true', block until the command completes.
91+
:returns: a :class:`ironic_python_agent.api.controller.v1.command.
92+
CommandResult` object.
93+
"""
6994
agent = pecan.request.agent
7095
result = agent.get_command_result(result_id)
7196

@@ -76,6 +101,14 @@ def get_one(self, result_id, wait=None):
76101

77102
@wsme_pecan.wsexpose(CommandResult, types.text, body=Command)
78103
def post(self, wait=None, command=None):
104+
"""Post a command for the agent to run.
105+
106+
:param wait: if 'true', block until the command completes.
107+
:param command: the command to execute. If None, an InvalidCommandError
108+
will be returned.
109+
:returns: a :class:`ironic_python_agent.api.controller.v1.command.
110+
CommandResult` object.
111+
"""
79112
# the POST body is always the last arg,
80113
# so command must be a kwarg here
81114
if command is None:

ironic_python_agent/api/controllers/v1/status.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,20 @@
2222

2323

2424
class AgentStatus(base.APIBase):
25+
"""An object representing an agent instance's status."""
26+
2527
started_at = base.MultiType(float)
2628
version = types.text
2729

2830
@classmethod
2931
def from_agent_status(cls, status):
32+
"""Convert an object representing agent status to an AgentStatus.
33+
34+
:param status: An :class:`ironic_python_agent.agent.
35+
IronicPythonAgentStatus` object.
36+
:returns: An :class:`ironic_python_agent.api.controllers.v1.status.
37+
AgentStatus` object.
38+
"""
3039
instance = cls()
3140
for field in ('started_at', 'version'):
3241
setattr(instance, field, getattr(status, field))
@@ -38,6 +47,7 @@ class StatusController(rest.RestController):
3847

3948
@wsme_pecan.wsexpose(AgentStatus)
4049
def get_all(self):
50+
"""Get current status of the running agent."""
4151
agent = pecan.request.agent
4252
status = agent.get_status()
4353
return AgentStatus.from_agent_status(status)

0 commit comments

Comments
 (0)