Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions remoteappmanager/webapi/admin/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
27 changes: 26 additions & 1 deletion remoteappmanager/webapi/admin/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
7 changes: 7 additions & 0 deletions remoteappmanager/webapi/admin/tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 6 additions & 0 deletions remoteappmanager/webapi/admin/tests/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
5 changes: 5 additions & 0 deletions remoteappmanager/webapi/admin/tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
16 changes: 16 additions & 0 deletions remoteappmanager/webapi/admin/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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