diff options
Diffstat (limited to 'opendc/api')
47 files changed, 313 insertions, 879 deletions
diff --git a/opendc/api/v2/datacenters/datacenterId/endpoint.py b/opendc/api/v2/datacenters/datacenterId/endpoint.py index 9444fb80..14dbbd2a 100644 --- a/opendc/api/v2/datacenters/datacenterId/endpoint.py +++ b/opendc/api/v2/datacenters/datacenterId/endpoint.py @@ -9,18 +9,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'datacenterId': 'int' - } - ) + request.check_required_parameters(path={'datacenterId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Datacenter from the database - datacenter = Datacenter.from_primary_key((request.params_path['datacenterId'],)) + datacenter = Datacenter.from_primary_key((request.params_path['datacenterId'], )) # Make sure this Datacenter exists @@ -36,8 +32,4 @@ def GET(request): datacenter.read() - return Response( - 200, - 'Successfully retrieved {}.'.format(datacenter), - datacenter.to_JSON() - ) + return Response(200, 'Successfully retrieved {}.'.format(datacenter), datacenter.to_JSON()) diff --git a/opendc/api/v2/datacenters/datacenterId/rooms/endpoint.py b/opendc/api/v2/datacenters/datacenterId/rooms/endpoint.py index e0155c7c..2cca01fd 100644 --- a/opendc/api/v2/datacenters/datacenterId/rooms/endpoint.py +++ b/opendc/api/v2/datacenters/datacenterId/rooms/endpoint.py @@ -10,17 +10,13 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'datacenterId': 'int' - } - ) + request.check_required_parameters(path={'datacenterId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Datacenter from the database - datacenter = Datacenter.from_primary_key((request.params_path['datacenterId'],)) + datacenter = Datacenter.from_primary_key((request.params_path['datacenterId'], )) # Make sure this Datacenter exists @@ -36,11 +32,7 @@ def GET(request): rooms = Room.query('datacenter_id', datacenter.id) - return Response( - 200, - 'Successfully retrieved Rooms for {}.'.format(datacenter), - [x.to_JSON() for x in rooms] - ) + return Response(200, 'Successfully retrieved Rooms for {}.'.format(datacenter), [x.to_JSON() for x in rooms]) def POST(request): @@ -49,18 +41,12 @@ def POST(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'datacenterId': 'int' - }, - body={ - 'room': { - 'id': 'int', - 'datacenterId': 'int', - 'roomType': 'string' - } - } - ) + request.check_required_parameters(path={'datacenterId': 'int'}, + body={'room': { + 'id': 'int', + 'datacenterId': 'int', + 'roomType': 'string' + }}) except exceptions.ParameterError as e: return Response(400, e.message) @@ -71,7 +57,7 @@ def POST(request): # Instantiate a Datacenter from the database - datacenter = Datacenter.from_primary_key((request.params_path['datacenterId'],)) + datacenter = Datacenter.from_primary_key((request.params_path['datacenterId'], )) # Make sure this Datacenter exists @@ -104,8 +90,4 @@ def POST(request): room.read() - return Response( - 200, - 'Successfully added {}.'.format(room), - room.to_JSON() - ) + return Response(200, 'Successfully added {}.'.format(room), room.to_JSON()) diff --git a/opendc/api/v2/experiments/experimentId/endpoint.py b/opendc/api/v2/experiments/experimentId/endpoint.py index 59e0e0fe..a306e441 100644 --- a/opendc/api/v2/experiments/experimentId/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/endpoint.py @@ -7,18 +7,14 @@ def GET(request): """Get this Experiment.""" try: - request.check_required_parameters( - path={ - 'experimentId': 'int' - } - ) + request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate an Experiment from the database - experiment = Experiment.from_primary_key((request.params_path['experimentId'],)) + experiment = Experiment.from_primary_key((request.params_path['experimentId'], )) # Make sure this Experiment exists @@ -34,11 +30,7 @@ def GET(request): experiment.read() - return Response( - 200, - 'Successfully retrieved {}.'.format(experiment), - experiment.to_JSON() - ) + return Response(200, 'Successfully retrieved {}.'.format(experiment), experiment.to_JSON()) def PUT(request): @@ -48,25 +40,20 @@ def PUT(request): try: request.check_required_parameters( - path={ - 'experimentId': 'int' - }, - body={ - 'experiment': { - 'pathId': 'int', - 'traceId': 'int', - 'schedulerName': 'string', - 'name': 'string' - } - } - ) + path={'experimentId': 'int'}, + body={'experiment': { + 'pathId': 'int', + 'traceId': 'int', + 'schedulerName': 'string', + 'name': 'string' + }}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate an Experiment from the database - experiment = Experiment.from_primary_key((request.params_path['experimentId'],)) + experiment = Experiment.from_primary_key((request.params_path['experimentId'], )) # Make sure this Experiment exists @@ -93,11 +80,7 @@ def PUT(request): # Return this Experiment - return Response( - 200, - 'Successfully updated {}.'.format(experiment), - experiment.to_JSON() - ) + return Response(200, 'Successfully updated {}.'.format(experiment), experiment.to_JSON()) def DELETE(request): @@ -106,18 +89,14 @@ def DELETE(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'experimentId': 'int' - } - ) + request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate an Experiment and make sure it exists - experiment = Experiment.from_primary_key((request.params_path['experimentId'],)) + experiment = Experiment.from_primary_key((request.params_path['experimentId'], )) if not experiment.exists(): return Response(404, '{} not found.'.format(experiment)) @@ -131,8 +110,4 @@ def DELETE(request): experiment.delete() - return Response( - 200, - 'Successfully deleted {}.'.format(experiment), - experiment.to_JSON() - ) + return Response(200, 'Successfully deleted {}.'.format(experiment), experiment.to_JSON()) diff --git a/opendc/api/v2/experiments/experimentId/last-simulated-tick/endpoint.py b/opendc/api/v2/experiments/experimentId/last-simulated-tick/endpoint.py index b4b19f59..f96c90ff 100644 --- a/opendc/api/v2/experiments/experimentId/last-simulated-tick/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/last-simulated-tick/endpoint.py @@ -9,18 +9,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'experimentId': 'int' - } - ) + request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate an Experiment from the database - experiment = Experiment.from_primary_key((request.params_path['experimentId'],)) + experiment = Experiment.from_primary_key((request.params_path['experimentId'], )) # Make sure this Experiment exists @@ -32,8 +28,5 @@ def GET(request): if not experiment.google_id_has_at_least(request.google_id, 'VIEW'): return Response(403, 'Forbidden from viewing last simulated tick for {}.'.format(experiment)) - return Response( - 200, - 'Successfully retrieved last simulated tick for {}.'.format(experiment), - {'lastSimulatedTick': experiment.last_simulated_tick} - ) + return Response(200, 'Successfully retrieved last simulated tick for {}.'.format(experiment), + {'lastSimulatedTick': experiment.last_simulated_tick}) diff --git a/opendc/api/v2/experiments/experimentId/machine-states/endpoint.py b/opendc/api/v2/experiments/experimentId/machine-states/endpoint.py index 8ad588d2..5f586896 100644 --- a/opendc/api/v2/experiments/experimentId/machine-states/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/machine-states/endpoint.py @@ -10,18 +10,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'experimentId': 'int' - } - ) + request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate an Experiment from the database - experiment = Experiment.from_primary_key((request.params_path['experimentId'],)) + experiment = Experiment.from_primary_key((request.params_path['experimentId'], )) # Make sure this Experiment exists @@ -36,16 +32,11 @@ def GET(request): # Get and return the Machine States if 'tick' in request.params_query: - machine_states = MachineState.from_experiment_id_and_tick( - request.params_path['experimentId'], - request.params_query['tick'] - ) + machine_states = MachineState.from_experiment_id_and_tick(request.params_path['experimentId'], + request.params_query['tick']) else: machine_states = MachineState.from_experiment_id(request.params_path['experimentId']) - return Response( - 200, - 'Successfully retrieved Machine States for {}.'.format(experiment), - [x.to_JSON() for x in machine_states] - ) + return Response(200, 'Successfully retrieved Machine States for {}.'.format(experiment), + [x.to_JSON() for x in machine_states]) diff --git a/opendc/api/v2/experiments/experimentId/rack-states/endpoint.py b/opendc/api/v2/experiments/experimentId/rack-states/endpoint.py index 03570039..54b2fd8a 100644 --- a/opendc/api/v2/experiments/experimentId/rack-states/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/rack-states/endpoint.py @@ -10,18 +10,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'experimentId': 'int' - } - ) + request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate an Experiment from the database - experiment = Experiment.from_primary_key((request.params_path['experimentId'],)) + experiment = Experiment.from_primary_key((request.params_path['experimentId'], )) # Make sure this Experiment exists @@ -36,16 +32,11 @@ def GET(request): # Get and return the Rack States if 'tick' in request.params_query: - rack_states = RackState.from_experiment_id_and_tick( - request.params_path['experimentId'], - request.params_query['tick'] - ) + rack_states = RackState.from_experiment_id_and_tick(request.params_path['experimentId'], + request.params_query['tick']) else: rack_states = RackState.from_experiment_id(request.params_path['experimentId']) - return Response( - 200, - 'Successfully retrieved Rack States for {}.'.format(experiment), - [x.to_JSON() for x in rack_states] - ) + return Response(200, 'Successfully retrieved Rack States for {}.'.format(experiment), + [x.to_JSON() for x in rack_states]) diff --git a/opendc/api/v2/experiments/experimentId/room-states/endpoint.py b/opendc/api/v2/experiments/experimentId/room-states/endpoint.py index 2693dc89..9b1e0a68 100644 --- a/opendc/api/v2/experiments/experimentId/room-states/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/room-states/endpoint.py @@ -10,18 +10,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'experimentId': 'int' - } - ) + request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate an Experiment from the database - experiment = Experiment.from_primary_key((request.params_path['experimentId'],)) + experiment = Experiment.from_primary_key((request.params_path['experimentId'], )) # Make sure this Experiment exists @@ -36,16 +32,11 @@ def GET(request): # Get and return the Room States if 'tick' in request.params_query: - room_states = RoomState.from_experiment_id_and_tick( - request.params_path['experimentId'], - request.params_query['tick'] - ) + room_states = RoomState.from_experiment_id_and_tick(request.params_path['experimentId'], + request.params_query['tick']) else: room_states = RoomState.from_experiment_id(request.params_path['experimentId']) - return Response( - 200, - 'Successfully retrieved Room States for {}.'.format(experiment), - [x.to_JSON() for x in room_states] - ) + return Response(200, 'Successfully retrieved Room States for {}.'.format(experiment), + [x.to_JSON() for x in room_states]) diff --git a/opendc/api/v2/experiments/experimentId/statistics/task-durations/endpoint.py b/opendc/api/v2/experiments/experimentId/statistics/task-durations/endpoint.py index b8311f08..fe62f7f6 100644 --- a/opendc/api/v2/experiments/experimentId/statistics/task-durations/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/statistics/task-durations/endpoint.py @@ -10,18 +10,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'experimentId': 'int' - } - ) + request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate an Experiment from the database - experiment = Experiment.from_primary_key((request.params_path['experimentId'],)) + experiment = Experiment.from_primary_key((request.params_path['experimentId'], )) # Make sure this Experiment exists @@ -37,8 +33,5 @@ def GET(request): task_durations = TaskDuration.from_experiment_id(request.params_path['experimentId']) - return Response( - 200, - 'Successfully retrieved Task Durations for {}.'.format(experiment), - [x.to_JSON() for x in task_durations] - ) + return Response(200, 'Successfully retrieved Task Durations for {}.'.format(experiment), + [x.to_JSON() for x in task_durations]) diff --git a/opendc/api/v2/experiments/experimentId/task-states/endpoint.py b/opendc/api/v2/experiments/experimentId/task-states/endpoint.py index 0c3fae89..3f6ce4a7 100644 --- a/opendc/api/v2/experiments/experimentId/task-states/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/task-states/endpoint.py @@ -10,18 +10,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'experimentId': 'int' - } - ) + request.check_required_parameters(path={'experimentId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate an Experiment from the database - experiment = Experiment.from_primary_key((request.params_path['experimentId'],)) + experiment = Experiment.from_primary_key((request.params_path['experimentId'], )) # Make sure this Experiment exists @@ -36,16 +32,11 @@ def GET(request): # Get and return the Task States if 'tick' in request.params_query: - task_states = TaskState.from_experiment_id_and_tick( - request.params_path['experimentId'], - request.params_query['tick'] - ) + task_states = TaskState.from_experiment_id_and_tick(request.params_path['experimentId'], + request.params_query['tick']) else: task_states = TaskState.query('experiment_id', request.params_path['experimentId']) - return Response( - 200, - 'Successfully retrieved Task States for {}.'.format(experiment), - [x.to_JSON() for x in task_states] - ) + return Response(200, 'Successfully retrieved Task States for {}.'.format(experiment), + [x.to_JSON() for x in task_states]) diff --git a/opendc/api/v2/jobs/jobId/endpoint.py b/opendc/api/v2/jobs/jobId/endpoint.py index da4dcd9d..c24b04d0 100644 --- a/opendc/api/v2/jobs/jobId/endpoint.py +++ b/opendc/api/v2/jobs/jobId/endpoint.py @@ -9,26 +9,18 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'jobId': 'int' - } - ) + request.check_required_parameters(path={'jobId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Job and make sure it exists - job = Job.from_primary_key((request.params_path['jobId'],)) + job = Job.from_primary_key((request.params_path['jobId'], )) if not job.exists(): return Response(404, '{} not found.'.format(job)) # Return this Job - return Response( - 200, - 'Successfully retrieved {}.'.format(job), - job.to_JSON() - ) + return Response(200, 'Successfully retrieved {}.'.format(job), job.to_JSON()) diff --git a/opendc/api/v2/jobs/jobId/tasks/endpoint.py b/opendc/api/v2/jobs/jobId/tasks/endpoint.py index 04ac5b8c..d412df00 100644 --- a/opendc/api/v2/jobs/jobId/tasks/endpoint.py +++ b/opendc/api/v2/jobs/jobId/tasks/endpoint.py @@ -10,18 +10,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'jobId': 'int' - } - ) + request.check_required_parameters(path={'jobId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Job and make sure it exists - job = Job.from_primary_key((request.params_path['jobId'],)) + job = Job.from_primary_key((request.params_path['jobId'], )) if not job.exists(): return Response(404, '{} not found.'.format(job)) @@ -30,8 +26,4 @@ def GET(request): tasks = Task.query('job_id', request.params_path['jobId']) - return Response( - 200, - 'Successfully retrieved Tasks for {}.'.format(job), - [x.to_JSON() for x in tasks] - ) + return Response(200, 'Successfully retrieved Tasks for {}.'.format(job), [x.to_JSON() for x in tasks]) diff --git a/opendc/api/v2/paths/pathId/branches/endpoint.py b/opendc/api/v2/paths/pathId/branches/endpoint.py index 13638ffa..5d3b6ec1 100644 --- a/opendc/api/v2/paths/pathId/branches/endpoint.py +++ b/opendc/api/v2/paths/pathId/branches/endpoint.py @@ -18,23 +18,14 @@ def POST(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'pathId': 'int' - }, - body={ - 'section': { - 'startTick': 'int' - } - } - ) + request.check_required_parameters(path={'pathId': 'int'}, body={'section': {'startTick': 'int'}}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate the current Path from the database - current_path = Path.from_primary_key((request.params_path['pathId'],)) + current_path = Path.from_primary_key((request.params_path['pathId'], )) # Make sure the current Path exists @@ -48,10 +39,8 @@ def POST(request): # Create the new Path - new_path = Path( - simulation_id=current_path.simulation_id, - datetime_created=database.datetime_to_string(datetime.now()) - ) + new_path = Path(simulation_id=current_path.simulation_id, + datetime_created=database.datetime_to_string(datetime.now())) new_path.insert() @@ -63,11 +52,9 @@ def POST(request): for current_section in current_sections: if current_section.start_tick < request.params_body['section']['startTick'] or current_section.start_tick == 0: - new_section = Section( - path_id=new_path.id, - datacenter_id=current_section.datacenter_id, - start_tick=current_section.start_tick - ) + new_section = Section(path_id=new_path.id, + datacenter_id=current_section.datacenter_id, + start_tick=current_section.start_tick) new_section.insert() @@ -75,13 +62,11 @@ def POST(request): # Make a deep copy of the last section's datacenter, its rooms, their tiles, etc. - path_parameters = { - 'simulationId': new_path.simulation_id - } + path_parameters = {'simulationId': new_path.simulation_id} # Copy the Datacenter - old_datacenter = Datacenter.from_primary_key((last_section.datacenter_id,)) + old_datacenter = Datacenter.from_primary_key((last_section.datacenter_id, )) message = old_datacenter.generate_api_call(path_parameters, request.token) response = Request(message).process() @@ -91,11 +76,9 @@ def POST(request): # Create the new last Section, with the IDs of the new Path and new Datacenter if last_section.start_tick != 0: - new_section = Section( - path_id=new_path.id, - datacenter_id=path_parameters['datacenterId'], - start_tick=request.params_body['section']['startTick'] - ) + new_section = Section(path_id=new_path.id, + datacenter_id=path_parameters['datacenterId'], + start_tick=request.params_body['section']['startTick']) new_section.insert() @@ -169,8 +152,4 @@ def POST(request): # Return the new Path - return Response( - 200, - 'Successfully created {}.'.format(new_path), - new_path.to_JSON() - ) + return Response(200, 'Successfully created {}.'.format(new_path), new_path.to_JSON()) diff --git a/opendc/api/v2/paths/pathId/endpoint.py b/opendc/api/v2/paths/pathId/endpoint.py index 7ade19ce..7a73ce17 100644 --- a/opendc/api/v2/paths/pathId/endpoint.py +++ b/opendc/api/v2/paths/pathId/endpoint.py @@ -9,18 +9,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'pathId': 'int' - } - ) + request.check_required_parameters(path={'pathId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Path from the database - path = Path.from_primary_key((request.params_path['pathId'],)) + path = Path.from_primary_key((request.params_path['pathId'], )) # Make sure this Path exists @@ -36,8 +32,4 @@ def GET(request): path.read() - return Response( - 200, - 'Successfully retrieved {}.'.format(path), - path.to_JSON() - ) + return Response(200, 'Successfully retrieved {}.'.format(path), path.to_JSON()) diff --git a/opendc/api/v2/paths/pathId/sections/endpoint.py b/opendc/api/v2/paths/pathId/sections/endpoint.py index d4161839..b8e4a861 100644 --- a/opendc/api/v2/paths/pathId/sections/endpoint.py +++ b/opendc/api/v2/paths/pathId/sections/endpoint.py @@ -10,17 +10,13 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'pathId': 'int' - } - ) + request.check_required_parameters(path={'pathId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Path from the database - path = Path.from_primary_key((request.params_path['pathId'],)) + path = Path.from_primary_key((request.params_path['pathId'], )) # Make sure this Path exists @@ -36,8 +32,4 @@ def GET(request): sections = Section.query('path_id', request.params_path['pathId']) - return Response( - 200, - 'Successfully retrieved Sections for {}.'.format(path), - [x.to_JSON() for x in sections] - ) + return Response(200, 'Successfully retrieved Sections for {}.'.format(path), [x.to_JSON() for x in sections]) diff --git a/opendc/api/v2/room-types/endpoint.py b/opendc/api/v2/room-types/endpoint.py index fe00f226..14675c86 100644 --- a/opendc/api/v2/room-types/endpoint.py +++ b/opendc/api/v2/room-types/endpoint.py @@ -11,8 +11,4 @@ def GET(request): # Return the RoomTypes - return Response( - 200, - 'Successfully retrieved RoomTypes.', - [x.to_JSON() for x in room_types] - ) + return Response(200, 'Successfully retrieved RoomTypes.', [x.to_JSON() for x in room_types]) diff --git a/opendc/api/v2/room-types/name/allowed-objects/endpoint.py b/opendc/api/v2/room-types/name/allowed-objects/endpoint.py index a574591c..9cc0dbca 100644 --- a/opendc/api/v2/room-types/name/allowed-objects/endpoint.py +++ b/opendc/api/v2/room-types/name/allowed-objects/endpoint.py @@ -9,11 +9,7 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'name': 'string' - } - ) + request.check_required_parameters(path={'name': 'string'}) except exceptions.ParameterError as e: return Response(400, e.message) @@ -24,8 +20,4 @@ def GET(request): # Return the AllowedObjects - return Response( - 200, - 'Successfully retrieved AllowedObjects.', - [x.to_JSON() for x in allowed_objects] - ) + return Response(200, 'Successfully retrieved AllowedObjects.', [x.to_JSON() for x in allowed_objects]) diff --git a/opendc/api/v2/rooms/roomId/endpoint.py b/opendc/api/v2/rooms/roomId/endpoint.py index 1dfc32cc..a43a82e7 100644 --- a/opendc/api/v2/rooms/roomId/endpoint.py +++ b/opendc/api/v2/rooms/roomId/endpoint.py @@ -9,18 +9,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'roomId': 'int' - } - ) + request.check_required_parameters(path={'roomId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Room from the database - room = Room.from_primary_key((request.params_path['roomId'],)) + room = Room.from_primary_key((request.params_path['roomId'], )) # Make sure this Room exists @@ -36,11 +32,7 @@ def GET(request): room.read() - return Response( - 200, - 'Successfully retrieved {}.'.format(room), - room.to_JSON() - ) + return Response(200, 'Successfully retrieved {}.'.format(room), room.to_JSON()) def PUT(request): @@ -49,24 +41,18 @@ def PUT(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'roomId': 'int' - }, - body={ - 'room': { - 'name': 'string', - 'roomType': 'string' - } - } - ) + request.check_required_parameters(path={'roomId': 'int'}, + body={'room': { + 'name': 'string', + 'roomType': 'string' + }}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Room from the database - room = Room.from_primary_key((request.params_path['roomId'],)) + room = Room.from_primary_key((request.params_path['roomId'], )) # Make sure this Room exists @@ -90,11 +76,7 @@ def PUT(request): # Return this Room - return Response( - 200, - 'Successfully updated {}.'.format(room), - room.to_JSON() - ) + return Response(200, 'Successfully updated {}.'.format(room), room.to_JSON()) def DELETE(request): @@ -103,18 +85,14 @@ def DELETE(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'roomId': 'int' - } - ) + request.check_required_parameters(path={'roomId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Room and make sure it exists - room = Room.from_primary_key((request.params_path['roomId'],)) + room = Room.from_primary_key((request.params_path['roomId'], )) if not room.exists(): return Response(404, '{} not found.'.format(room)) @@ -130,8 +108,4 @@ def DELETE(request): # Return this Room - return Response( - 200, - 'Successfully deleted {}.'.format(room), - room.to_JSON() - ) + return Response(200, 'Successfully deleted {}.'.format(room), room.to_JSON()) diff --git a/opendc/api/v2/rooms/roomId/tiles/endpoint.py b/opendc/api/v2/rooms/roomId/tiles/endpoint.py index a4ef51e7..6e498a48 100644 --- a/opendc/api/v2/rooms/roomId/tiles/endpoint.py +++ b/opendc/api/v2/rooms/roomId/tiles/endpoint.py @@ -10,18 +10,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'roomId': 'int' - } - ) + request.check_required_parameters(path={'roomId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Room from the database - room = Room.from_primary_key((request.params_path['roomId'],)) + room = Room.from_primary_key((request.params_path['roomId'], )) # Make sure this Room exists @@ -40,11 +36,7 @@ def GET(request): for tile in tiles: tile.read() - return Response( - 200, - 'Successfully retrieved Tiles for {}.'.format(room), - [x.to_JSON() for x in tiles] - ) + return Response(200, 'Successfully retrieved Tiles for {}.'.format(room), [x.to_JSON() for x in tiles]) def POST(request): @@ -53,18 +45,12 @@ def POST(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'roomId': 'int' - }, - body={ - 'tile': { - 'roomId': 'int', - 'positionX': 'int', - 'positionY': 'int' - } - } - ) + request.check_required_parameters(path={'roomId': 'int'}, + body={'tile': { + 'roomId': 'int', + 'positionX': 'int', + 'positionY': 'int' + }}) except exceptions.ParameterError as e: return Response(400, e.message) @@ -74,7 +60,7 @@ def POST(request): # Instantiate a Room from the database - room = Room.from_primary_key((request.params_path['roomId'],)) + room = Room.from_primary_key((request.params_path['roomId'], )) # Make sure this Room exists @@ -114,8 +100,4 @@ def POST(request): tile.read() - return Response( - 200, - 'Successfully added {}.'.format(tile), - tile.to_JSON() - ) + return Response(200, 'Successfully added {}.'.format(tile), tile.to_JSON()) diff --git a/opendc/api/v2/schedulers/endpoint.py b/opendc/api/v2/schedulers/endpoint.py index 36537764..224ecfb8 100644 --- a/opendc/api/v2/schedulers/endpoint.py +++ b/opendc/api/v2/schedulers/endpoint.py @@ -11,8 +11,4 @@ def GET(request): # Return the Schedulers - return Response( - 200, - 'Successfully retrieved Schedulers.', - [x.to_JSON() for x in schedulers] - ) + return Response(200, 'Successfully retrieved Schedulers.', [x.to_JSON() for x in schedulers]) diff --git a/opendc/api/v2/sections/sectionId/endpoint.py b/opendc/api/v2/sections/sectionId/endpoint.py index 94c81d37..0cda37bf 100644 --- a/opendc/api/v2/sections/sectionId/endpoint.py +++ b/opendc/api/v2/sections/sectionId/endpoint.py @@ -9,17 +9,13 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'sectionId': 'int' - } - ) + request.check_required_parameters(path={'sectionId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Section from the database - section = Section.from_primary_key((request.params_path['sectionId'],)) + section = Section.from_primary_key((request.params_path['sectionId'], )) # Make sure this Section exists @@ -35,8 +31,4 @@ def GET(request): section.read() - return Response( - 200, - 'Successfully retrieved {}.'.format(section), - section.to_JSON() - ) + return Response(200, 'Successfully retrieved {}.'.format(section), section.to_JSON()) diff --git a/opendc/api/v2/simulations/endpoint.py b/opendc/api/v2/simulations/endpoint.py index a8637728..72501379 100644 --- a/opendc/api/v2/simulations/endpoint.py +++ b/opendc/api/v2/simulations/endpoint.py @@ -16,13 +16,7 @@ def POST(request): # Make sure required parameters are there try: - request.check_required_parameters( - body={ - 'simulation': { - 'name': 'string' - } - } - ) + request.check_required_parameters(body={'simulation': {'name': 'string'}}) except exceptions.ParameterError as e: return Response(400, e.message) @@ -42,46 +36,30 @@ def POST(request): # Instantiate an Authorization and insert it into the database - authorization = Authorization( - user_id=User.from_google_id(request.google_id).id, - simulation_id=simulation.id, - authorization_level='OWN' - ) + authorization = Authorization(user_id=User.from_google_id(request.google_id).id, + simulation_id=simulation.id, + authorization_level='OWN') authorization.insert() # Instantiate a Path and insert it into the database - path = Path( - simulation_id=simulation.id, - datetime_created=database.datetime_to_string(datetime.now()) - ) + path = Path(simulation_id=simulation.id, datetime_created=database.datetime_to_string(datetime.now())) path.insert() # Instantiate a Datacenter and insert it into the database - datacenter = Datacenter( - starred=0, - simulation_id=simulation.id - ) + datacenter = Datacenter(starred=0, simulation_id=simulation.id) datacenter.insert() # Instantiate a Section and insert it into the database - section = Section( - path_id=path.id, - datacenter_id=datacenter.id, - start_tick=0 - ) + section = Section(path_id=path.id, datacenter_id=datacenter.id, start_tick=0) section.insert() # Return this Simulation - return Response( - 200, - 'Successfully created {}.'.format(simulation), - simulation.to_JSON() - ) + return Response(200, 'Successfully created {}.'.format(simulation), simulation.to_JSON()) diff --git a/opendc/api/v2/simulations/simulationId/authorizations/endpoint.py b/opendc/api/v2/simulations/simulationId/authorizations/endpoint.py index 1d6b494e..80d45d04 100644 --- a/opendc/api/v2/simulations/simulationId/authorizations/endpoint.py +++ b/opendc/api/v2/simulations/simulationId/authorizations/endpoint.py @@ -10,18 +10,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'simulationId': 'int' - } - ) + request.check_required_parameters(path={'simulationId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Simulation and make sure it exists - simulation = Simulation.from_primary_key((request.params_path['simulationId'],)) + simulation = Simulation.from_primary_key((request.params_path['simulationId'], )) if not simulation.exists(): return Response(404, '{} not found.'.format(simulation)) @@ -37,8 +33,5 @@ def GET(request): # Return the Authorizations - return Response( - 200, - 'Successfully retrieved Authorizations for {}.'.format(simulation), - [x.to_JSON() for x in authorizations] - ) + return Response(200, 'Successfully retrieved Authorizations for {}.'.format(simulation), + [x.to_JSON() for x in authorizations]) diff --git a/opendc/api/v2/simulations/simulationId/authorizations/userId/endpoint.py b/opendc/api/v2/simulations/simulationId/authorizations/userId/endpoint.py index 46458ffc..d417936f 100644 --- a/opendc/api/v2/simulations/simulationId/authorizations/userId/endpoint.py +++ b/opendc/api/v2/simulations/simulationId/authorizations/userId/endpoint.py @@ -11,22 +11,14 @@ def DELETE(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'simulationId': 'int', - 'userId': 'int' - } - ) + request.check_required_parameters(path={'simulationId': 'int', 'userId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate an Authorization - authorization = Authorization.from_primary_key(( - request.params_path['userId'], - request.params_path['simulationId'] - )) + authorization = Authorization.from_primary_key((request.params_path['userId'], request.params_path['simulationId'])) # Make sure this Authorization exists in the database @@ -42,11 +34,7 @@ def DELETE(request): authorization.delete() - return Response( - 200, - 'Successfully deleted {}.'.format(authorization), - authorization.to_JSON() - ) + return Response(200, 'Successfully deleted {}.'.format(authorization), authorization.to_JSON()) def GET(request): @@ -55,22 +43,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'simulationId': 'int', - 'userId': 'int' - } - ) + request.check_required_parameters(path={'simulationId': 'int', 'userId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate an Authorization - authorization = Authorization.from_primary_key(( - request.params_path['userId'], - request.params_path['simulationId'] - )) + authorization = Authorization.from_primary_key((request.params_path['userId'], request.params_path['simulationId'])) # Make sure this Authorization exists in the database @@ -83,11 +63,7 @@ def GET(request): # Return this Authorization - return Response( - 200, - 'Successfully retrieved {}'.format(authorization), - authorization.to_JSON() - ) + return Response(200, 'Successfully retrieved {}'.format(authorization), authorization.to_JSON()) def POST(request): @@ -96,17 +72,13 @@ def POST(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'userId': 'int', - 'simulationId': 'int' - }, - body={ - 'authorization': { - 'authorizationLevel': 'string' - } - } - ) + request.check_required_parameters(path={ + 'userId': 'int', + 'simulationId': 'int' + }, + body={'authorization': { + 'authorizationLevel': 'string' + }}) except exceptions.ParameterError as e: return Response(400, e.message) @@ -114,18 +86,21 @@ def POST(request): # Instantiate an Authorization authorization = Authorization.from_JSON({ - 'userId': request.params_path['userId'], - 'simulationId': request.params_path['simulationId'], - 'authorizationLevel': request.params_body['authorization']['authorizationLevel'] + 'userId': + request.params_path['userId'], + 'simulationId': + request.params_path['simulationId'], + 'authorizationLevel': + request.params_body['authorization']['authorizationLevel'] }) # Make sure the Simulation and User exist - user = User.from_primary_key((authorization.user_id,)) + user = User.from_primary_key((authorization.user_id, )) if not user.exists(): return Response(404, '{} not found.'.format(user)) - simulation = Simulation.from_primary_key((authorization.simulation_id,)) + simulation = Simulation.from_primary_key((authorization.simulation_id, )) if not simulation.exists(): return Response(404, '{} not found.'.format(simulation)) @@ -149,11 +124,7 @@ def POST(request): # Return this Authorization - return Response( - 200, - 'Successfully added {}'.format(authorization), - authorization.to_JSON() - ) + return Response(200, 'Successfully added {}'.format(authorization), authorization.to_JSON()) def PUT(request): @@ -162,17 +133,13 @@ def PUT(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'simulationId': 'int', - 'userId': 'int' - }, - body={ - 'authorization': { - 'authorizationLevel': 'string' - } - } - ) + request.check_required_parameters(path={ + 'simulationId': 'int', + 'userId': 'int' + }, + body={'authorization': { + 'authorizationLevel': 'string' + }}) except exceptions.ParameterError as e: return Response(400, e.message) @@ -180,9 +147,12 @@ def PUT(request): # Instantiate and Authorization authorization = Authorization.from_JSON({ - 'userId': request.params_path['userId'], - 'simulationId': request.params_path['simulationId'], - 'authorizationLevel': request.params_body['authorization']['authorizationLevel'] + 'userId': + request.params_path['userId'], + 'simulationId': + request.params_path['simulationId'], + 'authorizationLevel': + request.params_body['authorization']['authorizationLevel'] }) # Make sure this Authorization exists @@ -205,8 +175,4 @@ def PUT(request): # Return this Authorization - return Response( - 200, - 'Successfully updated {}.'.format(authorization), - authorization.to_JSON() - ) + return Response(200, 'Successfully updated {}.'.format(authorization), authorization.to_JSON()) diff --git a/opendc/api/v2/simulations/simulationId/datacenters/endpoint.py b/opendc/api/v2/simulations/simulationId/datacenters/endpoint.py index e28402e4..88c5fe21 100644 --- a/opendc/api/v2/simulations/simulationId/datacenters/endpoint.py +++ b/opendc/api/v2/simulations/simulationId/datacenters/endpoint.py @@ -10,17 +10,11 @@ def POST(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'simulationId': 'int' - }, - body={ - 'datacenter': { - 'starred': 'int', - 'simulationId': 'int' - } - } - ) + request.check_required_parameters(path={'simulationId': 'int'}, + body={'datacenter': { + 'starred': 'int', + 'simulationId': 'int' + }}) except exceptions.ParameterError as e: return Response(400, e.message) @@ -32,7 +26,7 @@ def POST(request): # Instantiate a Simulation from the database - simulation = Simulation.from_primary_key((request.params_path['simulationId'],)) + simulation = Simulation.from_primary_key((request.params_path['simulationId'], )) # Make sure this Simulation exists @@ -54,8 +48,4 @@ def POST(request): datacenter.read() - return Response( - 200, - 'Successfully added {}.'.format(datacenter), - datacenter.to_JSON() - ) + return Response(200, 'Successfully added {}.'.format(datacenter), datacenter.to_JSON()) diff --git a/opendc/api/v2/simulations/simulationId/endpoint.py b/opendc/api/v2/simulations/simulationId/endpoint.py index 5e595740..a6fc0a02 100644 --- a/opendc/api/v2/simulations/simulationId/endpoint.py +++ b/opendc/api/v2/simulations/simulationId/endpoint.py @@ -11,18 +11,14 @@ def DELETE(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'simulationId': 'int' - } - ) + request.check_required_parameters(path={'simulationId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Simulation and make sure it exists - simulation = Simulation.from_primary_key((request.params_path['simulationId'],)) + simulation = Simulation.from_primary_key((request.params_path['simulationId'], )) if not simulation.exists(): return Response(404, '{} not found.'.format(simulation)) @@ -38,11 +34,7 @@ def DELETE(request): # Return this Simulation - return Response( - 200, - 'Successfully deleted {}.'.format(simulation), - simulation.to_JSON() - ) + return Response(200, 'Successfully deleted {}.'.format(simulation), simulation.to_JSON()) def GET(request): @@ -51,18 +43,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'simulationId': 'int' - } - ) + request.check_required_parameters(path={'simulationId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Simulation and make sure it exists - simulation = Simulation.from_primary_key((request.params_path['simulationId'],)) + simulation = Simulation.from_primary_key((request.params_path['simulationId'], )) if not simulation.exists(): return Response(404, '{} not found.'.format(simulation)) @@ -76,11 +64,7 @@ def GET(request): simulation.read() - return Response( - 200, - 'Successfully retrieved {}'.format(simulation), - simulation.to_JSON() - ) + return Response(200, 'Successfully retrieved {}'.format(simulation), simulation.to_JSON()) def PUT(request): @@ -89,23 +73,14 @@ def PUT(request): # Make sure required parameters are there try: - request.check_required_parameters( - body={ - 'simulation': { - 'name': 'name' - } - }, - path={ - 'simulationId': 'int' - } - ) + request.check_required_parameters(body={'simulation': {'name': 'name'}}, path={'simulationId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Simulation and make sure it exists - simulation = Simulation.from_primary_key((request.params_path['simulationId'],)) + simulation = Simulation.from_primary_key((request.params_path['simulationId'], )) if not simulation.exists(): return Response(404, '{} not found.'.format(simulation)) @@ -126,8 +101,4 @@ def PUT(request): # Return this Simulation - return Response( - 200, - 'Successfully updated {}.'.format(simulation), - simulation.to_JSON() - ) + return Response(200, 'Successfully updated {}.'.format(simulation), simulation.to_JSON()) diff --git a/opendc/api/v2/simulations/simulationId/experiments/endpoint.py b/opendc/api/v2/simulations/simulationId/experiments/endpoint.py index 86fadb24..68465bdc 100644 --- a/opendc/api/v2/simulations/simulationId/experiments/endpoint.py +++ b/opendc/api/v2/simulations/simulationId/experiments/endpoint.py @@ -10,18 +10,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'simulationId': 'int' - } - ) + request.check_required_parameters(path={'simulationId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Simulation from the database - simulation = Simulation.from_primary_key((request.params_path['simulationId'],)) + simulation = Simulation.from_primary_key((request.params_path['simulationId'], )) # Make sure this Simulation exists @@ -37,11 +33,8 @@ def GET(request): experiments = Experiment.query('simulation_id', request.params_path['simulationId']) - return Response( - 200, - 'Successfully retrieved Experiments for {}.'.format(simulation), - [x.to_JSON() for x in experiments] - ) + return Response(200, 'Successfully retrieved Experiments for {}.'.format(simulation), + [x.to_JSON() for x in experiments]) def POST(request): @@ -50,20 +43,16 @@ def POST(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'simulationId': 'int' - }, - body={ - 'experiment': { - 'simulationId': 'int', - 'pathId': 'int', - 'traceId': 'int', - 'schedulerName': 'string', - 'name': 'string' - } - } - ) + request.check_required_parameters(path={'simulationId': 'int'}, + body={ + 'experiment': { + 'simulationId': 'int', + 'pathId': 'int', + 'traceId': 'int', + 'schedulerName': 'string', + 'name': 'string' + } + }) except exceptions.ParameterError as e: return Response(400, e.message) @@ -75,7 +64,7 @@ def POST(request): # Instantiate a Simulation from the database - simulation = Simulation.from_primary_key((request.params_path['simulationId'],)) + simulation = Simulation.from_primary_key((request.params_path['simulationId'], )) # Make sure this Simulation exists @@ -105,8 +94,4 @@ def POST(request): experiment.read() - return Response( - 200, - 'Successfully added {}.'.format(experiment), - experiment.to_JSON() - ) + return Response(200, 'Successfully added {}.'.format(experiment), experiment.to_JSON()) diff --git a/opendc/api/v2/simulations/simulationId/paths/endpoint.py b/opendc/api/v2/simulations/simulationId/paths/endpoint.py index e4aab427..85a373b2 100644 --- a/opendc/api/v2/simulations/simulationId/paths/endpoint.py +++ b/opendc/api/v2/simulations/simulationId/paths/endpoint.py @@ -10,17 +10,13 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'simulationId': 'int' - } - ) + request.check_required_parameters(path={'simulationId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Simulation from the database - simulation = Simulation.from_primary_key((request.params_path['simulationId'],)) + simulation = Simulation.from_primary_key((request.params_path['simulationId'], )) # Make sure this Simulation exists @@ -36,8 +32,4 @@ def GET(request): paths = Path.query('simulation_id', request.params_path['simulationId']) - return Response( - 200, - 'Successfully retrieved Paths for {}.'.format(simulation), - [x.to_JSON() for x in paths] - ) + return Response(200, 'Successfully retrieved Paths for {}.'.format(simulation), [x.to_JSON() for x in paths]) diff --git a/opendc/api/v2/specifications/cpus/endpoint.py b/opendc/api/v2/specifications/cpus/endpoint.py index 5cdbb9ec..87975221 100644 --- a/opendc/api/v2/specifications/cpus/endpoint.py +++ b/opendc/api/v2/specifications/cpus/endpoint.py @@ -11,8 +11,4 @@ def GET(request): # Return the CPUs - return Response( - 200, - 'Successfully retrieved CPUs.', - [x.to_JSON() for x in cpus] - ) + return Response(200, 'Successfully retrieved CPUs.', [x.to_JSON() for x in cpus]) diff --git a/opendc/api/v2/specifications/cpus/id/endpoint.py b/opendc/api/v2/specifications/cpus/id/endpoint.py index c2453e51..9c4229e1 100644 --- a/opendc/api/v2/specifications/cpus/id/endpoint.py +++ b/opendc/api/v2/specifications/cpus/id/endpoint.py @@ -9,26 +9,18 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'id': 'int' - } - ) + request.check_required_parameters(path={'id': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a CPU and make sure it exists - cpu = CPU.from_primary_key((request.params_path['id'],)) + cpu = CPU.from_primary_key((request.params_path['id'], )) if not cpu.exists(): return Response(404, '{} not found.'.format(cpu)) # Return this CPU - return Response( - 200, - 'Successfully retrieved {}.'.format(cpu), - cpu.to_JSON() - ) + return Response(200, 'Successfully retrieved {}.'.format(cpu), cpu.to_JSON()) diff --git a/opendc/api/v2/specifications/failure-models/endpoint.py b/opendc/api/v2/specifications/failure-models/endpoint.py index fff668c0..6397e27e 100644 --- a/opendc/api/v2/specifications/failure-models/endpoint.py +++ b/opendc/api/v2/specifications/failure-models/endpoint.py @@ -11,8 +11,4 @@ def GET(request): # Return the FailureModels - return Response( - 200, - 'Successfully retrieved FailureModels.', - [x.to_JSON() for x in failure_models] - ) + return Response(200, 'Successfully retrieved FailureModels.', [x.to_JSON() for x in failure_models]) diff --git a/opendc/api/v2/specifications/failure-models/id/endpoint.py b/opendc/api/v2/specifications/failure-models/id/endpoint.py index 0797c9c9..67fe004a 100644 --- a/opendc/api/v2/specifications/failure-models/id/endpoint.py +++ b/opendc/api/v2/specifications/failure-models/id/endpoint.py @@ -9,26 +9,18 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'id': 'int' - } - ) + request.check_required_parameters(path={'id': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a FailureModel and make sure it exists - failure_model = FailureModel.from_primary_key((request.params_path['id'],)) + failure_model = FailureModel.from_primary_key((request.params_path['id'], )) if not failure_model.exists(): return Response(404, '{} not found.'.format(failure_model)) # Return this FailureModel - return Response( - 200, - 'Successfully retrieved {}.'.format(failure_model), - failure_model.to_JSON() - ) + return Response(200, 'Successfully retrieved {}.'.format(failure_model), failure_model.to_JSON()) diff --git a/opendc/api/v2/specifications/gpus/endpoint.py b/opendc/api/v2/specifications/gpus/endpoint.py index 5676f62b..24beb873 100644 --- a/opendc/api/v2/specifications/gpus/endpoint.py +++ b/opendc/api/v2/specifications/gpus/endpoint.py @@ -11,8 +11,4 @@ def GET(request): # Return the GPUs - return Response( - 200, - 'Successfully retrieved GPUs.', - [x.to_JSON() for x in gpus] - ) + return Response(200, 'Successfully retrieved GPUs.', [x.to_JSON() for x in gpus]) diff --git a/opendc/api/v2/specifications/gpus/id/endpoint.py b/opendc/api/v2/specifications/gpus/id/endpoint.py index 81113dc3..e08833b8 100644 --- a/opendc/api/v2/specifications/gpus/id/endpoint.py +++ b/opendc/api/v2/specifications/gpus/id/endpoint.py @@ -9,26 +9,18 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'id': 'int' - } - ) + request.check_required_parameters(path={'id': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a GPU and make sure it exists - gpu = GPU.from_primary_key((request.params_path['id'],)) + gpu = GPU.from_primary_key((request.params_path['id'], )) if not gpu.exists(): return Response(404, '{} not found.'.format(gpu)) # Return this GPU - return Response( - 200, - 'Successfully retrieved {}.'.format(gpu), - gpu.to_JSON() - ) + return Response(200, 'Successfully retrieved {}.'.format(gpu), gpu.to_JSON()) diff --git a/opendc/api/v2/specifications/memories/endpoint.py b/opendc/api/v2/specifications/memories/endpoint.py index 271824b3..95025418 100644 --- a/opendc/api/v2/specifications/memories/endpoint.py +++ b/opendc/api/v2/specifications/memories/endpoint.py @@ -11,8 +11,4 @@ def GET(request): # Return the Memories - return Response( - 200, - 'Successfully retrieved Memories.', - [x.to_JSON() for x in memories] - ) + return Response(200, 'Successfully retrieved Memories.', [x.to_JSON() for x in memories]) diff --git a/opendc/api/v2/specifications/memories/id/endpoint.py b/opendc/api/v2/specifications/memories/id/endpoint.py index 863099ca..5f547f76 100644 --- a/opendc/api/v2/specifications/memories/id/endpoint.py +++ b/opendc/api/v2/specifications/memories/id/endpoint.py @@ -9,26 +9,18 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'id': 'int' - } - ) + request.check_required_parameters(path={'id': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Memory and make sure it exists - memory = Memory.from_primary_key((request.params_path['id'],)) + memory = Memory.from_primary_key((request.params_path['id'], )) if not memory.exists(): return Response(404, '{} not found.'.format(memory)) # Return this Memory - return Response( - 200, - 'Successfully retrieved {}.'.format(memory), - memory.to_JSON() - ) + return Response(200, 'Successfully retrieved {}.'.format(memory), memory.to_JSON()) diff --git a/opendc/api/v2/specifications/storages/endpoint.py b/opendc/api/v2/specifications/storages/endpoint.py index 28f33177..945b89b2 100644 --- a/opendc/api/v2/specifications/storages/endpoint.py +++ b/opendc/api/v2/specifications/storages/endpoint.py @@ -11,8 +11,4 @@ def GET(request): # Return the Storages - return Response( - 200, - 'Successfully retrieved Storages.', - [x.to_JSON() for x in storages] - ) + return Response(200, 'Successfully retrieved Storages.', [x.to_JSON() for x in storages]) diff --git a/opendc/api/v2/specifications/storages/id/endpoint.py b/opendc/api/v2/specifications/storages/id/endpoint.py index ebe65857..b1f7e8c0 100644 --- a/opendc/api/v2/specifications/storages/id/endpoint.py +++ b/opendc/api/v2/specifications/storages/id/endpoint.py @@ -9,26 +9,18 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'id': 'int' - } - ) + request.check_required_parameters(path={'id': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Storage and make sure it exists - storage = Storage.from_primary_key((request.params_path['id'],)) + storage = Storage.from_primary_key((request.params_path['id'], )) if not storage.exists(): return Response(404, '{} not found.'.format(storage)) # Return this CPU - return Response( - 200, - 'Successfully retrieved {}.'.format(storage), - storage.to_JSON() - ) + return Response(200, 'Successfully retrieved {}.'.format(storage), storage.to_JSON()) diff --git a/opendc/api/v2/tiles/tileId/endpoint.py b/opendc/api/v2/tiles/tileId/endpoint.py index 5ccc9cd7..85cbd9f4 100644 --- a/opendc/api/v2/tiles/tileId/endpoint.py +++ b/opendc/api/v2/tiles/tileId/endpoint.py @@ -9,18 +9,14 @@ def GET(request): # Make sure request parameters are there try: - request.check_required_parameters( - path={ - 'tileId': 'int' - } - ) + request.check_required_parameters(path={'tileId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Tile from the database - tile = Tile.from_primary_key((request.params_path['tileId'],)) + tile = Tile.from_primary_key((request.params_path['tileId'], )) # Make sure this Tile exists @@ -36,11 +32,7 @@ def GET(request): tile.read() - return Response( - 200, - 'Successfully retrieved {}.'.format(tile), - tile.to_JSON() - ) + return Response(200, 'Successfully retrieved {}.'.format(tile), tile.to_JSON()) def DELETE(request): @@ -49,18 +41,14 @@ def DELETE(request): # Make sure request parameters are there try: - request.check_required_parameters( - path={ - 'tileId': 'int' - } - ) + request.check_required_parameters(path={'tileId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Tile from the database - tile = Tile.from_primary_key((request.params_path['tileId'],)) + tile = Tile.from_primary_key((request.params_path['tileId'], )) # Make sure this Tile exists @@ -78,8 +66,4 @@ def DELETE(request): # Return this Tile - return Response( - 200, - 'Successfully deleted {}.'.format(tile), - tile.to_JSON() - ) + return Response(200, 'Successfully deleted {}.'.format(tile), tile.to_JSON()) diff --git a/opendc/api/v2/tiles/tileId/rack/endpoint.py b/opendc/api/v2/tiles/tileId/rack/endpoint.py index 64245856..0e1017e8 100644 --- a/opendc/api/v2/tiles/tileId/rack/endpoint.py +++ b/opendc/api/v2/tiles/tileId/rack/endpoint.py @@ -10,18 +10,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'tileId': 'int' - }, - ) + request.check_required_parameters(path={'tileId': 'int'}, ) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Tile from the database - tile = Tile.from_primary_key((request.params_path['tileId'],)) + tile = Tile.from_primary_key((request.params_path['tileId'], )) # Make sure this Tile exists @@ -35,7 +31,7 @@ def GET(request): # Instantiate a Rack from the database - rack = Rack.from_primary_key((tile.object_id,)) + rack = Rack.from_primary_key((tile.object_id, )) # Make sure this Rack exists @@ -46,11 +42,7 @@ def GET(request): rack.read() - return Response( - 200, - 'Successfully retrieved {}.'.format(rack), - rack.to_JSON() - ) + return Response(200, 'Successfully retrieved {}.'.format(rack), rack.to_JSON()) def POST(request): @@ -59,25 +51,19 @@ def POST(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'tileId': 'int' - }, - body={ - 'rack': { - 'name': 'string', - 'capacity': 'int', - 'powerCapacityW': 'int' - } - } - ) + request.check_required_parameters(path={'tileId': 'int'}, + body={'rack': { + 'name': 'string', + 'capacity': 'int', + 'powerCapacityW': 'int' + }}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Tile from the database - tile = Tile.from_primary_key((request.params_path['tileId'],)) + tile = Tile.from_primary_key((request.params_path['tileId'], )) # Make sure this Tile exists @@ -109,11 +95,7 @@ def POST(request): rack.read() - return Response( - 200, - 'Successfully added {}.'.format(rack), - rack.to_JSON() - ) + return Response(200, 'Successfully added {}.'.format(rack), rack.to_JSON()) def PUT(request): @@ -122,25 +104,19 @@ def PUT(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'tileId': 'int' - }, - body={ - 'rack': { - 'name': 'string', - 'capacity': 'int', - 'powerCapacityW': 'int' - } - } - ) + request.check_required_parameters(path={'tileId': 'int'}, + body={'rack': { + 'name': 'string', + 'capacity': 'int', + 'powerCapacityW': 'int' + }}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Tile from the database - tile = Tile.from_primary_key((request.params_path['tileId'],)) + tile = Tile.from_primary_key((request.params_path['tileId'], )) # Make sure this Tile exists @@ -154,7 +130,7 @@ def PUT(request): # Instantiate a Rack from the database - rack = Rack.from_primary_key((tile.object_id,)) + rack = Rack.from_primary_key((tile.object_id, )) # Make sure this Rack exists @@ -172,11 +148,7 @@ def PUT(request): rack.read() - return Response( - 200, - 'Successfully updated {}.'.format(rack), - rack.to_JSON() - ) + return Response(200, 'Successfully updated {}.'.format(rack), rack.to_JSON()) def DELETE(request): @@ -185,18 +157,14 @@ def DELETE(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'tileId': 'int' - }, - ) + request.check_required_parameters(path={'tileId': 'int'}, ) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Tile from the database - tile = Tile.from_primary_key((request.params_path['tileId'],)) + tile = Tile.from_primary_key((request.params_path['tileId'], )) # Make sure this Tile exists @@ -210,7 +178,7 @@ def DELETE(request): # Instantiate a Rack from the database - rack = Rack.from_primary_key((tile.object_id,)) + rack = Rack.from_primary_key((tile.object_id, )) # Make sure this Rack exists @@ -230,8 +198,4 @@ def DELETE(request): # Return this Rack - return Response( - 200, - 'Successfully deleted {}.'.format(rack), - rack.to_JSON() - ) + return Response(200, 'Successfully deleted {}.'.format(rack), rack.to_JSON()) diff --git a/opendc/api/v2/tiles/tileId/rack/machines/endpoint.py b/opendc/api/v2/tiles/tileId/rack/machines/endpoint.py index 5272c117..1ff25f44 100644 --- a/opendc/api/v2/tiles/tileId/rack/machines/endpoint.py +++ b/opendc/api/v2/tiles/tileId/rack/machines/endpoint.py @@ -10,11 +10,7 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'tileId': 'int' - } - ) + request.check_required_parameters(path={'tileId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) @@ -40,11 +36,7 @@ def GET(request): for machine in machines: machine.read() - return Response( - 200, - 'Successfully retrieved Machines for {}.'.format(rack), - [x.to_JSON() for x in machines] - ) + return Response(200, 'Successfully retrieved Machines for {}.'.format(rack), [x.to_JSON() for x in machines]) def POST(request): @@ -53,22 +45,18 @@ def POST(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'tileId': 'int' - }, - body={ - 'machine': { - 'rackId': 'int', - 'position': 'int', - 'tags': 'list-string', - 'cpuIds': 'list-int', - 'gpuIds': 'list-int', - 'memoryIds': 'list-int', - 'storageIds': 'list-int' - } - } - ) + request.check_required_parameters(path={'tileId': 'int'}, + body={ + 'machine': { + 'rackId': 'int', + 'position': 'int', + 'tags': 'list-string', + 'cpuIds': 'list-int', + 'gpuIds': 'list-int', + 'memoryIds': 'list-int', + 'storageIds': 'list-int' + } + }) except exceptions.ParameterError as e: return Response(400, e.message) @@ -111,8 +99,4 @@ def POST(request): machine.read() - return Response( - 200, - 'Successfully added {}.'.format(machine), - machine.to_JSON() - ) + return Response(200, 'Successfully added {}.'.format(machine), machine.to_JSON()) diff --git a/opendc/api/v2/tiles/tileId/rack/machines/position/endpoint.py b/opendc/api/v2/tiles/tileId/rack/machines/position/endpoint.py index 99011fa4..d82014b3 100644 --- a/opendc/api/v2/tiles/tileId/rack/machines/position/endpoint.py +++ b/opendc/api/v2/tiles/tileId/rack/machines/position/endpoint.py @@ -10,12 +10,7 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'tileId': 'int', - 'position': 'int' - } - ) + request.check_required_parameters(path={'tileId': 'int', 'position': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) @@ -38,34 +33,28 @@ def GET(request): machine.read() - return Response( - 200, - 'Successfully retrieved {}.'.format(machine), - machine.to_JSON() - ) + return Response(200, 'Successfully retrieved {}.'.format(machine), machine.to_JSON()) def PUT(request): """Update the Machine at this location in this Rack.""" try: - request.check_required_parameters( - path={ - 'tileId': 'int', - 'position': 'int' - }, - body={ - 'machine': { - 'rackId': 'int', - 'position': 'int', - 'tags': 'list-string', - 'cpuIds': 'list-int', - 'gpuIds': 'list-int', - 'memoryIds': 'list-int', - 'storageIds': 'list-int' - } - } - ) + request.check_required_parameters(path={ + 'tileId': 'int', + 'position': 'int' + }, + body={ + 'machine': { + 'rackId': 'int', + 'position': 'int', + 'tags': 'list-string', + 'cpuIds': 'list-int', + 'gpuIds': 'list-int', + 'memoryIds': 'list-int', + 'storageIds': 'list-int' + } + }) except exceptions.ParameterError as e: return Response(400, e.message) @@ -114,11 +103,7 @@ def PUT(request): machine.read() - return Response( - 200, - 'Successfully updated {}.'.format(machine), - machine.to_JSON() - ) + return Response(200, 'Successfully updated {}.'.format(machine), machine.to_JSON()) def DELETE(request): @@ -127,12 +112,7 @@ def DELETE(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'tileId': 'int', - 'position': 'int' - } - ) + request.check_required_parameters(path={'tileId': 'int', 'position': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) @@ -157,8 +137,4 @@ def DELETE(request): # Return this Machine - return Response( - 200, - 'Successfully deleted {}.'.format(machine), - machine.to_JSON() - ) + return Response(200, 'Successfully deleted {}.'.format(machine), machine.to_JSON()) diff --git a/opendc/api/v2/traces/endpoint.py b/opendc/api/v2/traces/endpoint.py index 78930b0f..610be73e 100644 --- a/opendc/api/v2/traces/endpoint.py +++ b/opendc/api/v2/traces/endpoint.py @@ -11,8 +11,4 @@ def GET(request): # Return the Traces - return Response( - 200, - 'Successfully retrieved Traces', - [x.to_JSON() for x in traces] - ) + return Response(200, 'Successfully retrieved Traces', [x.to_JSON() for x in traces]) diff --git a/opendc/api/v2/traces/traceId/endpoint.py b/opendc/api/v2/traces/traceId/endpoint.py index 50993c41..fe837c73 100644 --- a/opendc/api/v2/traces/traceId/endpoint.py +++ b/opendc/api/v2/traces/traceId/endpoint.py @@ -9,26 +9,18 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'traceId': 'int' - } - ) + request.check_required_parameters(path={'traceId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Trace and make sure it exists - trace = Trace.from_primary_key((request.params_path['traceId'],)) + trace = Trace.from_primary_key((request.params_path['traceId'], )) if not trace.exists(): return Response(404, '{} not found.'.format(trace)) # Return this Trace - return Response( - 200, - 'Successfully retrieved {}.'.format(trace), - trace.to_JSON() - ) + return Response(200, 'Successfully retrieved {}.'.format(trace), trace.to_JSON()) diff --git a/opendc/api/v2/traces/traceId/jobs/endpoint.py b/opendc/api/v2/traces/traceId/jobs/endpoint.py index bd2c6eb0..671e4d83 100644 --- a/opendc/api/v2/traces/traceId/jobs/endpoint.py +++ b/opendc/api/v2/traces/traceId/jobs/endpoint.py @@ -10,18 +10,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'traceId': 'int' - } - ) + request.check_required_parameters(path={'traceId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a Trace and make sure it exists - trace = Trace.from_primary_key((request.params_path['traceId'],)) + trace = Trace.from_primary_key((request.params_path['traceId'], )) if not trace.exists(): return Response(404, '{} not found.'.format(trace)) @@ -30,8 +26,4 @@ def GET(request): jobs = Job.query('trace_id', request.params_path['traceId']) - return Response( - 200, - 'Successfully retrieved Jobs for {}.'.format(trace), - [x.to_JSON() for x in jobs] - ) + return Response(200, 'Successfully retrieved Jobs for {}.'.format(trace), [x.to_JSON() for x in jobs]) diff --git a/opendc/api/v2/users/endpoint.py b/opendc/api/v2/users/endpoint.py index 83949fcf..27c8a9ef 100644 --- a/opendc/api/v2/users/endpoint.py +++ b/opendc/api/v2/users/endpoint.py @@ -8,11 +8,7 @@ def GET(request): """Search for a User using their email address.""" try: - request.check_required_parameters( - query={ - 'email': 'string' - } - ) + request.check_required_parameters(query={'email': 'string'}) except exceptions.ParameterError as e: return Response(400, e.message) @@ -21,11 +17,7 @@ def GET(request): if user is not None: return Response(404, f'User with email {request.params_query["email"]} not found') - return Response( - 200, - 'Successfully retrieved {}.'.format(user), - user.to_JSON() - ) + return Response(200, 'Successfully retrieved {}.'.format(user), user.to_JSON()) def POST(request): @@ -34,13 +26,7 @@ def POST(request): # Make sure required parameters are there try: - request.check_required_parameters( - body={ - 'user': { - 'email': 'string' - } - } - ) + request.check_required_parameters(body={'user': {'email': 'string'}}) except exceptions.ParameterError as e: return Response(400, e.message) @@ -67,8 +53,4 @@ def POST(request): # Return a JSON representation of the User - return Response( - 200, - 'Successfully created {}'.format(user), - user.to_JSON() - ) + return Response(200, 'Successfully created {}'.format(user), user.to_JSON()) diff --git a/opendc/api/v2/users/userId/authorizations/endpoint.py b/opendc/api/v2/users/userId/authorizations/endpoint.py index 46ca12ba..bb3e173c 100644 --- a/opendc/api/v2/users/userId/authorizations/endpoint.py +++ b/opendc/api/v2/users/userId/authorizations/endpoint.py @@ -10,18 +10,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'userId': 'int' - } - ) + request.check_required_parameters(path={'userId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a User and make sure they exist - user = User.from_primary_key((request.params_path['userId'],)) + user = User.from_primary_key((request.params_path['userId'], )) if not user.exists(): return Response(404, '{} not found.'.format(user)) @@ -35,8 +31,5 @@ def GET(request): authorizations = Authorization.query('user_id', request.params_path['userId']) - return Response( - 200, - 'Successfully retrieved Authorizations for {}.'.format(user), - [x.to_JSON() for x in authorizations] - ) + return Response(200, 'Successfully retrieved Authorizations for {}.'.format(user), + [x.to_JSON() for x in authorizations]) diff --git a/opendc/api/v2/users/userId/endpoint.py b/opendc/api/v2/users/userId/endpoint.py index 767c5d13..7f1ce84f 100644 --- a/opendc/api/v2/users/userId/endpoint.py +++ b/opendc/api/v2/users/userId/endpoint.py @@ -9,18 +9,14 @@ def DELETE(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'userId': 'int' - } - ) + request.check_required_parameters(path={'userId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a User and make sure they exist - user = User.from_primary_key((request.params_path['userId'],)) + user = User.from_primary_key((request.params_path['userId'], )) if not user.exists(): return Response(404, '{} not found'.format(user)) @@ -36,11 +32,7 @@ def DELETE(request): # Return this User - return Response( - 200, - 'Successfully deleted {}'.format(user), - user.to_JSON() - ) + return Response(200, 'Successfully deleted {}'.format(user), user.to_JSON()) def GET(request): @@ -49,18 +41,14 @@ def GET(request): # Make sure required parameters are there try: - request.check_required_parameters( - path={ - 'userId': 'int' - } - ) + request.check_required_parameters(path={'userId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a User and make sure they exist - user = User.from_primary_key((request.params_path['userId'],)) + user = User.from_primary_key((request.params_path['userId'], )) if not user.exists(): return Response(404, '{} not found.'.format(user)) @@ -80,24 +68,18 @@ def PUT(request): # Make sure the required parameters are there try: - request.check_required_parameters( - body={ - 'user': { - 'givenName': 'string', - 'familyName': 'string' - } - }, - path={ - 'userId': 'int' - } - ) + request.check_required_parameters(body={'user': { + 'givenName': 'string', + 'familyName': 'string' + }}, + path={'userId': 'int'}) except exceptions.ParameterError as e: return Response(400, e.message) # Instantiate a User and make sure they exist - user = User.from_primary_key((request.params_path['userId'],)) + user = User.from_primary_key((request.params_path['userId'], )) if not user.exists(): return Response(404, '{} not found.'.format(user)) @@ -116,8 +98,4 @@ def PUT(request): # Return this User - return Response( - 200, - 'Successfully updated {}.'.format(user), - user.to_JSON() - ) + return Response(200, 'Successfully updated {}.'.format(user), user.to_JSON()) |
