start.py 3.39 KB
Newer Older
1
# Copyright (c) 2016, Daniele Venzano
2 3 4 5 6 7 8 9 10 11 12 13 14 15
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

16 17
"""Main points of entry for the Zoe web interface."""

18 19
from zoe_api.web.request_handler import ZoeWebRequestHandler
from zoe_api.auth.base import BaseAuthenticator
20

21

22
class RootWeb(ZoeWebRequestHandler):
23
    """Handler class"""
24

25 26
    def get(self):
        """Home page without authentication."""
27
        self.redirect("/user")
28 29


30
class LoginWeb(ZoeWebRequestHandler):
31 32 33 34
    """The login web page."""

    def get(self):
        """Login page."""
Daniele Venzano's avatar
Daniele Venzano committed
35
        self.render('login.jinja2')
36 37 38 39 40

    def post(self):
        """Try to authenticate."""
        username = self.get_argument("username", "")
        password = self.get_argument("password", "")
41
        user = BaseAuthenticator().full_auth(username, password)
42 43

        if not self.get_secure_cookie('zoe'):
44
            cookie_val = user.username
45 46 47 48
            self.set_secure_cookie('zoe', cookie_val)
        self.redirect(self.get_argument("next", u"/user"))


49
class LogoutWeb(ZoeWebRequestHandler):
50 51 52 53 54 55 56 57
    """The logout web page."""

    def get(self):
        """Login page."""
        self.clear_cookie('zoe')
        self.redirect(self.get_argument("next", u"/login"))


58
class HomeWeb(ZoeWebRequestHandler):
59
    """Handler class"""
60

61 62
    def get(self):
        """Home page with authentication."""
63
        if self.current_user is None:
64
            return
65

66
        filters = {
67
            "user_id": self.current_user.id,
68 69
            "limit": 5
        }
70
        last_executions = self.api_endpoint.execution_list(self.current_user, **filters)
71 72

        filters = {
73
            "user_id": self.current_user.id,
74 75
            "status": "running"
        }
76
        last_running_executions = self.api_endpoint.execution_list(self.current_user, **filters)
77 78

        filters = {
79
            "user_id": self.current_user.id,
80 81
            "status": "submitted"
        }
82
        last_running_executions += self.api_endpoint.execution_list(self.current_user, **filters)
83 84

        filters = {
85
            "user_id": self.current_user.id,
86 87
            "status": "scheduled"
        }
88
        last_running_executions += self.api_endpoint.execution_list(self.current_user, **filters)
89

90
        filters = {
91
            "user_id": self.current_user.id,
92
            "status": "starting"
93
        }
94
        last_running_executions += self.api_endpoint.execution_list(self.current_user, **filters)
95 96

        running_reservations = [e.total_reservations for e in last_running_executions]
97 98
        total_memory = sum([r.memory.min for r in running_reservations])
        total_cores = sum([r.cores.min for r in running_reservations])
99 100

        template_vars = {
101 102 103 104
            "total_memory": total_memory,
            "total_cores": total_cores,
            'last_executions': sorted(last_executions, key=lambda e: e.id),
            'running_executions': sorted(last_running_executions, key=lambda e: e.id)
105
        }
Daniele Venzano's avatar
Daniele Venzano committed
106
        self.render('home_user.jinja2', **template_vars)