tables.py 8.89 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 22 23
from django_tables2 import Table, A
from django_tables2.columns import (TemplateColumn, Column, BooleanColumn,
                                    LinkColumn)
24

25
from vm.models import Instance, Node, InstanceTemplate, Lease
26 27 28 29
from django.utils.translation import ugettext_lazy as _


class VmListTable(Table):
30 31
    pk = TemplateColumn(
        template_name='dashboard/vm-list/column-id.html',
32 33 34
        verbose_name="ID",
        attrs={'th': {'class': 'vm-list-table-thin'}},
    )
35 36 37

    name = TemplateColumn(
        template_name="dashboard/vm-list/column-name.html"
38
    )
39

40 41 42 43 44 45 46 47 48 49 50 51
    admin = TemplateColumn(
        template_name='dashboard/vm-list/column-admin.html',
        attrs={'th': {'class': 'vm-list-table-admin'}},
    )
    details = TemplateColumn(
        template_name='dashboard/vm-list/column-details.html',
        attrs={'th': {'class': 'vm-list-table-thin'}},
    )
    actions = TemplateColumn(
        template_name='dashboard/vm-list/column-actions.html',
        attrs={'th': {'class': 'vm-list-table-thin'}},
    )
52
    time_of_suspend = TemplateColumn(
53
        '{{ record.time_of_suspend|timeuntil }}',
54
        verbose_name=_("Suspend in"))
55
    time_of_delete = TemplateColumn(
56
        '{{ record.time_of_delete|timeuntil }}',
57
        verbose_name=_("Delete in"))
58 59 60 61 62 63

    class Meta:
        model = Instance
        attrs = {'class': ('table table-bordered table-striped table-hover '
                           'vm-list-table')}
        fields = ('pk', 'name', 'state', 'time_of_suspend', 'time_of_delete', )
64 65 66 67 68 69


class NodeListTable(Table):

    pk = Column(
        verbose_name="ID",
70
        attrs={'th': {'class': 'node-list-table-thin'}},
71 72
    )

73 74 75
    overcommit = Column(
        verbose_name="Overcommit",
        attrs={'th': {'class': 'node-list-table-thin'}},
76 77
    )

78 79 80 81 82 83 84 85 86 87
    host = Column(
        verbose_name="Host",
    )

    enabled = BooleanColumn(
        verbose_name="Enabled",
        attrs={'th': {'class': 'node-list-table-thin'}},
    )

    name = TemplateColumn(
88 89
        template_name="dashboard/node-list/column-name.html",
        order_by="normalized_name"
90 91 92 93 94 95 96 97 98
    )

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

    number_of_VMs = TemplateColumn(
        template_name='dashboard/node-list/column-vm.html',
99
        attrs={'th': {'class': 'node-list-table-thin'}},
100 101
    )

102 103 104
    monitor = TemplateColumn(
        template_name='dashboard/node-list/column-monitor.html',
        attrs={'th': {'class': 'node-list-table-monitor'}},
105 106 107 108 109 110 111 112
    )

    details = TemplateColumn(
        template_name='dashboard/node-list/column-details.html',
        attrs={'th': {'class': 'node-list-table-thin'}},
    )
    actions = TemplateColumn(
        attrs={'th': {'class': 'node-list-table-thin'}},
113 114
        template_code=('{% include "dashboard/node-list/column-'
                       'actions.html" with btn_size="btn-xs" %}'),
115 116
    )

117 118 119 120
    class Meta:
        model = Node
        attrs = {'class': ('table table-bordered table-striped table-hover '
                           'node-list-table')}
121 122 123
        fields = ('pk', 'name', 'host', 'enabled', 'priority', 'overcommit',
                  'number_of_VMs', )

124

125
class GroupListTable(Table):
126 127 128 129 130 131 132 133 134 135 136
    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(
137
        orderable=False,
138 139 140 141 142
        template_name='dashboard/group-list/column-users.html',
        attrs={'th': {'class': 'group-list-table-admin'}},
    )

    admin = TemplateColumn(
143
        orderable=False,
144 145 146 147 148
        template_name='dashboard/group-list/column-admin.html',
        attrs={'th': {'class': 'group-list-table-admin'}},
    )

    actions = TemplateColumn(
149
        orderable=False,
150 151 152 153 154
        attrs={'th': {'class': 'group-list-table-thin'}},
        template_code=('{% include "dashboard/group-list/column-'
                       'actions.html" with btn_size="btn-xs" %}'),
    )

