tables.py 9.09 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# Copyright 2014 Budapest University of Technology and Economics (BME IK)
#
# This file is part of CIRCLE Cloud.
#
# CIRCLE is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# CIRCLE is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with CIRCLE.  If not, see <http://www.gnu.org/licenses/>.

18 19
from __future__ import absolute_import

20
from django.contrib.auth.models import Group, User
21
from django_tables2 import Table, A
22 23
from django_tables2.columns import (TemplateColumn, Column, LinkColumn,
                                    BooleanColumn)
24

25
from vm.models import Node, InstanceTemplate, Lease
26
from django.utils.translation import ugettext_lazy as _
27
from django_sshkey.models import UserKey
28
from dashboard.models import ConnectCommand
29 30


31 32 33 34
class NodeListTable(Table):

    pk = Column(
        verbose_name="ID",
35
        attrs={'th': {'class': 'node-list-table-thin'}},
36 37
    )

38
    overcommit = Column(
39
        verbose_name=_("Overcommit"),
40
        attrs={'th': {'class': 'node-list-table-thin'}},
41 42
    )

43 44
    get_status_display = Column(
        verbose_name=_("Status"),
45
        attrs={'th': {'class': 'node-list-table-thin'}},
46
        order_by=("enabled", "schedule_enabled"),
47 48 49
    )

    name = TemplateColumn(
50 51
        template_name="dashboard/node-list/column-name.html",
        order_by="normalized_name"
52 53 54 55 56 57 58
    )

    priority = Column(
        attrs={'th': {'class': 'node-list-table-thin'}},
    )

    number_of_VMs = TemplateColumn(
59
        verbose_name=_("Number of VMs"),
60
        template_name='dashboard/node-list/column-vm.html',
61
        attrs={'th': {'class': 'node-list-table-thin'}},
62 63
    )

64
    monitor = TemplateColumn(
Kálmán Viktor committed
65
        verbose_name=_("Monitor"),
66 67
        template_name='dashboard/node-list/column-monitor.html',
        attrs={'th': {'class': 'node-list-table-monitor'}},
68
        orderable=False,
69 70
    )

71 72 73 74 75 76
    minion_online = BooleanColumn(
        verbose_name=_("Minion online"),
        attrs={'th': {'class': 'node-list-table-thin'}},
        orderable=False,
    )

77 78 79 80
    class Meta:
        model = Node
        attrs = {'class': ('table table-bordered table-striped table-hover '
                           'node-list-table')}
81
        fields = ('pk', 'name', 'host', 'get_status_display', 'priority',
82
                  'minion_online', 'overcommit', 'number_of_VMs', )
83

84

85
class GroupListTable(Table):
86 87 88 89 90 91 92 93 94 95 96
    pk = TemplateColumn(
        template_name='dashboard/group-list/column-id.html',
        verbose_name="ID",
        attrs={'th': {'class': 'group-list-table-thin'}},
    )

    name = TemplateColumn(
        template_name="dashboard/group-list/column-name.html"
    )

    number_of_users = TemplateColumn(
97
        orderable=False,
98
        verbose_name=_("Number of users"),
99 100 101 102 103
        template_name='dashboard/group-list/column-users.html',
        attrs={'th': {'class': 'group-list-table-admin'}},
    )

    admin = TemplateColumn(
104
        orderable=False,
105
        verbose_name=_("Admin"),
106 107 108 109 110
        template_name='dashboard/group-list/column-admin.html',
        attrs={'th': {'class': 'group-list-table-admin'}},
    )

    actions = TemplateColumn(
111
        orderable=False,
112
        verbose_name=_("Actions"),
113 114 115 116 117
        attrs={'th': {'class': 'group-list-table-thin'}},
        template_code=('{% include "dashboard/group-list/column-'
                       'actions.html" with btn_size="btn-xs" %}'),
    )

118 119 120 121
    class Meta:
        model = Group
        attrs = {'class': ('table table-bordered table-striped table-hover '
                           'group-list-table')}
122 123 124 125
        fields = ('pk', 'name', )


class UserListTable(Table):
126 127 128
    username = LinkColumn(
        'dashboard.views.profile',
        args=[A('username')],
129
    )
130 131 132 133 134
    profile__org_id = LinkColumn(
        'dashboard.views.profile',
        accessor='profile.org_id',
        args=[A('username')],
        verbose_name=_('Organization ID')
135
    )
136 137
    is_superuser = BooleanColumn()
    is_active = BooleanColumn()
138 139 140

    class Meta:
        model = User
141 142 143
        attrs = {'class': ('table table-bordered table-striped table-hover')}
        fields = ('username', 'last_name', 'first_name', 'profile__org_id',
                  'email', 'is_active', 'is_superuser')
144 145


146
class TemplateListTable(Table):
147 148
    name = TemplateColumn(
        template_name="dashboard/template-list/column-template-name.html",
149
        attrs={'th': {'data-sort': "string"}}
150
    )
