summaryrefslogtreecommitdiff
path: root/opendc/api/v1/simulations/simulationId
diff options
context:
space:
mode:
authorGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-25 13:50:49 +0200
committerGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-25 13:50:49 +0200
commita1589e75358558eada7ffc2efc7e3fa7160d233e (patch)
tree7889a2364292cd8b90fe996da7907bebf200d3dc /opendc/api/v1/simulations/simulationId
parent1f34466d41ba01a3dd36b0866696367d397daf7e (diff)
Reformat codebase and fix spelling errors
Diffstat (limited to 'opendc/api/v1/simulations/simulationId')
-rw-r--r--opendc/api/v1/simulations/simulationId/authorizations/endpoint.py5
-rw-r--r--opendc/api/v1/simulations/simulationId/authorizations/userId/endpoint.py32
-rw-r--r--opendc/api/v1/simulations/simulationId/datacenters/endpoint.py7
-rw-r--r--opendc/api/v1/simulations/simulationId/endpoint.py19
-rw-r--r--opendc/api/v1/simulations/simulationId/experiments/endpoint.py15
-rw-r--r--opendc/api/v1/simulations/simulationId/paths/endpoint.py5
6 files changed, 46 insertions, 37 deletions
diff --git a/opendc/api/v1/simulations/simulationId/authorizations/endpoint.py b/opendc/api/v1/simulations/simulationId/authorizations/endpoint.py
index d880564e..1d6b494e 100644
--- a/opendc/api/v1/simulations/simulationId/authorizations/endpoint.py
+++ b/opendc/api/v1/simulations/simulationId/authorizations/endpoint.py
@@ -1,8 +1,9 @@
from opendc.models.authorization import Authorization
from opendc.models.simulation import Simulation
-from opendc.util import database, exceptions
+from opendc.util import exceptions
from opendc.util.rest import Response
+
def GET(request):
"""Find all authorizations for a Simulation."""
@@ -10,7 +11,7 @@ def GET(request):
try:
request.check_required_parameters(
- path = {
+ path={
'simulationId': 'int'
}
)
diff --git a/opendc/api/v1/simulations/simulationId/authorizations/userId/endpoint.py b/opendc/api/v1/simulations/simulationId/authorizations/userId/endpoint.py
index c3e599cf..46458ffc 100644
--- a/opendc/api/v1/simulations/simulationId/authorizations/userId/endpoint.py
+++ b/opendc/api/v1/simulations/simulationId/authorizations/userId/endpoint.py
@@ -1,9 +1,10 @@
from opendc.models.authorization import Authorization
from opendc.models.simulation import Simulation
from opendc.models.user import User
-from opendc.util import database, exceptions
+from opendc.util import exceptions
from opendc.util.rest import Response
+
def DELETE(request):
"""Delete a user's authorization level over a simulation."""
@@ -11,7 +12,7 @@ def DELETE(request):
try:
request.check_required_parameters(
- path = {
+ path={
'simulationId': 'int',
'userId': 'int'
}
@@ -21,7 +22,7 @@ def DELETE(request):
return Response(400, e.message)
# Instantiate an Authorization
-
+
authorization = Authorization.from_primary_key((
request.params_path['userId'],
request.params_path['simulationId']
@@ -30,7 +31,7 @@ def DELETE(request):
# Make sure this Authorization exists in the database
if not authorization.exists():
- return Response (404, '{} not found.'.format(authorization))
+ return Response(404, '{} not found.'.format(authorization))
# Make sure this User is allowed to delete this Authorization
@@ -47,14 +48,15 @@ def DELETE(request):
authorization.to_JSON()
)
+
def GET(request):
"""Get this User's Authorization over this Simulation."""
-
+
# Make sure required parameters are there
try:
request.check_required_parameters(
- path = {
+ path={
'simulationId': 'int',
'userId': 'int'
}
@@ -62,7 +64,7 @@ def GET(request):
except exceptions.ParameterError as e:
return Response(400, e.message)
-
+
# Instantiate an Authorization
authorization = Authorization.from_primary_key((
@@ -87,6 +89,7 @@ def GET(request):
authorization.to_JSON()
)
+
def POST(request):
"""Add an authorization for a user's access to a simulation."""
@@ -94,11 +97,11 @@ def POST(request):
try:
request.check_required_parameters(
- path = {
+ path={
'userId': 'int',
'simulationId': 'int'
},
- body = {
+ body={
'authorization': {
'authorizationLevel': 'string'
}
@@ -143,7 +146,7 @@ def POST(request):
except exceptions.ForeignKeyError:
return Response(400, 'Invalid authorizationLevel')
-
+
# Return this Authorization
return Response(
@@ -152,6 +155,7 @@ def POST(request):
authorization.to_JSON()
)
+
def PUT(request):
"""Change a user's authorization level over a simulation."""
@@ -159,11 +163,11 @@ def PUT(request):
try:
request.check_required_parameters(
- path = {
+ path={
'simulationId': 'int',
'userId': 'int'
},
- body = {
+ body={
'authorization': {
'authorizationLevel': 'string'
}
@@ -192,7 +196,7 @@ def PUT(request):
return Response(403, 'Forbidden from updating {}.'.format(authorization))
# Try to update this Authorization
-
+
try:
authorization.update()
@@ -200,7 +204,7 @@ def PUT(request):
return Response(400, 'Invalid authorization level.')
# Return this Authorization
-
+
return Response(
200,
'Successfully updated {}.'.format(authorization),
diff --git a/opendc/api/v1/simulations/simulationId/datacenters/endpoint.py b/opendc/api/v1/simulations/simulationId/datacenters/endpoint.py
index d53cd1c8..e28402e4 100644
--- a/opendc/api/v1/simulations/simulationId/datacenters/endpoint.py
+++ b/opendc/api/v1/simulations/simulationId/datacenters/endpoint.py
@@ -1,8 +1,9 @@
from opendc.models.datacenter import Datacenter
from opendc.models.simulation import Simulation
-from opendc.util import database, exceptions
+from opendc.util import exceptions
from opendc.util.rest import Response
+
def POST(request):
"""Add a new Datacenter to this Simulation."""
@@ -10,10 +11,10 @@ def POST(request):
try:
request.check_required_parameters(
- path = {
+ path={
'simulationId': 'int'
},
- body = {
+ body={
'datacenter': {
'starred': 'int',
'simulationId': 'int'
diff --git a/opendc/api/v1/simulations/simulationId/endpoint.py b/opendc/api/v1/simulations/simulationId/endpoint.py
index 01623973..5e595740 100644
--- a/opendc/api/v1/simulations/simulationId/endpoint.py
+++ b/opendc/api/v1/simulations/simulationId/endpoint.py
@@ -1,11 +1,10 @@
from datetime import datetime
-from opendc.models.authorization import Authorization
from opendc.models.simulation import Simulation
-from opendc.models.user import User
from opendc.util import database, exceptions
from opendc.util.rest import Response
+
def DELETE(request):
"""Delete this Simulation."""
@@ -13,14 +12,14 @@ def DELETE(request):
try:
request.check_required_parameters(
- path = {
+ 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'],))
@@ -45,6 +44,7 @@ def DELETE(request):
simulation.to_JSON()
)
+
def GET(request):
"""Get this Simulation."""
@@ -52,7 +52,7 @@ def GET(request):
try:
request.check_required_parameters(
- path = {
+ path={
'simulationId': 'int'
}
)
@@ -82,6 +82,7 @@ def GET(request):
simulation.to_JSON()
)
+
def PUT(request):
"""Update a simulation's name."""
@@ -89,12 +90,12 @@ def PUT(request):
try:
request.check_required_parameters(
- body = {
+ body={
'simulation': {
'name': 'name'
}
},
- path = {
+ path={
'simulationId': 'int'
}
)
@@ -115,7 +116,7 @@ def PUT(request):
return Response(403, 'Forbidden from editing {}.'.format(simulation))
# Update this Simulation in the database
-
+
simulation.read()
simulation.name = request.params_body['simulation']['name']
diff --git a/opendc/api/v1/simulations/simulationId/experiments/endpoint.py b/opendc/api/v1/simulations/simulationId/experiments/endpoint.py
index 034e82a1..86fadb24 100644
--- a/opendc/api/v1/simulations/simulationId/experiments/endpoint.py
+++ b/opendc/api/v1/simulations/simulationId/experiments/endpoint.py
@@ -1,9 +1,9 @@
from opendc.models.experiment import Experiment
-from opendc.models.queued_experiment import QueuedExperiment
from opendc.models.simulation import Simulation
-from opendc.util import database, exceptions
+from opendc.util import exceptions
from opendc.util.rest import Response
+
def GET(request):
"""Get this Simulation's Experiments."""
@@ -11,7 +11,7 @@ def GET(request):
try:
request.check_required_parameters(
- path = {
+ path={
'simulationId': 'int'
}
)
@@ -43,6 +43,7 @@ def GET(request):
[x.to_JSON() for x in experiments]
)
+
def POST(request):
"""Add a new Experiment for this Simulation."""
@@ -50,10 +51,10 @@ def POST(request):
try:
request.check_required_parameters(
- path = {
+ path={
'simulationId': 'int'
},
- body = {
+ body={
'experiment': {
'simulationId': 'int',
'pathId': 'int',
@@ -96,12 +97,12 @@ def POST(request):
try:
experiment.insert()
-
+
except exceptions.ForeignKeyError as e:
return Response(400, 'Foreign key constraint not met.' + e.message)
# Return this Experiment
-
+
experiment.read()
return Response(
diff --git a/opendc/api/v1/simulations/simulationId/paths/endpoint.py b/opendc/api/v1/simulations/simulationId/paths/endpoint.py
index e74c8d22..e4aab427 100644
--- a/opendc/api/v1/simulations/simulationId/paths/endpoint.py
+++ b/opendc/api/v1/simulations/simulationId/paths/endpoint.py
@@ -1,8 +1,9 @@
from opendc.models.path import Path
from opendc.models.simulation import Simulation
-from opendc.util import database, exceptions
+from opendc.util import exceptions
from opendc.util.rest import Response
+
def GET(request):
"""Get this Simulation's Paths."""
@@ -10,7 +11,7 @@ def GET(request):
try:
request.check_required_parameters(
- path = {
+ path={
'simulationId': 'int'
}
)