From bae760a62fc6a480fbe615dff6a7de03c7fd6d1d Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Wed, 24 Jun 2020 09:13:09 +0200 Subject: Add formatter --- opendc/api/v2/simulations/endpoint.py | 38 ++------ .../simulationId/authorizations/endpoint.py | 15 +-- .../simulationId/authorizations/userId/endpoint.py | 106 +++++++-------------- .../simulationId/datacenters/endpoint.py | 24 ++--- opendc/api/v2/simulations/simulationId/endpoint.py | 47 ++------- .../simulationId/experiments/endpoint.py | 47 ++++----- .../v2/simulations/simulationId/paths/endpoint.py | 14 +-- 7 files changed, 83 insertions(+), 208 deletions(-) (limited to 'opendc/api/v2/simulations') 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]) -- cgit v1.2.3