add BaseAgent methods to retrieve and list results

This commit is contained in:
Russell Haering 2014-01-09 13:43:04 -08:00
parent f01b8a62ad
commit d6ddc267b3
2 changed files with 18 additions and 1 deletions
teeth_agent

@ -188,7 +188,7 @@ class BaseTeethAgent(object):
self.mode = mode
self.version = pkg_resources.get_distribution('teeth-agent').version
self.api = api.TeethAgentAPIServer(self)
self.command_results = {}
self.command_results = collections.OrderedDict()
self.command_map = {}
self.heartbeater = TeethAgentHeartbeater(self)
self.hardware = hardware.HardwareInspector()
@ -210,6 +210,16 @@ class BaseTeethAgent(object):
def get_agent_mac_addr(self):
return self.hardware.get_primary_mac_address()
def list_command_results(self):
return self.command_results.values()
def get_command_result(self, result_id):
try:
return self.command_results[result_id]
except KeyError:
raise errors.RequestedObjectNotFoundError('Command Result',
result_id)
def execute_command(self, command_name, **kwargs):
"""Execute an agent command."""
if command_name not in self.command_map:

@ -46,6 +46,13 @@ class InvalidCommandParamsError(errors.InvalidContentError):
super(InvalidCommandParamsError, self).__init__(details)
class RequestedObjectNotFoundError(errors.NotFound):
def __init__(self, type_descr, obj_id):
details = '{} with id {} not found.'.format(type_descr, obj_id)
super(RequestedObjectNotFoundError, self).__init__(details)
self.details = details
class HeartbeatError(errors.RESTError):
"""Error raised when a heartbeat to the agent API fails."""