summaryrefslogtreecommitdiff
path: root/opendc
diff options
context:
space:
mode:
Diffstat (limited to 'opendc')
-rw-r--r--opendc/api/v2/datacenters/datacenterId/endpoint.py14
-rw-r--r--opendc/api/v2/datacenters/datacenterId/rooms/endpoint.py40
-rw-r--r--opendc/api/v2/experiments/experimentId/endpoint.py55
-rw-r--r--opendc/api/v2/experiments/experimentId/last-simulated-tick/endpoint.py15
-rw-r--r--opendc/api/v2/experiments/experimentId/machine-states/endpoint.py21
-rw-r--r--opendc/api/v2/experiments/experimentId/rack-states/endpoint.py21
-rw-r--r--opendc/api/v2/experiments/experimentId/room-states/endpoint.py21
-rw-r--r--opendc/api/v2/experiments/experimentId/statistics/task-durations/endpoint.py15
-rw-r--r--opendc/api/v2/experiments/experimentId/task-states/endpoint.py21
-rw-r--r--opendc/api/v2/jobs/jobId/endpoint.py14
-rw-r--r--opendc/api/v2/jobs/jobId/tasks/endpoint.py14
-rw-r--r--opendc/api/v2/paths/pathId/branches/endpoint.py47
-rw-r--r--opendc/api/v2/paths/pathId/endpoint.py14
-rw-r--r--opendc/api/v2/paths/pathId/sections/endpoint.py14
-rw-r--r--opendc/api/v2/room-types/endpoint.py6
-rw-r--r--opendc/api/v2/room-types/name/allowed-objects/endpoint.py12
-rw-r--r--opendc/api/v2/rooms/roomId/endpoint.py52
-rw-r--r--opendc/api/v2/rooms/roomId/tiles/endpoint.py40
-rw-r--r--opendc/api/v2/schedulers/endpoint.py6
-rw-r--r--opendc/api/v2/sections/sectionId/endpoint.py14
-rw-r--r--opendc/api/v2/simulations/endpoint.py38
-rw-r--r--opendc/api/v2/simulations/simulationId/authorizations/endpoint.py15
-rw-r--r--opendc/api/v2/simulations/simulationId/authorizations/userId/endpoint.py106
-rw-r--r--opendc/api/v2/simulations/simulationId/datacenters/endpoint.py24
-rw-r--r--opendc/api/v2/simulations/simulationId/endpoint.py47
-rw-r--r--opendc/api/v2/simulations/simulationId/experiments/endpoint.py47
-rw-r--r--opendc/api/v2/simulations/simulationId/paths/endpoint.py14
-rw-r--r--opendc/api/v2/specifications/cpus/endpoint.py6
-rw-r--r--opendc/api/v2/specifications/cpus/id/endpoint.py14
-rw-r--r--opendc/api/v2/specifications/failure-models/endpoint.py6
-rw-r--r--opendc/api/v2/specifications/failure-models/id/endpoint.py14
-rw-r--r--opendc/api/v2/specifications/gpus/endpoint.py6
-rw-r--r--opendc/api/v2/specifications/gpus/id/endpoint.py14
-rw-r--r--opendc/api/v2/specifications/memories/endpoint.py6
-rw-r--r--opendc/api/v2/specifications/memories/id/endpoint.py14
-rw-r--r--opendc/api/v2/specifications/storages/endpoint.py6
-rw-r--r--opendc/api/v2/specifications/storages/id/endpoint.py14
-rw-r--r--opendc/api/v2/tiles/tileId/endpoint.py28
-rw-r--r--opendc/api/v2/tiles/tileId/rack/endpoint.py86
-rw-r--r--opendc/api/v2/tiles/tileId/rack/machines/endpoint.py46
-rw-r--r--opendc/api/v2/tiles/tileId/rack/machines/position/endpoint.py64
-rw-r--r--opendc/api/v2/traces/endpoint.py6
-rw-r--r--opendc/api/v2/traces/traceId/endpoint.py14
-rw-r--r--opendc/api/v2/traces/traceId/jobs/endpoint.py14
-rw-r--r--opendc/api/v2/users/endpoint.py26
-rw-r--r--opendc/api/v2/users/userId/authorizations/endpoint.py15
-rw-r--r--opendc/api/v2/users/userId/endpoint.py46
-rw-r--r--opendc/models/allowed_object.py7
-rw-r--r--opendc/models/authorization.py7
-rw-r--r--opendc/models/cpu.py11
-rw-r--r--opendc/models/datacenter.py8
-rw-r--r--opendc/models/experiment.py2
-rw-r--r--opendc/models/failure_model.py8
-rw-r--r--opendc/models/gpu.py11
-rw-r--r--opendc/models/job.py7
-rw-r--r--opendc/models/machine.py12
-rw-r--r--opendc/models/machine_state.py15
-rw-r--r--opendc/models/memory.py9
-rw-r--r--opendc/models/model.py54
-rw-r--r--opendc/models/object.py7
-rw-r--r--opendc/models/queued_experiment.py6
-rw-r--r--opendc/models/rack.py6
-rw-r--r--opendc/models/rack_state.py16
-rw-r--r--opendc/models/room.py2
-rw-r--r--opendc/models/room_state.py16
-rw-r--r--opendc/models/room_type.py6
-rw-r--r--opendc/models/scheduler.py6
-rw-r--r--opendc/models/section.py2
-rw-r--r--opendc/models/storage.py9
-rw-r--r--opendc/models/task_duration.py14
-rw-r--r--opendc/models/task_state.py10
-rw-r--r--opendc/models/tile.py4
-rw-r--r--opendc/models/trace.py7
-rw-r--r--opendc/models/user.py4
-rw-r--r--opendc/util/exceptions.py23
-rw-r--r--opendc/util/parameter_checker.py22
-rw-r--r--opendc/util/rest.py20
77 files changed, 386 insertions, 1137 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())
diff --git a/opendc/models/allowed_object.py b/opendc/models/allowed_object.py
index 62fcb1ae..48f2abd5 100644
--- a/opendc/models/allowed_object.py
+++ b/opendc/models/allowed_object.py
@@ -2,12 +2,7 @@ from opendc.models.model import Model
class AllowedObject(Model):
- JSON_TO_PYTHON_DICT = {
- 'AllowedObject': {
- 'roomType': 'room_type',
- 'objectType': 'object_type'
- }
- }
+ JSON_TO_PYTHON_DICT = {'AllowedObject': {'roomType': 'room_type', 'objectType': 'object_type'}}
COLLECTION_NAME = 'allowed_objects'
COLUMNS = ['room_type', 'object_type']
diff --git a/opendc/models/authorization.py b/opendc/models/authorization.py
index 4c714e6d..7ec88e78 100644
--- a/opendc/models/authorization.py
+++ b/opendc/models/authorization.py
@@ -18,12 +18,7 @@ class Authorization(Model):
def google_id_has_at_least(self, google_id, authorization_level):
"""Return True if the User has at least the given auth level over this Authorization."""
- authorization = Authorization.from_primary_key(
- (
- User.from_google_id(google_id).id,
- self.simulation_id
- )
- )
+ authorization = Authorization.from_primary_key((User.from_google_id(google_id).id, self.simulation_id))
if authorization is None:
return False
diff --git a/opendc/models/cpu.py b/opendc/models/cpu.py
index 7ab8cecc..034a86fe 100644
--- a/opendc/models/cpu.py
+++ b/opendc/models/cpu.py
@@ -19,15 +19,8 @@ class CPU(Model):
COLLECTION_NAME = 'cpus'
COLUMNS = [
- 'id',
- 'manufacturer',
- 'family',
- 'generation',
- 'model',
- 'clock_rate_mhz',
- 'number_of_cores',
- 'energy_consumption_w',
- 'failure_model_id'
+ 'id', 'manufacturer', 'family', 'generation', 'model', 'clock_rate_mhz', 'number_of_cores',
+ 'energy_consumption_w', 'failure_model_id'
]
COLUMNS_PRIMARY_KEY = ['id']
diff --git a/opendc/models/datacenter.py b/opendc/models/datacenter.py
index 21e37b52..d4cbf811 100644
--- a/opendc/models/datacenter.py
+++ b/opendc/models/datacenter.py
@@ -3,13 +3,7 @@ from opendc.models.section import Section
class Datacenter(Model):
- JSON_TO_PYTHON_DICT = {
- 'datacenter': {
- 'id': 'id',
- 'starred': 'starred',
- 'simulationId': 'simulation_id'
- }
- }
+ JSON_TO_PYTHON_DICT = {'datacenter': {'id': 'id', 'starred': 'starred', 'simulationId': 'simulation_id'}}
PATH = '/v1/simulations/{simulationId}/datacenters'
diff --git a/opendc/models/experiment.py b/opendc/models/experiment.py
index 23d80047..1f33fa3b 100644
--- a/opendc/models/experiment.py
+++ b/opendc/models/experiment.py
@@ -27,7 +27,7 @@ class Experiment(Model):
# Get the Simulation
try:
- simulation = Simulation.from_primary_key((self.simulation_id,))
+ simulation = Simulation.from_primary_key((self.simulation_id, ))
except exceptions.RowNotFoundError:
return False
diff --git a/opendc/models/failure_model.py b/opendc/models/failure_model.py
index cffa2c47..f5c4909d 100644
--- a/opendc/models/failure_model.py
+++ b/opendc/models/failure_model.py
@@ -2,13 +2,7 @@ from opendc.models.model import Model
class FailureModel(Model):
- JSON_TO_PYTHON_DICT = {
- 'FailureModel': {
- 'id': 'id',
- 'name': 'name',
- 'rate': 'rate'
- }
- }
+ JSON_TO_PYTHON_DICT = {'FailureModel': {'id': 'id', 'name': 'name', 'rate': 'rate'}}
COLLECTION_NAME = 'failure_models'
COLUMNS = ['id', 'name', 'rate']
diff --git a/opendc/models/gpu.py b/opendc/models/gpu.py
index d56ceba6..672df6fa 100644
--- a/opendc/models/gpu.py
+++ b/opendc/models/gpu.py
@@ -19,15 +19,8 @@ class GPU(Model):
COLLECTION_NAME = 'gpus'
COLUMNS = [
- 'id',
- 'manufacturer',
- 'family',
- 'generation',
- 'model',
- 'clock_rate_mhz',
- 'number_of_cores',
- 'energy_consumption_w',
- 'failure_model_id'
+ 'id', 'manufacturer', 'family', 'generation', 'model', 'clock_rate_mhz', 'number_of_cores',
+ 'energy_consumption_w', 'failure_model_id'
]
COLUMNS_PRIMARY_KEY = ['id']
diff --git a/opendc/models/job.py b/opendc/models/job.py
index aaf2a20c..81354952 100644
--- a/opendc/models/job.py
+++ b/opendc/models/job.py
@@ -2,12 +2,7 @@ from opendc.models.model import Model
class Job(Model):
- JSON_TO_PYTHON_DICT = {
- 'Job': {
- 'id': 'id',
- 'name': 'name'
- }
- }
+ JSON_TO_PYTHON_DICT = {'Job': {'id': 'id', 'name': 'name'}}
COLLECTION_NAME = 'jobs'
COLUMNS = ['id', 'name']
diff --git a/opendc/models/machine.py b/opendc/models/machine.py
index b79cae94..1b853bf9 100644
--- a/opendc/models/machine.py
+++ b/opendc/models/machine.py
@@ -41,15 +41,13 @@ class Machine(Model):
# First, delete current machine-device links
statement = 'DELETE FROM machine_{} WHERE machine_id = %s'.format(device_table)
- database.execute(statement, (before_insert.id,))
+ database.execute(statement, (before_insert.id, ))
# Then, add current ones
for device_id in getattr(before_insert, before_insert.device_table_to_attribute[device_table]):
statement = 'INSERT INTO machine_{} (machine_id, {}) VALUES (%s, %s)'.format(
- device_table,
- before_insert.device_table_to_attribute[device_table][:-1]
- )
+ device_table, before_insert.device_table_to_attribute[device_table][:-1])
database.execute(statement, (before_insert.id, device_id))
@@ -68,7 +66,7 @@ class Machine(Model):
except:
return cls(id=-1)
- return cls.from_primary_key((machine_id,))
+ return cls.from_primary_key((machine_id, ))
def google_id_has_at_least(self, google_id, authorization_level):
"""Return True if the user has at least the given auth level over this Machine."""
@@ -76,7 +74,7 @@ class Machine(Model):
# Get the Rack
try:
- rack = Rack.from_primary_key((self.rack_id,))
+ rack = Rack.from_primary_key((self.rack_id, ))
except exceptions.RowNotFoundError:
return False
@@ -102,7 +100,7 @@ class Machine(Model):
for device_table in self.device_table_to_attribute.keys():
statement = 'SELECT * FROM machine_{} WHERE machine_id = %s'.format(device_table)
- results = database.fetch_all(statement, (self.id,))
+ results = database.fetch_all(statement, (self.id, ))
device_ids = []
diff --git a/opendc/models/machine_state.py b/opendc/models/machine_state.py
index ba6d261f..3418f66e 100644
--- a/opendc/models/machine_state.py
+++ b/opendc/models/machine_state.py
@@ -14,8 +14,7 @@ class MachineState(Model):
}
COLLECTION_NAME = 'machine_states'
- COLUMNS = ['id', 'machine_id', 'experiment_id', 'tick', 'temperature_c', 'in_use_memory_mb',
- 'load_fraction']
+ COLUMNS = ['id', 'machine_id', 'experiment_id', 'tick', 'temperature_c', 'in_use_memory_mb', 'load_fraction']
COLUMNS_PRIMARY_KEY = ['id']
@@ -23,13 +22,7 @@ class MachineState(Model):
def _from_database_row(cls, row):
"""Instantiate a MachineState from a database row (including tick from the TaskState)."""
- return cls(
- machine_id=row[1],
- temperature_c=row[4],
- in_use_memory_mb=row[5],
- load_fraction=row[6],
- tick=row[3]
- )
+ return cls(machine_id=row[1], temperature_c=row[4], in_use_memory_mb=row[5], load_fraction=row[6], tick=row[3])
@classmethod
def from_experiment_id(cls, experiment_id):
@@ -38,7 +31,7 @@ class MachineState(Model):
machine_states = []
statement = 'SELECT * FROM machine_states WHERE experiment_id = %s'
- results = database.fetch_all(statement, (experiment_id,))
+ results = database.fetch_all(statement, (experiment_id, ))
for row in results:
machine_states.append(cls._from_database_row(row))
@@ -65,7 +58,7 @@ class MachineState(Model):
super(MachineState, self).read()
statement = 'SELECT tick FROM task_states WHERE id = %s'
- result = database.fetch_one(statement, (self.task_state_id,))
+ result = database.fetch_one(statement, (self.task_state_id, ))
self.tick = result[0]
diff --git a/opendc/models/memory.py b/opendc/models/memory.py
index 496c887f..17a79e14 100644
--- a/opendc/models/memory.py
+++ b/opendc/models/memory.py
@@ -19,14 +19,7 @@ class Memory(Model):
COLLECTION_NAME = 'memories'
COLUMNS = [
- 'id',
- 'manufacturer',
- 'family',
- 'generation',
- 'model',
- 'speed_mb_per_s',
- 'size_mb',
- 'energy_consumption_w',
+ 'id', 'manufacturer', 'family', 'generation', 'model', 'speed_mb_per_s', 'size_mb', 'energy_consumption_w',
'failure_model_id'
]
diff --git a/opendc/models/model.py b/opendc/models/model.py
index e9ce4f5e..896eb235 100644
--- a/opendc/models/model.py
+++ b/opendc/models/model.py
@@ -4,11 +4,7 @@ from opendc.util import database, exceptions
class Model(object):
# MUST OVERRIDE IN DERIVED CLASS
- JSON_TO_PYTHON_DICT = {
- 'Model': {
- 'jsonParameterName': 'python_parameter_name'
- }
- }
+ JSON_TO_PYTHON_DICT = {'Model': {'jsonParameterName': 'python_parameter_name'}}
PATH = ''
PATH_PARAMETERS = {}
@@ -33,10 +29,7 @@ class Model(object):
for attribute in self.COLUMNS_PRIMARY_KEY:
identifiers.append('{} = {}'.format(attribute, getattr(self, attribute)))
- return '{} ({})'.format(
- self.COLLECTION_NAME[:-1].title().replace('_', ''),
- '; '.join(identifiers)
- )
+ return '{} ({})'.format(self.COLLECTION_NAME[:-1].title().replace('_', ''), '; '.join(identifiers))
# JSON CONVERSION METHODS
@@ -120,9 +113,7 @@ class Model(object):
def _generate_update_columns_string(cls):
"""Generate a SQLite updatable columns string for this Model."""
- return ', '.join(
- ['{} = %s'.format(x) for x in cls.COLUMNS if x not in cls.COLUMNS_PRIMARY_KEY]
- )
+ return ', '.join(['{} = %s'.format(x) for x in cls.COLUMNS if x not in cls.COLUMNS_PRIMARY_KEY])
# SQL TUPLE GENERATION METHODS
@@ -182,10 +173,7 @@ class Model(object):
If the primary key does not exist in the database, return a stub.
"""
- query = 'SELECT * FROM {} WHERE {}'.format(
- cls.COLLECTION_NAME,
- cls._generate_primary_key_string()
- )
+ query = 'SELECT * FROM {} WHERE {}'.format(cls.COLLECTION_NAME, cls._generate_primary_key_string())
# Return an instantiation of the Model with values from the row if it exists
@@ -207,7 +195,7 @@ class Model(object):
if column_name is not None and value is not None:
statement = 'SELECT * FROM {} WHERE {} = %s'.format(cls.COLLECTION_NAME, column_name)
- database_models = database.fetch_all(statement, (value,))
+ database_models = database.fetch_all(statement, (value, ))
else:
statement = 'SELECT * FROM {}'.format(cls.COLLECTION_NAME)
@@ -230,10 +218,7 @@ class Model(object):
self.read()
- statement = 'DELETE FROM {} WHERE {}'.format(
- self.COLLECTION_NAME,
- self._generate_primary_key_string()
- )
+ statement = 'DELETE FROM {} WHERE {}'.format(self.COLLECTION_NAME, self._generate_primary_key_string())
values = self._generate_primary_key_tuple()
@@ -254,18 +239,12 @@ class Model(object):
"""
if column is None:
- query = query.format(
- self.COLLECTION_NAME,
- self._generate_primary_key_string()
- )
+ query = query.format(self.COLLECTION_NAME, self._generate_primary_key_string())
values = self._generate_primary_key_tuple()
else:
- query = query.format(
- self.COLLECTION_NAME,
- '{} = %s'.format(column)
- )
- values = (getattr(self, column),)
+ query = query.format(self.COLLECTION_NAME, '{} = %s'.format(column))
+ values = (getattr(self, column), )
return database.fetch_one(query, values)[0] == 1
@@ -280,11 +259,9 @@ class Model(object):
def insert_with_id(self, is_auto_generated=True):
"""Insert this Model into the database without removing its id."""
- statement = 'INSERT INTO {} ({}) VALUES ({})'.format(
- self.COLLECTION_NAME,
- self._generate_insert_columns_string(),
- self._generate_insert_placeholders_string()
- )
+ statement = 'INSERT INTO {} ({}) VALUES ({})'.format(self.COLLECTION_NAME,
+ self._generate_insert_columns_string(),
+ self._generate_insert_placeholders_string())
values = self._generate_insert_columns_tuple()
@@ -315,11 +292,8 @@ class Model(object):
def update(self):
"""Update this Model's non-primary key attributes in the database."""
- statement = 'UPDATE {} SET {} WHERE {}'.format(
- self.COLLECTION_NAME,
- self._generate_update_columns_string(),
- self._generate_primary_key_string()
- )
+ statement = 'UPDATE {} SET {} WHERE {}'.format(self.COLLECTION_NAME, self._generate_update_columns_string(),
+ self._generate_primary_key_string())
values = self._generate_update_columns_tuple() + self._generate_primary_key_tuple()
diff --git a/opendc/models/object.py b/opendc/models/object.py
index dab2f24e..2ce079af 100644
--- a/opendc/models/object.py
+++ b/opendc/models/object.py
@@ -2,12 +2,7 @@ from opendc.models.model import Model
class Object(Model):
- JSON_TO_PYTHON_DICT = {
- 'Object': {
- 'id': 'id',
- 'type': 'type'
- }
- }
+ JSON_TO_PYTHON_DICT = {'Object': {'id': 'id', 'type': 'type'}}
COLLECTION_NAME = 'objects'
COLUMNS = ['id', 'type']
diff --git a/opendc/models/queued_experiment.py b/opendc/models/queued_experiment.py
index cd00a495..b59cfedc 100644
--- a/opendc/models/queued_experiment.py
+++ b/opendc/models/queued_experiment.py
@@ -2,11 +2,7 @@ from opendc.models.model import Model
class QueuedExperiment(Model):
- JSON_TO_PYTHON_DICT = {
- 'QueuedExperiment': {
- 'experimentId': 'experiment_id'
- }
- }
+ JSON_TO_PYTHON_DICT = {'QueuedExperiment': {'experimentId': 'experiment_id'}}
COLLECTION_NAME = 'queued_experiments'
COLUMNS = ['experiment_id']
diff --git a/opendc/models/rack.py b/opendc/models/rack.py
index 7b085a57..52cb0ffe 100644
--- a/opendc/models/rack.py
+++ b/opendc/models/rack.py
@@ -24,12 +24,12 @@ class Rack(Model):
def from_tile_id(cls, tile_id):
"""Get a Rack from the ID of the Tile it's on."""
- tile = Tile.from_primary_key((tile_id,))
+ tile = Tile.from_primary_key((tile_id, ))
if not tile.exists():
return Rack(id=-1)
- return cls.from_primary_key((tile.object_id,))
+ return cls.from_primary_key((tile.object_id, ))
def google_id_has_at_least(self, google_id, authorization_level):
"""Return True if the user has at least the given auth level over this Rack."""
@@ -57,5 +57,5 @@ class Rack(Model):
def delete(self):
"""Delete a Rack by deleting its associated object."""
- obj = Object.from_primary_key((self.id,))
+ obj = Object.from_primary_key((self.id, ))
obj.delete()
diff --git a/opendc/models/rack_state.py b/opendc/models/rack_state.py
index 440ab293..a261fce0 100644
--- a/opendc/models/rack_state.py
+++ b/opendc/models/rack_state.py
@@ -3,23 +3,13 @@ from opendc.util import database
class RackState(Model):
- JSON_TO_PYTHON_DICT = {
- 'RackState': {
- 'rackId': 'rack_id',
- 'loadFraction': 'load_fraction',
- 'tick': 'tick'
- }
- }
+ JSON_TO_PYTHON_DICT = {'RackState': {'rackId': 'rack_id', 'loadFraction': 'load_fraction', 'tick': 'tick'}}
@classmethod
def _from_database_row(cls, row):
"""Instantiate a RackState from a database row."""
- return cls(
- rack_id=row[0],
- load_fraction=row[1],
- tick=row[2]
- )
+ return cls(rack_id=row[0], load_fraction=row[1], tick=row[2])
@classmethod
def from_experiment_id(cls, experiment_id):
@@ -35,7 +25,7 @@ class RackState(Model):
WHERE machine_states.experiment_id = %s
GROUP BY machine_states.tick, racks.id
'''
- results = database.fetch_all(statement, (experiment_id,))
+ results = database.fetch_all(statement, (experiment_id, ))
for row in results:
rack_states.append(cls._from_database_row(row))
diff --git a/opendc/models/room.py b/opendc/models/room.py
index a4266627..6a7627f5 100644
--- a/opendc/models/room.py
+++ b/opendc/models/room.py
@@ -26,7 +26,7 @@ class Room(Model):
# Get the Datacenter
try:
- datacenter = Datacenter.from_primary_key((self.datacenter_id,))
+ datacenter = Datacenter.from_primary_key((self.datacenter_id, ))
except exceptions.RowNotFoundError:
return False
diff --git a/opendc/models/room_state.py b/opendc/models/room_state.py
index 2404d86b..4326a32b 100644
--- a/opendc/models/room_state.py
+++ b/opendc/models/room_state.py
@@ -3,23 +3,13 @@ from opendc.util import database
class RoomState(Model):
- JSON_TO_PYTHON_DICT = {
- 'RoomState': {
- 'roomId': 'room_id',
- 'loadFraction': 'load_fraction',
- 'tick': 'tick'
- }
- }
+ JSON_TO_PYTHON_DICT = {'RoomState': {'roomId': 'room_id', 'loadFraction': 'load_fraction', 'tick': 'tick'}}
@classmethod
def _from_database_row(cls, row):
"""Instantiate a RoomState from a database row."""
- return cls(
- room_id=row[0],
- load_fraction=row[1],
- tick=row[2]
- )
+ return cls(room_id=row[0], load_fraction=row[1], tick=row[2])
@classmethod
def from_experiment_id(cls, experiment_id):
@@ -39,7 +29,7 @@ class RoomState(Model):
AND machine_states.experiment_id = %s
GROUP BY machine_states.tick, rooms.id
'''
- results = database.fetch_all(statement, (experiment_id,))
+ results = database.fetch_all(statement, (experiment_id, ))
for row in results:
room_states.append(cls._from_database_row(row))
diff --git a/opendc/models/room_type.py b/opendc/models/room_type.py
index c252e4fe..b91c1e67 100644
--- a/opendc/models/room_type.py
+++ b/opendc/models/room_type.py
@@ -2,11 +2,7 @@ from opendc.models.model import Model
class RoomType(Model):
- JSON_TO_PYTHON_DICT = {
- 'RoomType': {
- 'name': 'name'
- }
- }
+ JSON_TO_PYTHON_DICT = {'RoomType': {'name': 'name'}}
COLLECTION_NAME = 'room_types'
COLUMNS = ['name']
diff --git a/opendc/models/scheduler.py b/opendc/models/scheduler.py
index c9523ce2..c3c98b7a 100644
--- a/opendc/models/scheduler.py
+++ b/opendc/models/scheduler.py
@@ -2,11 +2,7 @@ from opendc.models.model import Model
class Scheduler(Model):
- JSON_TO_PYTHON_DICT = {
- 'Scheduler': {
- 'name': 'name'
- }
- }
+ JSON_TO_PYTHON_DICT = {'Scheduler': {'name': 'name'}}
COLLECTION_NAME = 'schedulers'
COLUMNS = ['name']
diff --git a/opendc/models/section.py b/opendc/models/section.py
index 53b5e6c9..2fd71068 100644
--- a/opendc/models/section.py
+++ b/opendc/models/section.py
@@ -23,7 +23,7 @@ class Section(Model):
# Get the Path
try:
- path = Path.from_primary_key((self.path_id,))
+ path = Path.from_primary_key((self.path_id, ))
except exceptions.RowNotFoundError:
return False
diff --git a/opendc/models/storage.py b/opendc/models/storage.py
index 3f84ba5e..93cc8b68 100644
--- a/opendc/models/storage.py
+++ b/opendc/models/storage.py
@@ -19,14 +19,7 @@ class Storage(Model):
COLLECTION_NAME = 'storages'
COLUMNS = [
- 'id',
- 'manufacturer',
- 'family',
- 'generation',
- 'model',
- 'speed_mb_per_s',
- 'size_mb',
- 'energy_consumption_w',
+ 'id', 'manufacturer', 'family', 'generation', 'model', 'speed_mb_per_s', 'size_mb', 'energy_consumption_w',
'failure_model_id'
]
diff --git a/opendc/models/task_duration.py b/opendc/models/task_duration.py
index 14cbc31a..ad6459ab 100644
--- a/opendc/models/task_duration.py
+++ b/opendc/models/task_duration.py
@@ -3,21 +3,13 @@ from opendc.util import database
class TaskDuration(Model):
- JSON_TO_PYTHON_DICT = {
- 'TaskDuration': {
- 'taskId': 'task_id',
- 'duration': 'duration'
- }
- }
+ JSON_TO_PYTHON_DICT = {'TaskDuration': {'taskId': 'task_id', 'duration': 'duration'}}
@classmethod
def _from_database_row(cls, row):
"""Instantiate a RoomState from a database row."""
- return cls(
- task_id=row[0],
- duration=row[1]
- )
+ return cls(task_id=row[0], duration=row[1])
@classmethod
def from_experiment_id(cls, experiment_id):
@@ -31,7 +23,7 @@ class TaskDuration(Model):
GROUP BY task_id
'''
- results = database.fetch_all(statement, (experiment_id,))
+ results = database.fetch_all(statement, (experiment_id, ))
for row in results:
room_states.append(cls._from_database_row(row))
diff --git a/opendc/models/task_state.py b/opendc/models/task_state.py
index ad78cc67..2cef20ee 100644
--- a/opendc/models/task_state.py
+++ b/opendc/models/task_state.py
@@ -29,15 +29,7 @@ class TaskState(Model):
results = database.fetch_all(statement, (experiment_id, tick))
for row in results:
- task_states.append(
- cls(
- id=row[0],
- task_id=row[1],
- experiment_id=row[2],
- tick=row[3],
- flops_left=row[4]
- )
- )
+ task_states.append(cls(id=row[0], task_id=row[1], experiment_id=row[2], tick=row[3], flops_left=row[4]))
return task_states
diff --git a/opendc/models/tile.py b/opendc/models/tile.py
index ac22ccac..a945564f 100644
--- a/opendc/models/tile.py
+++ b/opendc/models/tile.py
@@ -29,7 +29,7 @@ class Tile(Model):
# Get the Room
try:
- room = Room.from_primary_key((self.room_id,))
+ room = Room.from_primary_key((self.room_id, ))
except exceptions.RowNotFoundError:
return False
@@ -43,5 +43,5 @@ class Tile(Model):
super(Tile, self).read()
if self.object_id is not None:
- obj = Object.from_primary_key((self.object_id,))
+ obj = Object.from_primary_key((self.object_id, ))
self.object_type = obj.type
diff --git a/opendc/models/trace.py b/opendc/models/trace.py
index 2f5e33cd..f6d2e1c1 100644
--- a/opendc/models/trace.py
+++ b/opendc/models/trace.py
@@ -2,12 +2,7 @@ from opendc.models.model import Model
class Trace(Model):
- JSON_TO_PYTHON_DICT = {
- 'Trace': {
- 'id': 'id',
- 'name': 'name'
- }
- }
+ JSON_TO_PYTHON_DICT = {'Trace': {'id': 'id', 'name': 'name'}}
COLLECTION_NAME = 'traces'
COLUMNS = ['id', 'name']
diff --git a/opendc/models/user.py b/opendc/models/user.py
index 0406c31c..df3a4e76 100644
--- a/opendc/models/user.py
+++ b/opendc/models/user.py
@@ -20,7 +20,7 @@ class User(Model):
def from_google_id(cls, google_id):
"""Initialize a User by fetching them by their google id."""
- user = cls._from_database('SELECT * FROM users WHERE google_id = %s', (google_id,))
+ user = cls._from_database('SELECT * FROM users WHERE google_id = %s', (google_id, ))
if user is not None:
return user
@@ -31,7 +31,7 @@ class User(Model):
def from_email(cls, email):
"""Initialize a User by fetching them by their email."""
- user = cls._from_database('SELECT * FROM users WHERE email = %s', (email,))
+ user = cls._from_database('SELECT * FROM users WHERE email = %s', (email, ))
if user is not None:
return user
diff --git a/opendc/util/exceptions.py b/opendc/util/exceptions.py
index 8eea268a..caf6dd8e 100644
--- a/opendc/util/exceptions.py
+++ b/opendc/util/exceptions.py
@@ -27,11 +27,8 @@ class ForeignKeyError(Exception):
class RowNotFoundError(Exception):
"""Raised when a database row is not found."""
-
def __init__(self, table_name):
- super(RowNotFoundError, self).__init__(
- 'Row in `{}` table not found.'.format(table_name)
- )
+ super(RowNotFoundError, self).__init__('Row in `{}` table not found.'.format(table_name))
self.table_name = table_name
@@ -42,14 +39,9 @@ class ParameterError(Exception):
class IncorrectParameterError(ParameterError):
"""Raised when a parameter is of the wrong type."""
-
def __init__(self, parameter_name, parameter_location):
- super(IncorrectParameterError, self).__init__(
- 'Incorrectly typed `{}` {} parameter.'.format(
- parameter_name,
- parameter_location
- )
- )
+ super(IncorrectParameterError,
+ self).__init__('Incorrectly typed `{}` {} parameter.'.format(parameter_name, parameter_location))
self.parameter_name = parameter_name
self.parameter_location = parameter_location
@@ -57,14 +49,9 @@ class IncorrectParameterError(ParameterError):
class MissingParameterError(ParameterError):
"""Raised when a parameter is missing."""
-
def __init__(self, parameter_name, parameter_location):
- super(MissingParameterError, self).__init__(
- 'Missing required `{}` {} parameter.'.format(
- parameter_name,
- parameter_location
- )
- )
+ super(MissingParameterError,
+ self).__init__('Missing required `{}` {} parameter.'.format(parameter_name, parameter_location))
self.parameter_name = parameter_name
self.parameter_location = parameter_location
diff --git a/opendc/util/parameter_checker.py b/opendc/util/parameter_checker.py
index c60d26d3..561ed497 100644
--- a/opendc/util/parameter_checker.py
+++ b/opendc/util/parameter_checker.py
@@ -14,11 +14,7 @@ def _missing_parameter(params_required, params_actual, parent=''):
if isinstance(param_required, dict):
- param_missing = _missing_parameter(
- param_required,
- param_actual,
- param_name
- )
+ param_missing = _missing_parameter(param_required, param_actual, param_name)
if param_missing is not None:
return '{}.{}'.format(parent, param_missing)
@@ -36,11 +32,7 @@ def _incorrect_parameter(params_required, params_actual, parent=''):
if isinstance(param_required, dict):
- param_incorrect = _incorrect_parameter(
- param_required,
- param_actual,
- param_name
- )
+ param_incorrect = _incorrect_parameter(param_required, param_actual, param_name)
if param_incorrect is not None:
return '{}.{}'.format(parent, param_incorrect)
@@ -80,14 +72,8 @@ def check(request, **kwargs):
missing_parameter = _missing_parameter(params_required, params_actual)
if missing_parameter is not None:
- raise exceptions.MissingParameterError(
- _format_parameter(missing_parameter),
- location
- )
+ raise exceptions.MissingParameterError(_format_parameter(missing_parameter), location)
incorrect_parameter = _incorrect_parameter(params_required, params_actual)
if incorrect_parameter is not None:
- raise exceptions.IncorrectParameterError(
- _format_parameter(incorrect_parameter),
- location
- )
+ raise exceptions.IncorrectParameterError(_format_parameter(incorrect_parameter), location)
diff --git a/opendc/util/rest.py b/opendc/util/rest.py
index 85da4eaa..d5df5306 100644
--- a/opendc/util/rest.py
+++ b/opendc/util/rest.py
@@ -12,7 +12,6 @@ with open(sys.argv[1]) as f:
class Request(object):
"""WebSocket message to REST request mapping."""
-
def __init__(self, message=None):
""""Initialize a Request from a socket message."""
@@ -52,9 +51,7 @@ class Request(object):
raise exceptions.UnimplementedEndpointError('Non-ASCII path')
except ImportError:
- raise exceptions.UnimplementedEndpointError(
- 'Unimplemented endpoint: {}.'.format(self.path)
- )
+ raise exceptions.UnimplementedEndpointError('Unimplemented endpoint: {}.'.format(self.path))
# Check the method
@@ -62,8 +59,8 @@ class Request(object):
raise exceptions.UnsupportedMethodError('Non-rest method: {}'.format(self.method))
if not hasattr(self.module, self.method):
- raise exceptions.UnsupportedMethodError(
- 'Unimplemented method at endpoint {}: {}'.format(self.path, self.method))
+ raise exceptions.UnsupportedMethodError('Unimplemented method at endpoint {}: {}'.format(
+ self.path, self.method))
# Verify the user
@@ -118,23 +115,16 @@ class Request(object):
class Response(object):
"""Response to websocket mapping"""
-
def __init__(self, status_code, status_description, content=None):
"""Initialize a new Response."""
- self.status = {
- 'code': status_code,
- 'description': status_description
- }
+ self.status = {'code': status_code, 'description': status_description}
self.content = content
def to_JSON(self):
""""Return a JSON representation of this Response"""
- data = {
- 'id': self.id,
- 'status': self.status
- }
+ data = {'id': self.id, 'status': self.status}
if self.content is not None:
data['content'] = self.content