diff --git a/remoteappmanager/webapi/admin/application.py b/remoteappmanager/webapi/admin/application.py index 024bdfcc9..c1ffe8fd9 100644 --- a/remoteappmanager/webapi/admin/application.py +++ b/remoteappmanager/webapi/admin/application.py @@ -46,3 +46,23 @@ def create(self, resource, **kwargs): raise exceptions.Unable() resource.identifier = str(id) + + @gen.coroutine + @authenticated + def items(self, items_response, **kwargs): + """Produces a list of Application items in the items_response object. + + Parameters + ---------- + items_response: ItemsResponse + an object to be filled with the appropriate information + """ + db = self.application.db + apps = db.list_applications() + + items = [] + for app in apps: + item = Application(identifier=str(app.id), image_name=app.image) + items.append(item) + + items_response.set(items) diff --git a/remoteappmanager/webapi/admin/container.py b/remoteappmanager/webapi/admin/container.py index d1045dcf3..d9575d5ae 100644 --- a/remoteappmanager/webapi/admin/container.py +++ b/remoteappmanager/webapi/admin/container.py @@ -3,12 +3,22 @@ from tornadowebapi import exceptions from tornadowebapi.resource import Resource from tornadowebapi.resource_handler import ResourceHandler +from tornadowebapi.traitlets import Unicode from remoteappmanager.webapi.decorators import authenticated class Container(Resource): - pass + """Represents a container as seen from the administrator. + It can only be stopped. + """ + docker_id = Unicode(allow_empty=False, strip=True, scope="output") + name = Unicode(allow_empty=False, strip=True, scope="output") + image_name = Unicode(allow_empty=False, strip=True, scope="output") + image_id = Unicode(allow_empty=False, strip=True, scope="output") + mapping_id = Unicode(allow_empty=False, strip=True, scope="output") + user = Unicode(allow_empty=False, strip=True, scope="output") + realm = Unicode(allow_empty=False, strip=True, scope="output") class ContainerHandler(ResourceHandler): @@ -43,3 +53,18 @@ def delete(self, resource, **kwargs): self.log.exception( "Could not stop and remove container for id {}".format( identifier)) + + @gen.coroutine + @authenticated + def items(self, items_response, **kwargs): + """Get all the currently running containers.""" + manager = self.application.container_manager + containers = (yield manager.find_containers()) + + items = [] + for c in containers: + item = Container(identifier=c.url_id) + item.fill(c) + items.append(item) + + items_response.set(items) diff --git a/remoteappmanager/webapi/admin/tests/test_application.py b/remoteappmanager/webapi/admin/tests/test_application.py index 3704382e4..f4be9b11a 100644 --- a/remoteappmanager/webapi/admin/tests/test_application.py +++ b/remoteappmanager/webapi/admin/tests/test_application.py @@ -68,5 +68,12 @@ def test_delete_failed_auth(self): self.delete("/user/johndoe/api/v1/applications/0/", httpstatus.NOT_FOUND) + def test_items(self): + response, data = self.get("/user/johndoe/api/v1/applications/", + httpstatus.OK) + + self.assertEqual(data["items"]["0"]["image_name"], + "simphonyproject/simphony-mayavi:0.6.0") + def cookie_auth_token(self): return "jupyter-hub-token-johndoe=johndoe" diff --git a/remoteappmanager/webapi/admin/tests/test_container.py b/remoteappmanager/webapi/admin/tests/test_container.py index b79ae1991..eff382be5 100644 --- a/remoteappmanager/webapi/admin/tests/test_container.py +++ b/remoteappmanager/webapi/admin/tests/test_container.py @@ -51,6 +51,12 @@ def test_delete_failure_stop_container(self): self.delete("/user/johndoe/api/v1/containers/found/", httpstatus.NO_CONTENT) + def test_items(self): + response, data = self.get("/user/johndoe/api/v1/containers/", + httpstatus.OK) + + self.assertEqual(len(data["identifiers"]), 1) + def cookie_auth_token(self): return "jupyter-hub-token-johndoe=johndoe" diff --git a/remoteappmanager/webapi/admin/tests/test_user.py b/remoteappmanager/webapi/admin/tests/test_user.py index a29df780f..731b9848e 100644 --- a/remoteappmanager/webapi/admin/tests/test_user.py +++ b/remoteappmanager/webapi/admin/tests/test_user.py @@ -67,5 +67,10 @@ def test_delete_failed_auth(self): self.delete("/user/johndoe/api/v1/users/0/", httpstatus.NOT_FOUND) + def test_items(self): + response, data = self.get("/user/johndoe/api/v1/users/", httpstatus.OK) + + self.assertEqual(data["items"]["0"]["name"], "johndoe") + def cookie_auth_token(self): return "jupyter-hub-token-johndoe=johndoe" diff --git a/remoteappmanager/webapi/admin/user.py b/remoteappmanager/webapi/admin/user.py index 70b35f6e5..8445952d8 100644 --- a/remoteappmanager/webapi/admin/user.py +++ b/remoteappmanager/webapi/admin/user.py @@ -45,3 +45,19 @@ def create(self, resource, **kwargs): raise exceptions.Exists() except db_exceptions.UnsupportedOperation: raise exceptions.Unable() + + @gen.coroutine + @authenticated + def items(self, items_response, **kwargs): + """Produces a list of User items in the items_response object. + + Parameters + ---------- + items_response: ItemsResponse + an object to be filled with the appropriate information + """ + users = self.application.db.list_users() + + items_response.set([ + User(identifier=str(u.id), name=u.name) + for u in users]) diff --git a/requirements.txt b/requirements.txt index 98e630513..db94425f3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,5 +11,5 @@ git+git://github.com/jupyterhub/jupyterhub.git@2d1a45f0190059ef436c2f97dc8d6e391 jupyter_client==4.3.0 click==6.6 tabulate==0.7.5 -git+git://github.com/simphony/tornado-webapi.git@master#egg=tornadowebapi +git+git://github.com/simphony/tornado-webapi.git@13d044331a1e86a03b18f6c1424cc9adf424ddac#egg=tornadowebapi oauthenticator==0.5.1