tables.py 8.65 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 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 45 46 47
    enabled = BooleanColumn(
        attrs={'th': {'class': 'node-list-table-thin'}},
    )

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

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

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

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

69 70 71 72
    class Meta:
        model = Node
        attrs = {'class': ('table table-bordered table-striped table-hover '
                           'node-list-table')}
73 74 75
        fields = ('pk', 'name', 'host', 'enabled', 'priority', 'overcommit',
                  'number_of_VMs', )

76

77
class GroupListTable(Table):
78 79 80 81 82 83 84 85 86 87 88
    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(
89
        orderable=False,
90 91 92 93 94
        template_name='dashboard/group-list/column-users.html',
        attrs={'th': {'class': 'group-list-table-admin'}},
    )

    admin = TemplateColumn(
95
        orderable=False,
96 97 98 99 100
        template_name='dashboard/group-list/column-admin.html',
        attrs={'th': {'class': 'group-list-table-admin'}},
    )

    actions = TemplateColumn(
101
        orderable=False,
102 103 104 105 106
        attrs={'th': {'class': 'group-list-table-thin'}},
        template_code=('{% include "dashboard/group-list/column-'
                       'actions.html" with btn_size="btn-xs" %}'),
    )

107 108 109 110
    class Meta:
        model = Group
        attrs = {'class': ('table table-bordered table-striped table-hover '
                           'group-list-table')}
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
        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', )
130 131


132 133 134 135 136
class UserListTablex(Table):
    class Meta:
        model = User


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

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

187
        prefix = "template-"
188 189 190


class LeaseListTable(Table):
191
    name = LinkColumn(
192 193 194 195
        'dashboard.views.lease-detail',
        args=[A('pk')],
    )

196
    suspend_interval_seconds = TemplateColumn(
197 198 199
        "{{ record.get_readable_suspend_time }}"
    )

200
    delete_interval_seconds = TemplateColumn(
201 202 203 204 205
        "{{ record.get_readable_delete_time }}"
    )

    actions = TemplateColumn(
        verbose_name=_("Actions"),
206 207
        template_name="dashboard/template-list/column-lease-actions.html",
        orderable=False,
208 209 210 211 212 213
    )

    class Meta:
        model = Lease
        attrs = {'class': ('table table-bordered table-striped table-hover'
                           ' lease-list-table')}
214 215
        fields = ('name', 'suspend_interval_seconds',
                  'delete_interval_seconds', )
216
        prefix = "lease-"
217
        empty_text = _("No available leases.")
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245


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
246 247
        attrs = {'class': ('table table-bordered table-striped table-hover'),
                 'id': "profile-key-list-table"}
248
        fields = ('name', 'fingerprint', 'created', 'actions')
249 250
        prefix = "key-"
        empty_text = _("You haven't added any public keys yet.")
251 252 253


class ConnectCommandListTable(Table):
254 255 256
    name = LinkColumn(
        'dashboard.views.connect-command-detail',
        args=[A('pk')],
257 258
        attrs={'th': {'data-sort': "string"}}
    )
259 260
    access_method = Column(
        verbose_name=_("Access method"),
261 262 263 264 265 266 267 268
        attrs={'th': {'data-sort': "string"}}
    )
    template = Column(
        verbose_name=_("Template"),
        attrs={'th': {'data-sort': "string"}}
    )
    actions = TemplateColumn(
        verbose_name=_("Actions"),
269 270
        template_name=("dashboard/connect-command-list/column-command"
                       "-actions.html"),
271 272 273 274 275
        orderable=False,
    )

    class Meta:
        model = ConnectCommand
276 277 278
        attrs = {'class': ('table table-bordered table-striped table-hover'),
                 'id': "profile-command-list-table"}
        fields = ('name', 'access_method',  'template', 'actions')
279
        prefix = "cmd-"
280 281 282 283
        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.")