151 152
    resources = TemplateColumn(
        template_name="dashboard/template-list/column-template-resources.html",
153
        verbose_name=_("Resources"),
154
        attrs={'th': {'data-sort': "int"}},
155
        order_by=("ram_size"),
156 157 158 159
    )
    lease = TemplateColumn(
        "{{ record.lease.name }}",
        verbose_name=_("Lease"),
160 161 162 163 164 165 166
        attrs={'th': {'data-sort': "string"}}
    )
    system = Column(
        attrs={'th': {'data-sort': "string"}}
    )
    access_method = Column(
        attrs={'th': {'data-sort': "string"}}
167
    )
168 169 170 171 172
    owner = TemplateColumn(
        template_name="dashboard/template-list/column-template-owner.html",
        verbose_name=_("Owner"),
        attrs={'th': {'data-sort': "string"}}
    )
173 174 175 176
    created = TemplateColumn(
        template_name="dashboard/template-list/column-template-created.html",
        verbose_name=_("Created at"),
    )
177 178 179 180 181
    running = TemplateColumn(
        template_name="dashboard/template-list/column-template-running.html",
        verbose_name=_("Running"),
        attrs={'th': {'data-sort': "int"}},
    )
182 183
    actions = TemplateColumn(
        verbose_name=_("Actions"),
184 185
        template_name="dashboard/template-list/column-template-actions.html",
        attrs={'th': {'class': 'template-list-table-thin'}},
186
        orderable=False,
187 188 189 190 191 192
    )

    class Meta:
        model = InstanceTemplate
        attrs = {'class': ('table table-bordered table-striped table-hover'
                           ' template-list-table')}
193 194
        fields = ('name', 'resources', 'system', 'access_method', 'lease',
                  'owner', 'created', 'running', 'actions', )
195

196
        prefix = "template-"
197 198 199


class LeaseListTable(Table):
200
    name = LinkColumn(
201 202 203 204
        'dashboard.views.lease-detail',
        args=[A('pk')],
    )

205
    suspend_interval_seconds = TemplateColumn(
206 207 208
        "{{ record.get_readable_suspend_time }}"
    )

209
    delete_interval_seconds = TemplateColumn(
210 211 212 213 214
        "{{ record.get_readable_delete_time }}"
    )

    actions = TemplateColumn(
        verbose_name=_("Actions"),
215 216
        template_name="dashboard/template-list/column-lease-actions.html",
        orderable=False,
217 218 219 220 221 222
    )

    class Meta:
        model = Lease
        attrs = {'class': ('table table-bordered table-striped table-hover'
                           ' lease-list-table')}
223 224
        fields = ('name', 'suspend_interval_seconds',
                  'delete_interval_seconds', )
225
        prefix = "lease-"
226
        empty_text = _("No available leases.")
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254


class UserKeyListTable(Table):
    name = LinkColumn(
        'dashboard.views.userkey-detail',
        args=[A('pk')],
        verbose_name=_("Name"),
        attrs={'th': {'data-sort': "string"}}
    )

    fingerprint = Column(
        verbose_name=_("Fingerprint"),
        attrs={'th': {'data-sort': "string"}}
    )

    created = Column(
        verbose_name=_("Created at"),
        attrs={'th': {'data-sort': "string"}}
    )

    actions = TemplateColumn(
        verbose_name=_("Actions"),
        template_name="dashboard/userkey-list/column-userkey-actions.html",
        orderable=False,
    )

    class Meta:
        model = UserKey
255 256
        attrs = {'class': ('table table-bordered table-striped table-hover'),
                 'id': "profile-key-list-table"}
257
        fields = ('name', 'fingerprint', 'created', 'actions')
258 259
        prefix = "key-"
        empty_text = _("You haven't added any public keys yet.")
260 261 262


class ConnectCommandListTable(Table):
263 264 265
    name = LinkColumn(
        'dashboard.views.connect-command-detail',
        args=[A('pk')],
266 267
        attrs={'th': {'data-sort': "string"}}
    )
268 269
    access_method = Column(
        verbose_name=_("Access method"),
270 271 272 273 274 275 276 277
        attrs={'th': {'data-sort': "string"}}
    )
    template = Column(
        verbose_name=_("Template"),
        attrs={'th': {'data-sort': "string"}}
    )
    actions = TemplateColumn(
        verbose_name=_("Actions"),
278 279
        template_name=("dashboard/connect-command-list/column-command"
                       "-actions.html"),
280 281 282 283 284
        orderable=False,
    )

    class Meta:
        model = ConnectCommand
285 286 287
        attrs = {'class': ('table table-bordered table-striped table-hover'),
                 'id': "profile-command-list-table"}
        fields = ('name', 'access_method',  'template', 'actions')
288
        prefix = "cmd-"
289 290 291 292
        empty_text = _(
            "You don't have any custom connection commands yet. You can "
            "specify commands to be displayed on VM detail pages instead of "
            "the defaults.")