add /status and fix tests
This commit is contained in:
		| @@ -25,6 +25,7 @@ import wsmeext.pecan as wsme_pecan | ||||
| from teeth_agent.api.controllers.v1 import base | ||||
| from teeth_agent.api.controllers.v1 import command | ||||
| from teeth_agent.api.controllers.v1 import link | ||||
| from teeth_agent.api.controllers.v1 import status | ||||
|  | ||||
|  | ||||
| class MediaType(base.APIBase): | ||||
| @@ -53,6 +54,9 @@ class V1(base.APIBase): | ||||
|     commands = [link.Link] | ||||
|     "Links to the command resource" | ||||
|  | ||||
|     status = [link.Link] | ||||
|     "Links to the status resource" | ||||
|  | ||||
|     @classmethod | ||||
|     def convert(self): | ||||
|         v1 = V1() | ||||
| @@ -81,6 +85,17 @@ class V1(base.APIBase): | ||||
|                                 '', | ||||
|                                 bookmark=True) | ||||
|         ] | ||||
|         v1.status = [ | ||||
|             link.Link.make_link('self', | ||||
|                                 pecan.request.host_url, | ||||
|                                 'status', | ||||
|                                 ''), | ||||
|             link.Link.make_link('bookmark', | ||||
|                                 pecan.request.host_url, | ||||
|                                 'status', | ||||
|                                 '', | ||||
|                                 bookmark=True) | ||||
|         ] | ||||
|         v1.media_types = [MediaType('application/json', | ||||
|                           'application/vnd.openstack.ironic.v1+json')] | ||||
|         return v1 | ||||
| @@ -90,6 +105,7 @@ class Controller(rest.RestController): | ||||
|     """Version 1 API controller root.""" | ||||
|  | ||||
|     commands = command.CommandController() | ||||
|     status = status.StatusController() | ||||
|  | ||||
|     @wsme_pecan.wsexpose(V1) | ||||
|     def get(self): | ||||
|   | ||||
							
								
								
									
										44
									
								
								teeth_agent/api/controllers/v1/status.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								teeth_agent/api/controllers/v1/status.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,44 @@ | ||||
| # Copyright 2014 Rackspace, Inc. | ||||
| # All Rights Reserved. | ||||
| # | ||||
| #    Licensed under the Apache License, Version 2.0 (the "License"); you may | ||||
| #    not use this file except in compliance with the License. You may obtain | ||||
| #    a copy of the License at | ||||
| # | ||||
| #         http://www.apache.org/licenses/LICENSE-2.0 | ||||
| # | ||||
| #    Unless required by applicable law or agreed to in writing, software | ||||
| #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||||
| #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||||
| #    License for the specific language governing permissions and limitations | ||||
| #    under the License. | ||||
|  | ||||
| import pecan | ||||
| from pecan import rest | ||||
| from wsme import types | ||||
| from wsmeext import pecan as wsme_pecan | ||||
|  | ||||
| from teeth_agent.api.controllers.v1 import base | ||||
|  | ||||
|  | ||||
| class AgentStatus(base.APIBase): | ||||
|     mode = types.text | ||||
|     started_at = base.MultiType(float) | ||||
|     version = types.text | ||||
|  | ||||
|     @classmethod | ||||
|     def from_agent_status(cls, status): | ||||
|         instance = cls() | ||||
|         for field in ('mode', 'started_at', 'version'): | ||||
|             setattr(instance, field, getattr(status, field)) | ||||
|         return instance | ||||
|  | ||||
|  | ||||
| class StatusController(rest.RestController): | ||||
|     """Controller for getting agent status.""" | ||||
|  | ||||
|     @wsme_pecan.wsexpose(AgentStatus) | ||||
|     def get_all(self): | ||||
|         agent = pecan.request.agent | ||||
|         status = agent.get_status() | ||||
|         return AgentStatus.from_agent_status(status) | ||||
| @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and | ||||
| limitations under the License. | ||||
| """ | ||||
|  | ||||
| import collections | ||||
| import threading | ||||
| import uuid | ||||
|  | ||||
| @@ -40,7 +39,7 @@ class BaseCommandResult(encoding.Serializable): | ||||
|         self.command_error = None | ||||
|         self.command_result = None | ||||
|  | ||||
|     def serialize(self): | ||||
|     def serialize(self, view): | ||||
|         return dict(( | ||||
|             (u'id', self.id), | ||||
|             (u'command_name', self.command_name), | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jim Rollenhagen
					Jim Rollenhagen