155 156 157 158
    class Meta:
        model = Group
        attrs = {'class': ('table table-bordered table-striped table-hover '
                           'group-list-table')}
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
        fields = ('pk', 'name', )


class UserListTable(Table):
    pk = TemplateColumn(
        template_name='dashboard/vm-list/column-id.html',
        verbose_name="ID",
        attrs={'th': {'class': 'vm-list-table-thin'}},
    )

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

    class Meta:
        model = User
        attrs = {'class': ('table table-bordered table-striped table-hover '
                           'vm-list-table')}
        fields = ('pk', 'username', )
178 179


180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
class NodeVmListTable(Table):
    pk = TemplateColumn(
        template_name='dashboard/vm-list/column-id.html',
        verbose_name="ID",
        attrs={'th': {'class': 'vm-list-table-thin'}},
    )

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

    admin = TemplateColumn(
        template_name='dashboard/vm-list/column-admin.html',
        attrs={'th': {'class': 'vm-list-table-admin'}},
    )
    details = TemplateColumn(
        template_name='dashboard/vm-list/column-details.html',
        attrs={'th': {'class': 'vm-list-table-thin'}},
    )
    actions = TemplateColumn(
        template_name='dashboard/vm-list/column-actions.html',
        attrs={'th': {'class': 'vm-list-table-thin'}},
    )
    time_of_suspend = TemplateColumn(
        '{{ record.time_of_suspend|timeuntil }}',
        verbose_name=_("Suspend in"))
    time_of_delete = TemplateColumn(
        '{{ record.time_of_delete|timeuntil }}',
        verbose_name=_("Delete in"))

    class Meta:
        model = Instance
        attrs = {'class': ('table table-bordered table-striped table-hover '
                           'vm-list-table')}
        fields = ('pk', 'name', 'state', 'time_of_suspend', 'time_of_delete', )
215 216


217 218 219 220 221
class UserListTablex(Table):
    class Meta:
        model = User


222
class TemplateListTable(Table):
223
    name = LinkColumn(
224 225
        'dashboard.views.template-detail',
        args=[A('pk')],
226
        attrs={'th': {'data-sort': "string"}}
227 228 229
    )
    num_cores = Column(
        verbose_name=_("Cores"),
230
        attrs={'th': {'data-sort': "int"}}
231 232 233
    )
    ram_size = TemplateColumn(
        "{{ record.ram_size }} Mb",
234
        attrs={'th': {'data-sort': "string"}}
235 236 237 238
    )
    lease = TemplateColumn(
        "{{ record.lease.name }}",
        verbose_name=_("Lease"),
239 240 241 242 243 244 245 246 247 248
        attrs={'th': {'data-sort': "string"}}
    )
    arch = Column(
        attrs={'th': {'data-sort': "string"}}
    )
    system = Column(
        attrs={'th': {'data-sort': "string"}}
    )
    access_method = Column(
        attrs={'th': {'data-sort': "string"}}
249 250 251
    )
    actions = TemplateColumn(
        verbose_name=_("Actions"),
252 253
        template_name="dashboard/template-list/column-template-actions.html",
        attrs={'th': {'class': 'template-list-table-thin'}},
254
        orderable=False,
255 256 257 258 259 260
    )

    class Meta:
        model = InstanceTemplate
        attrs = {'class': ('table table-bordered table-striped table-hover'
                           ' template-list-table')}
261
        fields = ('name', 'num_cores', 'ram_size', 'arch',
262
                  'system', 'access_method', 'lease', 'actions', )
263

264
        prefix = "template-"
265 266 267


class LeaseListTable(Table):
268
    name = LinkColumn(
269 270 271 272
        'dashboard.views.lease-detail',
        args=[A('pk')],
    )

273
    suspend_interval_seconds = TemplateColumn(
274 275 276
        "{{ record.get_readable_suspend_time }}"
    )

277
    delete_interval_seconds = TemplateColumn(
278 279 280 281 282
        "{{ record.get_readable_delete_time }}"
    )

    actions = TemplateColumn(
        verbose_name=_("Actions"),
283 284
        template_name="dashboard/template-list/column-lease-actions.html",
        orderable=False,
285 286 287 288 289 290
    )

    class Meta:
        model = Lease
        attrs = {'class': ('table table-bordered table-striped table-hover'
                           ' lease-list-table')}
291 292
        fields = ('name', 'suspend_interval_seconds',
                  'delete_interval_seconds', )
293
        prefix = "lease-"