diff options
| author | Georgios Andreadis <info@gandreadis.com> | 2020-06-25 14:48:24 +0200 |
|---|---|---|
| committer | Georgios Andreadis <info@gandreadis.com> | 2020-06-25 14:48:24 +0200 |
| commit | ff31029e732dd56743690dc608f535163a0548ff (patch) | |
| tree | 04fe8e4a17816d93db386b5b6c560be654cdee86 /opendc | |
| parent | c2706e023070211f8ac992b800353807a1f10886 (diff) | |
Experiment
Diffstat (limited to 'opendc')
77 files changed, 203 insertions, 183 deletions
diff --git a/opendc/api/v2/datacenters/datacenterId/endpoint.py b/opendc/api/v2/datacenters/datacenterId/endpoint.py index 3265abb2..67fbfcd8 100644 --- a/opendc/api/v2/datacenters/datacenterId/endpoint.py +++ b/opendc/api/v2/datacenters/datacenterId/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.datacenter import Datacenter +from opendc.models_old.datacenter import Datacenter from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/datacenters/datacenterId/rooms/endpoint.py b/opendc/api/v2/datacenters/datacenterId/rooms/endpoint.py index 593b38a7..96ee7028 100644 --- a/opendc/api/v2/datacenters/datacenterId/rooms/endpoint.py +++ b/opendc/api/v2/datacenters/datacenterId/rooms/endpoint.py @@ -1,5 +1,5 @@ -from opendc.models.datacenter import Datacenter -from opendc.models.room import Room +from opendc.models_old.datacenter import Datacenter +from opendc.models_old.room import Room from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/experiments/experimentId/endpoint.py b/opendc/api/v2/experiments/experimentId/endpoint.py index 4ae4abf2..bc2b139e 100644 --- a/opendc/api/v2/experiments/experimentId/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.experiment import Experiment +from opendc.models_old.experiment import Experiment from opendc.util import exceptions from opendc.util.rest import Response 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 554c03b5..3309502c 100644 --- a/opendc/api/v2/experiments/experimentId/last-simulated-tick/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/last-simulated-tick/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.experiment import Experiment +from opendc.models_old.experiment import Experiment from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/experiments/experimentId/machine-states/endpoint.py b/opendc/api/v2/experiments/experimentId/machine-states/endpoint.py index e903e691..c7dcad9a 100644 --- a/opendc/api/v2/experiments/experimentId/machine-states/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/machine-states/endpoint.py @@ -1,5 +1,5 @@ -from opendc.models.experiment import Experiment -from opendc.models.machine_state import MachineState +from opendc.models_old.experiment import Experiment +from opendc.models_old.machine_state import MachineState from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/experiments/experimentId/rack-states/endpoint.py b/opendc/api/v2/experiments/experimentId/rack-states/endpoint.py index a1841bf0..f3acf56a 100644 --- a/opendc/api/v2/experiments/experimentId/rack-states/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/rack-states/endpoint.py @@ -1,5 +1,5 @@ -from opendc.models.experiment import Experiment -from opendc.models.rack_state import RackState +from opendc.models_old.experiment import Experiment +from opendc.models_old.rack_state import RackState from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/experiments/experimentId/room-states/endpoint.py b/opendc/api/v2/experiments/experimentId/room-states/endpoint.py index 19ecec22..db3f8b14 100644 --- a/opendc/api/v2/experiments/experimentId/room-states/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/room-states/endpoint.py @@ -1,5 +1,5 @@ -from opendc.models.experiment import Experiment -from opendc.models.room_state import RoomState +from opendc.models_old.experiment import Experiment +from opendc.models_old.room_state import RoomState from opendc.util import exceptions from opendc.util.rest import Response 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 6bc0d4bd..498db239 100644 --- a/opendc/api/v2/experiments/experimentId/statistics/task-durations/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/statistics/task-durations/endpoint.py @@ -1,5 +1,5 @@ -from opendc.models.experiment import Experiment -from opendc.models.task_duration import TaskDuration +from opendc.models_old.experiment import Experiment +from opendc.models_old.task_duration import TaskDuration from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/experiments/experimentId/task-states/endpoint.py b/opendc/api/v2/experiments/experimentId/task-states/endpoint.py index b4d8a702..c0ae47fc 100644 --- a/opendc/api/v2/experiments/experimentId/task-states/endpoint.py +++ b/opendc/api/v2/experiments/experimentId/task-states/endpoint.py @@ -1,5 +1,5 @@ -from opendc.models.experiment import Experiment -from opendc.models.task_state import TaskState +from opendc.models_old.experiment import Experiment +from opendc.models_old.task_state import TaskState from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/jobs/jobId/endpoint.py b/opendc/api/v2/jobs/jobId/endpoint.py index 4dc43728..45eedf3f 100644 --- a/opendc/api/v2/jobs/jobId/endpoint.py +++ b/opendc/api/v2/jobs/jobId/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.job import Job +from opendc.models_old.job import Job from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/jobs/jobId/tasks/endpoint.py b/opendc/api/v2/jobs/jobId/tasks/endpoint.py index f2cb3384..cae5ac90 100644 --- a/opendc/api/v2/jobs/jobId/tasks/endpoint.py +++ b/opendc/api/v2/jobs/jobId/tasks/endpoint.py @@ -1,5 +1,5 @@ -from opendc.models.job import Job -from opendc.models.task import Task +from opendc.models_old.job import Job +from opendc.models_old.task import Task from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/paths/pathId/branches/endpoint.py b/opendc/api/v2/paths/pathId/branches/endpoint.py index d3256e8c..6b0eebbd 100644 --- a/opendc/api/v2/paths/pathId/branches/endpoint.py +++ b/opendc/api/v2/paths/pathId/branches/endpoint.py @@ -1,13 +1,13 @@ from datetime import datetime -from opendc.models.datacenter import Datacenter -from opendc.models.machine import Machine -from opendc.models.object import Object -from opendc.models.path import Path -from opendc.models.rack import Rack -from opendc.models.room import Room -from opendc.models.section import Section -from opendc.models.tile import Tile +from opendc.models_old.datacenter import Datacenter +from opendc.models_old.machine import Machine +from opendc.models_old.object import Object +from opendc.models_old.path import Path +from opendc.models_old.rack import Rack +from opendc.models_old.room import Room +from opendc.models_old.section import Section +from opendc.models_old.tile import Tile from opendc.util import database, exceptions from opendc.util.rest import Request, Response diff --git a/opendc/api/v2/paths/pathId/endpoint.py b/opendc/api/v2/paths/pathId/endpoint.py index 42357fc5..a3348618 100644 --- a/opendc/api/v2/paths/pathId/endpoint.py +++ b/opendc/api/v2/paths/pathId/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.path import Path +from opendc.models_old.path import Path from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/paths/pathId/sections/endpoint.py b/opendc/api/v2/paths/pathId/sections/endpoint.py index a983ff1f..8f3e270b 100644 --- a/opendc/api/v2/paths/pathId/sections/endpoint.py +++ b/opendc/api/v2/paths/pathId/sections/endpoint.py @@ -1,5 +1,5 @@ -from opendc.models.path import Path -from opendc.models.section import Section +from opendc.models_old.path import Path +from opendc.models_old.section import Section from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/room-types/endpoint.py b/opendc/api/v2/room-types/endpoint.py index 14675c86..71efc75d 100644 --- a/opendc/api/v2/room-types/endpoint.py +++ b/opendc/api/v2/room-types/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.room_type import RoomType +from opendc.models_old.room_type import RoomType from opendc.util.rest import Response 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 166781e8..7b605c2b 100644 --- a/opendc/api/v2/room-types/name/allowed-objects/endpoint.py +++ b/opendc/api/v2/room-types/name/allowed-objects/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.allowed_object import AllowedObject +from opendc.models_old.allowed_object import AllowedObject from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/rooms/roomId/endpoint.py b/opendc/api/v2/rooms/roomId/endpoint.py index 90bcdfd6..663760aa 100644 --- a/opendc/api/v2/rooms/roomId/endpoint.py +++ b/opendc/api/v2/rooms/roomId/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.room import Room +from opendc.models_old.room import Room from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/rooms/roomId/tiles/endpoint.py b/opendc/api/v2/rooms/roomId/tiles/endpoint.py index 971514ec..3385dd36 100644 --- a/opendc/api/v2/rooms/roomId/tiles/endpoint.py +++ b/opendc/api/v2/rooms/roomId/tiles/endpoint.py @@ -1,5 +1,5 @@ -from opendc.models.room import Room -from opendc.models.tile import Tile +from opendc.models_old.room import Room +from opendc.models_old.tile import Tile from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/schedulers/endpoint.py b/opendc/api/v2/schedulers/endpoint.py index 224ecfb8..4f3948a9 100644 --- a/opendc/api/v2/schedulers/endpoint.py +++ b/opendc/api/v2/schedulers/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.scheduler import Scheduler +from opendc.models_old.scheduler import Scheduler from opendc.util.rest import Response diff --git a/opendc/api/v2/sections/sectionId/endpoint.py b/opendc/api/v2/sections/sectionId/endpoint.py index 80e15328..58af44b5 100644 --- a/opendc/api/v2/sections/sectionId/endpoint.py +++ b/opendc/api/v2/sections/sectionId/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.section import Section +from opendc.models_old.section import Section from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/simulations/endpoint.py b/opendc/api/v2/simulations/endpoint.py index 3eb7e903..7ef90e97 100644 --- a/opendc/api/v2/simulations/endpoint.py +++ b/opendc/api/v2/simulations/endpoint.py @@ -1,11 +1,11 @@ from datetime import datetime -from opendc.models.authorization import Authorization -from opendc.models.datacenter import Datacenter -from opendc.models.path import Path -from opendc.models.section import Section -from opendc.models.simulation import Simulation -from opendc.models.user import User +from opendc.models_old.authorization import Authorization +from opendc.models_old.datacenter import Datacenter +from opendc.models_old.path import Path +from opendc.models_old.section import Section +from opendc.models_old.simulation import Simulation +from opendc.models_old.user import User from opendc.util import database, exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/simulations/simulationId/authorizations/endpoint.py b/opendc/api/v2/simulations/simulationId/authorizations/endpoint.py index b0a54524..bc1a7dc3 100644 --- a/opendc/api/v2/simulations/simulationId/authorizations/endpoint.py +++ b/opendc/api/v2/simulations/simulationId/authorizations/endpoint.py @@ -1,5 +1,5 @@ -from opendc.models.authorization import Authorization -from opendc.models.simulation import Simulation +from opendc.models_old.authorization import Authorization +from opendc.models_old.simulation import Simulation from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/simulations/simulationId/authorizations/userId/endpoint.py b/opendc/api/v2/simulations/simulationId/authorizations/userId/endpoint.py index 19d13a65..d132b1dd 100644 --- a/opendc/api/v2/simulations/simulationId/authorizations/userId/endpoint.py +++ b/opendc/api/v2/simulations/simulationId/authorizations/userId/endpoint.py @@ -1,6 +1,6 @@ -from opendc.models.authorization import Authorization -from opendc.models.simulation import Simulation -from opendc.models.user import User +from opendc.models_old.authorization import Authorization +from opendc.models_old.simulation import Simulation +from opendc.models_old.user import User from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/simulations/simulationId/datacenters/endpoint.py b/opendc/api/v2/simulations/simulationId/datacenters/endpoint.py index c1d49228..dbef2e8f 100644 --- a/opendc/api/v2/simulations/simulationId/datacenters/endpoint.py +++ b/opendc/api/v2/simulations/simulationId/datacenters/endpoint.py @@ -1,5 +1,5 @@ -from opendc.models.datacenter import Datacenter -from opendc.models.simulation import Simulation +from opendc.models_old.datacenter import Datacenter +from opendc.models_old.simulation import Simulation from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/simulations/simulationId/endpoint.py b/opendc/api/v2/simulations/simulationId/endpoint.py index 4aa33c7a..09714560 100644 --- a/opendc/api/v2/simulations/simulationId/endpoint.py +++ b/opendc/api/v2/simulations/simulationId/endpoint.py @@ -1,6 +1,6 @@ from datetime import datetime -from opendc.models.simulation import Simulation +from opendc.models_old.simulation import Simulation from opendc.util import database, exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/simulations/simulationId/experiments/endpoint.py b/opendc/api/v2/simulations/simulationId/experiments/endpoint.py index 07305690..5ecaffb7 100644 --- a/opendc/api/v2/simulations/simulationId/experiments/endpoint.py +++ b/opendc/api/v2/simulations/simulationId/experiments/endpoint.py @@ -1,5 +1,5 @@ -from opendc.models.experiment import Experiment -from opendc.models.simulation import Simulation +from opendc.models_old.experiment import Experiment +from opendc.models_old.simulation import Simulation from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/simulations/simulationId/paths/endpoint.py b/opendc/api/v2/simulations/simulationId/paths/endpoint.py index 69a302ba..4e4a1ec7 100644 --- a/opendc/api/v2/simulations/simulationId/paths/endpoint.py +++ b/opendc/api/v2/simulations/simulationId/paths/endpoint.py @@ -1,5 +1,5 @@ -from opendc.models.path import Path -from opendc.models.simulation import Simulation +from opendc.models_old.path import Path +from opendc.models_old.simulation import Simulation from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/specifications/cpus/endpoint.py b/opendc/api/v2/specifications/cpus/endpoint.py index 87975221..b2ec36f4 100644 --- a/opendc/api/v2/specifications/cpus/endpoint.py +++ b/opendc/api/v2/specifications/cpus/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.cpu import CPU +from opendc.models_old.cpu import CPU from opendc.util.rest import Response diff --git a/opendc/api/v2/specifications/cpus/id/endpoint.py b/opendc/api/v2/specifications/cpus/id/endpoint.py index 205b61c5..83cda92d 100644 --- a/opendc/api/v2/specifications/cpus/id/endpoint.py +++ b/opendc/api/v2/specifications/cpus/id/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.cpu import CPU +from opendc.models_old.cpu import CPU from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/specifications/failure-models/endpoint.py b/opendc/api/v2/specifications/failure-models/endpoint.py index 6397e27e..63807ed2 100644 --- a/opendc/api/v2/specifications/failure-models/endpoint.py +++ b/opendc/api/v2/specifications/failure-models/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.failure_model import FailureModel +from opendc.models_old.failure_model import FailureModel from opendc.util.rest import Response diff --git a/opendc/api/v2/specifications/failure-models/id/endpoint.py b/opendc/api/v2/specifications/failure-models/id/endpoint.py index db450f70..bfba4f16 100644 --- a/opendc/api/v2/specifications/failure-models/id/endpoint.py +++ b/opendc/api/v2/specifications/failure-models/id/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.failure_model import FailureModel +from opendc.models_old.failure_model import FailureModel from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/specifications/gpus/endpoint.py b/opendc/api/v2/specifications/gpus/endpoint.py index 24beb873..d536ba47 100644 --- a/opendc/api/v2/specifications/gpus/endpoint.py +++ b/opendc/api/v2/specifications/gpus/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.gpu import GPU +from opendc.models_old.gpu import GPU from opendc.util.rest import Response diff --git a/opendc/api/v2/specifications/gpus/id/endpoint.py b/opendc/api/v2/specifications/gpus/id/endpoint.py index 489b7e8d..9a0c0f75 100644 --- a/opendc/api/v2/specifications/gpus/id/endpoint.py +++ b/opendc/api/v2/specifications/gpus/id/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.gpu import GPU +from opendc.models_old.gpu import GPU from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/specifications/memories/endpoint.py b/opendc/api/v2/specifications/memories/endpoint.py index 95025418..7a8f6a7a 100644 --- a/opendc/api/v2/specifications/memories/endpoint.py +++ b/opendc/api/v2/specifications/memories/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.memory import Memory +from opendc.models_old.memory import Memory from opendc.util.rest import Response diff --git a/opendc/api/v2/specifications/memories/id/endpoint.py b/opendc/api/v2/specifications/memories/id/endpoint.py index f34ca36f..f8922833 100644 --- a/opendc/api/v2/specifications/memories/id/endpoint.py +++ b/opendc/api/v2/specifications/memories/id/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.memory import Memory +from opendc.models_old.memory import Memory from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/specifications/storages/endpoint.py b/opendc/api/v2/specifications/storages/endpoint.py index 945b89b2..20b9b794 100644 --- a/opendc/api/v2/specifications/storages/endpoint.py +++ b/opendc/api/v2/specifications/storages/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.storage import Storage +from opendc.models_old.storage import Storage from opendc.util.rest import Response diff --git a/opendc/api/v2/specifications/storages/id/endpoint.py b/opendc/api/v2/specifications/storages/id/endpoint.py index 1b7a5ac7..39c20fef 100644 --- a/opendc/api/v2/specifications/storages/id/endpoint.py +++ b/opendc/api/v2/specifications/storages/id/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.storage import Storage +from opendc.models_old.storage import Storage from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/tiles/tileId/endpoint.py b/opendc/api/v2/tiles/tileId/endpoint.py index 4a1a5447..e1efda77 100644 --- a/opendc/api/v2/tiles/tileId/endpoint.py +++ b/opendc/api/v2/tiles/tileId/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.tile import Tile +from opendc.models_old.tile import Tile from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/tiles/tileId/rack/endpoint.py b/opendc/api/v2/tiles/tileId/rack/endpoint.py index 2a5803e4..b5c7fde6 100644 --- a/opendc/api/v2/tiles/tileId/rack/endpoint.py +++ b/opendc/api/v2/tiles/tileId/rack/endpoint.py @@ -1,5 +1,5 @@ -from opendc.models.rack import Rack -from opendc.models.tile import Tile +from opendc.models_old.rack import Rack +from opendc.models_old.tile import Tile from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/tiles/tileId/rack/machines/endpoint.py b/opendc/api/v2/tiles/tileId/rack/machines/endpoint.py index 34d3866e..7980d676 100644 --- a/opendc/api/v2/tiles/tileId/rack/machines/endpoint.py +++ b/opendc/api/v2/tiles/tileId/rack/machines/endpoint.py @@ -1,5 +1,5 @@ -from opendc.models.machine import Machine -from opendc.models.rack import Rack +from opendc.models_old.machine import Machine +from opendc.models_old.rack import Rack from opendc.util import exceptions from opendc.util.rest import Response 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 72fd44d5..dc598162 100644 --- a/opendc/api/v2/tiles/tileId/rack/machines/position/endpoint.py +++ b/opendc/api/v2/tiles/tileId/rack/machines/position/endpoint.py @@ -1,5 +1,5 @@ -from opendc.models.machine import Machine -from opendc.models.rack import Rack +from opendc.models_old.machine import Machine +from opendc.models_old.rack import Rack from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/traces/endpoint.py b/opendc/api/v2/traces/endpoint.py index 610be73e..58cc6153 100644 --- a/opendc/api/v2/traces/endpoint.py +++ b/opendc/api/v2/traces/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.trace import Trace +from opendc.models_old.trace import Trace from opendc.util.rest import Response diff --git a/opendc/api/v2/traces/traceId/endpoint.py b/opendc/api/v2/traces/traceId/endpoint.py index 720d3fd0..f6442a31 100644 --- a/opendc/api/v2/traces/traceId/endpoint.py +++ b/opendc/api/v2/traces/traceId/endpoint.py @@ -1,4 +1,4 @@ -from opendc.models.trace import Trace +from opendc.models_old.trace import Trace from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/traces/traceId/jobs/endpoint.py b/opendc/api/v2/traces/traceId/jobs/endpoint.py index eec52b56..af681b70 100644 --- a/opendc/api/v2/traces/traceId/jobs/endpoint.py +++ b/opendc/api/v2/traces/traceId/jobs/endpoint.py @@ -1,5 +1,5 @@ -from opendc.models.job import Job -from opendc.models.trace import Trace +from opendc.models_old.job import Job +from opendc.models_old.trace import Trace from opendc.util import exceptions from opendc.util.rest import Response diff --git a/opendc/api/v2/users/userId/endpoint.py b/opendc/api/v2/users/userId/endpoint.py index 6de26e64..9418f70a 100644 --- a/opendc/api/v2/users/userId/endpoint.py +++ b/opendc/api/v2/users/userId/endpoint.py @@ -1,5 +1,5 @@ +from opendc.models.user import User from opendc.util import exceptions -from opendc.util.database import DB from opendc.util.rest import Response @@ -11,12 +11,13 @@ def GET(request): except exceptions.ParameterError as e: return Response(400, str(e)) - user = DB.fetch_one({'_id': request.params_path['userId']}, 'users') + user = User(request.params_path['userId']) - if user is None: - return Response(404, f'User with ID {request.params_path["userId"]} not found.') - - return Response(200, f'Successfully retrieved {user}.', user) + validation_error = user.validate() + if validation_error is None: + return Response(200, f'Successfully retrieved {user}.', user.obj) + else: + return validation_error def PUT(request): @@ -31,22 +32,18 @@ def PUT(request): except exceptions.ParameterError as e: return Response(400, str(e)) - user_id = request.params_path['userId'] - user = DB.fetch_one({'_id': user_id}, 'users') - - if user is None: - return Response(404, f'User with ID {user_id} not found.') + user = User(request.params_path['userId']) - print(user['googleId'], request.google_id) - if user['googleId'] != request.google_id: - return Response(403, f'Forbidden from editing {user}.') + validation_error = user.validate(request.google_id) + if validation_error is not None: + return validation_error - user['givenName'] = request.params_body['user']['givenName'] - user['familyName'] = request.params_body['user']['familyName'] + user.set_property('givenName', request.params_body['user']['givenName']) + user.set_property('familyName', request.params_body['user']['familyName']) - DB.update(user_id, user, 'users') + user.update() - return Response(200, f'Successfully updated {user}.', user) + return Response(200, f'Successfully updated {user}.', user.obj) def DELETE(request): @@ -57,15 +54,12 @@ def DELETE(request): except exceptions.ParameterError as e: return Response(400, str(e)) - user_id = request.params_path['userId'] - user = DB.fetch_one({'_id': user_id}, 'users') - - if user is None: - return Response(404, f'User with ID {user_id} not found.') + user = User(request.params_path['userId']) - if user['googleId'] != request.google_id: - return Response(403, f'Forbidden from editing {user}.') + validation_error = user.validate(request.google_id) + if validation_error is not None: + return validation_error - DB.delete_one({'_id': user_id}, 'users') + user.delete() - return Response(200, f'Successfully deleted {user}.', user) + return Response(200, f'Successfully deleted {user}.', user.obj) diff --git a/opendc/models/user.py b/opendc/models/user.py index df3a4e76..39437025 100644 --- a/opendc/models/user.py +++ b/opendc/models/user.py @@ -1,47 +1,26 @@ -from opendc.models.model import Model +from opendc.util.database import DB +from opendc.util.rest import Response -class User(Model): - JSON_TO_PYTHON_DICT = { - 'User': { - 'id': 'id', - 'googleId': 'google_id', - 'email': 'email', - 'givenName': 'given_name', - 'familyName': 'family_name' - } - } +class User: + def __init__(self, obj_id): + self.obj_id = obj_id + self.obj = DB.fetch_one({'_id': obj_id}, 'users') - COLLECTION_NAME = 'users' - COLUMNS = ['id', 'google_id', 'email', 'given_name', 'family_name'] - COLUMNS_PRIMARY_KEY = ['id'] + def validate(self, request_google_id=None): + if self.obj is None: + return Response(404, f'User with ID {self.obj_id} not found.') - @classmethod - def from_google_id(cls, google_id): - """Initialize a User by fetching them by their google id.""" + if request_google_id is not None and self.obj['googleId'] != request_google_id: + return Response(403, f'Forbidden from editing user with ID {self.obj_id}.') - user = cls._from_database('SELECT * FROM users WHERE google_id = %s', (google_id, )) + return None - if user is not None: - return user + def set_property(self, key, value): + self.obj[key] = value - return User() + def update(self): + DB.update(self.obj_id, self.obj, 'users') - @classmethod - 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, )) - - if user is not None: - return user - - return User() - - 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 User.""" - - if authorization_level in ['EDIT', 'OWN']: - return google_id == self.google_id - - return True + def delete(self): + DB.delete_one({'_id': self.obj_id}, 'users') diff --git a/opendc/models_old/__init__.py b/opendc/models_old/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/opendc/models_old/__init__.py diff --git a/opendc/models/allowed_object.py b/opendc/models_old/allowed_object.py index 48f2abd5..bcadf025 100644 --- a/opendc/models/allowed_object.py +++ b/opendc/models_old/allowed_object.py @@ -1,4 +1,4 @@ -from opendc.models.model import Model +from opendc.models_old.model import Model class AllowedObject(Model): diff --git a/opendc/models/authorization.py b/opendc/models_old/authorization.py index 7ec88e78..43d784e9 100644 --- a/opendc/models/authorization.py +++ b/opendc/models_old/authorization.py @@ -1,5 +1,5 @@ -from opendc.models.model import Model -from opendc.models.user import User +from opendc.models_old.model import Model +from opendc.models_old.user import User class Authorization(Model): diff --git a/opendc/models/cpu.py b/opendc/models_old/cpu.py index 034a86fe..0f50ce1c 100644 --- a/opendc/models/cpu.py +++ b/opendc/models_old/cpu.py @@ -1,4 +1,4 @@ -from opendc.models.model import Model +from opendc.models_old.model import Model class CPU(Model): diff --git a/opendc/models/datacenter.py b/opendc/models_old/datacenter.py index d4cbf811..b1ed2eee 100644 --- a/opendc/models/datacenter.py +++ b/opendc/models_old/datacenter.py @@ -1,5 +1,5 @@ -from opendc.models.model import Model -from opendc.models.section import Section +from opendc.models_old.model import Model +from opendc.models_old.section import Section class Datacenter(Model): diff --git a/opendc/models/experiment.py b/opendc/models_old/experiment.py index 1f33fa3b..64b99212 100644 --- a/opendc/models/experiment.py +++ b/opendc/models_old/experiment.py @@ -1,5 +1,5 @@ -from opendc.models.model import Model -from opendc.models.simulation import Simulation +from opendc.models_old.model import Model +from opendc.models_old.simulation import Simulation from opendc.util import exceptions diff --git a/opendc/models/failure_model.py b/opendc/models_old/failure_model.py index f5c4909d..d1a8c1cc 100644 --- a/opendc/models/failure_model.py +++ b/opendc/models_old/failure_model.py @@ -1,4 +1,4 @@ -from opendc.models.model import Model +from opendc.models_old.model import Model class FailureModel(Model): diff --git a/opendc/models/gpu.py b/opendc/models_old/gpu.py index 672df6fa..31b3b6b1 100644 --- a/opendc/models/gpu.py +++ b/opendc/models_old/gpu.py @@ -1,4 +1,4 @@ -from opendc.models.model import Model +from opendc.models_old.model import Model class GPU(Model): diff --git a/opendc/models/job.py b/opendc/models_old/job.py index 81354952..9cb7cd7e 100644 --- a/opendc/models/job.py +++ b/opendc/models_old/job.py @@ -1,4 +1,4 @@ -from opendc.models.model import Model +from opendc.models_old.model import Model class Job(Model): diff --git a/opendc/models/machine.py b/opendc/models_old/machine.py index 1b853bf9..8e5ccb44 100644 --- a/opendc/models/machine.py +++ b/opendc/models_old/machine.py @@ -1,7 +1,7 @@ import copy -from opendc.models.model import Model -from opendc.models.rack import Rack +from opendc.models_old.model import Model +from opendc.models_old.rack import Rack from opendc.util import database, exceptions diff --git a/opendc/models/machine_state.py b/opendc/models_old/machine_state.py index 3418f66e..0e9f7dad 100644 --- a/opendc/models/machine_state.py +++ b/opendc/models_old/machine_state.py @@ -1,4 +1,4 @@ -from opendc.models.model import Model +from opendc.models_old.model import Model from opendc.util import database diff --git a/opendc/models/memory.py b/opendc/models_old/memory.py index 17a79e14..8edf8f5d 100644 --- a/opendc/models/memory.py +++ b/opendc/models_old/memory.py @@ -1,4 +1,4 @@ -from opendc.models.model import Model +from opendc.models_old.model import Model class Memory(Model): diff --git a/opendc/models/model.py b/opendc/models_old/model.py index 73eabd26..73eabd26 100644 --- a/opendc/models/model.py +++ b/opendc/models_old/model.py diff --git a/opendc/models/object.py b/opendc/models_old/object.py index 2ce079af..8f2e308b 100644 --- a/opendc/models/object.py +++ b/opendc/models_old/object.py @@ -1,4 +1,4 @@ -from opendc.models.model import Model +from opendc.models_old.model import Model class Object(Model): diff --git a/opendc/models/path.py b/opendc/models_old/path.py index 093c9346..4d07b2d5 100644 --- a/opendc/models/path.py +++ b/opendc/models_old/path.py @@ -1,6 +1,6 @@ -from opendc.models.authorization import Authorization -from opendc.models.model import Model -from opendc.models.user import User +from opendc.models_old.authorization import Authorization +from opendc.models_old.model import Model +from opendc.models_old.user import User from opendc.util import exceptions diff --git a/opendc/models/queued_experiment.py b/opendc/models_old/queued_experiment.py index b59cfedc..b474dc31 100644 --- a/opendc/models/queued_experiment.py +++ b/opendc/models_old/queued_experiment.py @@ -1,4 +1,4 @@ -from opendc.models.model import Model +from opendc.models_old.model import Model class QueuedExperiment(Model): diff --git a/opendc/models/rack.py b/opendc/models_old/rack.py index 52cb0ffe..dc08eb6a 100644 --- a/opendc/models/rack.py +++ b/opendc/models_old/rack.py @@ -1,6 +1,6 @@ -from opendc.models.model import Model -from opendc.models.object import Object -from opendc.models.tile import Tile +from opendc.models_old.model import Model +from opendc.models_old.object import Object +from opendc.models_old.tile import Tile class Rack(Model): diff --git a/opendc/models/rack_state.py b/opendc/models_old/rack_state.py index a261fce0..12e0f931 100644 --- a/opendc/models/rack_state.py +++ b/opendc/models_old/rack_state.py @@ -1,4 +1,4 @@ -from opendc.models.model import Model +from opendc.models_old.model import Model from opendc.util import database diff --git a/opendc/models/room.py b/opendc/models_old/room.py index 6a7627f5..e0eb7c2f 100644 --- a/opendc/models/room.py +++ b/opendc/models_old/room.py @@ -1,5 +1,5 @@ -from opendc.models.datacenter import Datacenter -from opendc.models.model import Model +from opendc.models_old.datacenter import Datacenter +from opendc.models_old.model import Model from opendc.util import exceptions diff --git a/opendc/models/room_state.py b/opendc/models_old/room_state.py index 4326a32b..c6635649 100644 --- a/opendc/models/room_state.py +++ b/opendc/models_old/room_state.py @@ -1,4 +1,4 @@ -from opendc.models.model import Model +from opendc.models_old.model import Model from opendc.util import database diff --git a/opendc/models/room_type.py b/opendc/models_old/room_type.py index b91c1e67..755572f8 100644 --- a/opendc/models/room_type.py +++ b/opendc/models_old/room_type.py @@ -1,4 +1,4 @@ -from opendc.models.model import Model +from opendc.models_old.model import Model class RoomType(Model): diff --git a/opendc/models/scheduler.py b/opendc/models_old/scheduler.py index c3c98b7a..b9939321 100644 --- a/opendc/models/scheduler.py +++ b/opendc/models_old/scheduler.py @@ -1,4 +1,4 @@ -from opendc.models.model import Model +from opendc.models_old.model import Model class Scheduler(Model): diff --git a/opendc/models/section.py b/opendc/models_old/section.py index 2fd71068..0df4967c 100644 --- a/opendc/models/section.py +++ b/opendc/models_old/section.py @@ -1,5 +1,5 @@ -from opendc.models.model import Model -from opendc.models.path import Path +from opendc.models_old.model import Model +from opendc.models_old.path import Path from opendc.util import exceptions diff --git a/opendc/models/simulation.py b/opendc/models_old/simulation.py index af47b4c5..9c1820a3 100644 --- a/opendc/models/simulation.py +++ b/opendc/models_old/simulation.py @@ -1,6 +1,6 @@ -from opendc.models.authorization import Authorization -from opendc.models.model import Model -from opendc.models.user import User +from opendc.models_old.authorization import Authorization +from opendc.models_old.model import Model +from opendc.models_old.user import User from opendc.util import exceptions diff --git a/opendc/models/storage.py b/opendc/models_old/storage.py index 93cc8b68..9f0f9215 100644 --- a/opendc/models/storage.py +++ b/opendc/models_old/storage.py @@ -1,4 +1,4 @@ -from opendc.models.model import Model +from opendc.models_old.model import Model class Storage(Model): diff --git a/opendc/models/task.py b/opendc/models_old/task.py index 411405c2..e6f99014 100644 --- a/opendc/models/task.py +++ b/opendc/models_old/task.py @@ -1,4 +1,4 @@ -from opendc.models.model import Model +from opendc.models_old.model import Model class Task(Model): diff --git a/opendc/models/task_duration.py b/opendc/models_old/task_duration.py index ad6459ab..5058e8de 100644 --- a/opendc/models/task_duration.py +++ b/opendc/models_old/task_duration.py @@ -1,4 +1,4 @@ -from opendc.models.model import Model +from opendc.models_old.model import Model from opendc.util import database diff --git a/opendc/models/task_state.py b/opendc/models_old/task_state.py index 2cef20ee..cc3fdd89 100644 --- a/opendc/models/task_state.py +++ b/opendc/models_old/task_state.py @@ -1,4 +1,4 @@ -from opendc.models.model import Model +from opendc.models_old.model import Model from opendc.util import database diff --git a/opendc/models/tile.py b/opendc/models_old/tile.py index a945564f..e46b29a6 100644 --- a/opendc/models/tile.py +++ b/opendc/models_old/tile.py @@ -1,6 +1,6 @@ -from opendc.models.model import Model -from opendc.models.object import Object -from opendc.models.room import Room +from opendc.models_old.model import Model +from opendc.models_old.object import Object +from opendc.models_old.room import Room from opendc.util import exceptions diff --git a/opendc/models/trace.py b/opendc/models_old/trace.py index f6d2e1c1..58abe058 100644 --- a/opendc/models/trace.py +++ b/opendc/models_old/trace.py @@ -1,4 +1,4 @@ -from opendc.models.model import Model +from opendc.models_old.model import Model class Trace(Model): diff --git a/opendc/models_old/user.py b/opendc/models_old/user.py new file mode 100644 index 00000000..657d5019 --- /dev/null +++ b/opendc/models_old/user.py @@ -0,0 +1,47 @@ +from opendc.models_old.model import Model + + +class User(Model): + JSON_TO_PYTHON_DICT = { + 'User': { + 'id': 'id', + 'googleId': 'google_id', + 'email': 'email', + 'givenName': 'given_name', + 'familyName': 'family_name' + } + } + + COLLECTION_NAME = 'users' + COLUMNS = ['id', 'google_id', 'email', 'given_name', 'family_name'] + COLUMNS_PRIMARY_KEY = ['id'] + + @classmethod + 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, )) + + if user is not None: + return user + + return User() + + @classmethod + 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, )) + + if user is not None: + return user + + return User() + + 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 User.""" + + if authorization_level in ['EDIT', 'OWN']: + return google_id == self.google_id + + return True |
