diff options
Diffstat (limited to 'opendc/api/v1/tiles')
| -rw-r--r-- | opendc/api/v1/tiles/tileId/endpoint.py | 8 | ||||
| -rw-r--r-- | opendc/api/v1/tiles/tileId/rack/endpoint.py | 32 | ||||
| -rw-r--r-- | opendc/api/v1/tiles/tileId/rack/machines/endpoint.py | 16 | ||||
| -rw-r--r-- | opendc/api/v1/tiles/tileId/rack/machines/position/endpoint.py | 17 |
4 files changed, 42 insertions, 31 deletions
diff --git a/opendc/api/v1/tiles/tileId/endpoint.py b/opendc/api/v1/tiles/tileId/endpoint.py index deb76195..5ccc9cd7 100644 --- a/opendc/api/v1/tiles/tileId/endpoint.py +++ b/opendc/api/v1/tiles/tileId/endpoint.py @@ -1,7 +1,8 @@ from opendc.models.tile import Tile -from opendc.util import database, exceptions +from opendc.util import exceptions from opendc.util.rest import Response + def GET(request): """Get this Tile.""" @@ -9,7 +10,7 @@ def GET(request): try: request.check_required_parameters( - path = { + path={ 'tileId': 'int' } ) @@ -41,6 +42,7 @@ def GET(request): tile.to_JSON() ) + def DELETE(request): """Delete this Tile.""" @@ -48,7 +50,7 @@ def DELETE(request): try: request.check_required_parameters( - path = { + path={ 'tileId': 'int' } ) diff --git a/opendc/api/v1/tiles/tileId/rack/endpoint.py b/opendc/api/v1/tiles/tileId/rack/endpoint.py index 59338e9a..64245856 100644 --- a/opendc/api/v1/tiles/tileId/rack/endpoint.py +++ b/opendc/api/v1/tiles/tileId/rack/endpoint.py @@ -1,8 +1,9 @@ from opendc.models.rack import Rack from opendc.models.tile import Tile -from opendc.util import database, exceptions +from opendc.util import exceptions from opendc.util.rest import Response + def GET(request): """Get this Tile's Rack.""" @@ -10,11 +11,11 @@ def GET(request): try: request.check_required_parameters( - path = { + path={ 'tileId': 'int' }, ) - + except exceptions.ParameterError as e: return Response(400, e.message) @@ -51,6 +52,7 @@ def GET(request): rack.to_JSON() ) + def POST(request): """Add a Rack to this Tile if it is empty.""" @@ -58,10 +60,10 @@ def POST(request): try: request.check_required_parameters( - path = { + path={ 'tileId': 'int' }, - body = { + body={ 'rack': { 'name': 'string', 'capacity': 'int', @@ -69,7 +71,7 @@ def POST(request): } } ) - + except exceptions.ParameterError as e: return Response(400, e.message) @@ -93,7 +95,7 @@ def POST(request): return Response(409, '{} occupied.'.format(tile)) # Instantiate a Rack and insert it into the database - + rack = Rack.from_JSON(request.params_body['rack']) rack.insert() @@ -112,7 +114,8 @@ def POST(request): 'Successfully added {}.'.format(rack), rack.to_JSON() ) - + + def PUT(request): """Update the Rack on this Tile.""" @@ -120,10 +123,10 @@ def PUT(request): try: request.check_required_parameters( - path = { + path={ 'tileId': 'int' }, - body = { + body={ 'rack': { 'name': 'string', 'capacity': 'int', @@ -131,7 +134,7 @@ def PUT(request): } } ) - + except exceptions.ParameterError as e: return Response(400, e.message) @@ -175,6 +178,7 @@ def PUT(request): rack.to_JSON() ) + def DELETE(request): """Delete this Tile's Rack.""" @@ -182,11 +186,11 @@ def DELETE(request): try: request.check_required_parameters( - path = { + path={ 'tileId': 'int' }, ) - + except exceptions.ParameterError as e: return Response(400, e.message) @@ -217,7 +221,7 @@ def DELETE(request): tile.object_id = None tile.object_type = None - + tile.update() # Delete this Rack diff --git a/opendc/api/v1/tiles/tileId/rack/machines/endpoint.py b/opendc/api/v1/tiles/tileId/rack/machines/endpoint.py index 2d160713..5272c117 100644 --- a/opendc/api/v1/tiles/tileId/rack/machines/endpoint.py +++ b/opendc/api/v1/tiles/tileId/rack/machines/endpoint.py @@ -1,8 +1,9 @@ from opendc.models.machine import Machine from opendc.models.rack import Rack -from opendc.util import database, exceptions +from opendc.util import exceptions from opendc.util.rest import Response + def GET(request): """Get this Rack's Machines.""" @@ -10,7 +11,7 @@ def GET(request): try: request.check_required_parameters( - path = { + path={ 'tileId': 'int' } ) @@ -45,6 +46,7 @@ def GET(request): [x.to_JSON() for x in machines] ) + def POST(request): """Add a Machine to this rack.""" @@ -52,10 +54,10 @@ def POST(request): try: request.check_required_parameters( - path = { + path={ 'tileId': 'int' }, - body = { + body={ 'machine': { 'rackId': 'int', 'position': 'int', @@ -91,14 +93,14 @@ def POST(request): return Response(403, 'Forbidden from viewing {}.'.format(rack)) # Instantiate a Machine - + machine = Machine.from_JSON(request.params_body['machine']) - + # Try to insert this Machine try: machine.insert() - + except exceptions.ForeignKeyError: return Response(409, 'Rack position occupied.') diff --git a/opendc/api/v1/tiles/tileId/rack/machines/position/endpoint.py b/opendc/api/v1/tiles/tileId/rack/machines/position/endpoint.py index 15e6cf96..99011fa4 100644 --- a/opendc/api/v1/tiles/tileId/rack/machines/position/endpoint.py +++ b/opendc/api/v1/tiles/tileId/rack/machines/position/endpoint.py @@ -1,8 +1,9 @@ from opendc.models.machine import Machine from opendc.models.rack import Rack -from opendc.util import database, exceptions +from opendc.util import exceptions from opendc.util.rest import Response + def GET(request): """Get the Machine at this location in this Rack.""" @@ -10,7 +11,7 @@ def GET(request): try: request.check_required_parameters( - path = { + path={ 'tileId': 'int', 'position': 'int' } @@ -43,16 +44,17 @@ def GET(request): machine.to_JSON() ) + def PUT(request): """Update the Machine at this location in this Rack.""" try: request.check_required_parameters( - path = { + path={ 'tileId': 'int', 'position': 'int' }, - body = { + body={ 'machine': { 'rackId': 'int', 'position': 'int', @@ -91,7 +93,7 @@ def PUT(request): # Update this Machine - machine.positoin = request.params_body['machine']['position'] + machine.position = request.params_body['machine']['position'] machine.tags = request.params_body['machine']['tags'] machine.cpu_ids = request.params_body['machine']['cpuIds'] machine.gpu_ids = request.params_body['machine']['gpuIds'] @@ -100,7 +102,7 @@ def PUT(request): try: machine.update() - + except exceptions.ForeignKeyError: return Response(409, 'Rack position occupied.') @@ -118,6 +120,7 @@ def PUT(request): machine.to_JSON() ) + def DELETE(request): """Delete the Machine at this location in this Rack.""" @@ -125,7 +128,7 @@ def DELETE(request): try: request.check_required_parameters( - path = { + path={ 'tileId': 'int', 'position': 'int' } |
