1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4
# not use this file except in compliance with the License. You may obtain
5
# a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
# License for the specific language governing permissions and limitations
17
from django.template.defaultfilters import filesizeformat # noqa
18
from django.utils.translation import ugettext_lazy as _ # noqa
20
from horizon import exceptions
21
from horizon import tables
22
from openstack_dashboard import api
25
LOG = logging.getLogger(__name__)
28
class CommonFilterAction(tables.FilterAction):
29
def filter(self, table, resources, filter_string):
30
q = filter_string.lower()
31
return [resource for resource in resources
32
if q in resource.resource.lower() or
33
q in resource.tenant.lower() or
34
q in resource.user.lower()]
37
def get_status(fields):
38
# TODO(lsmola) it should periodically renew the tables I guess
40
if any([getattr(datum, field, None) is 0 or getattr(datum, field, None)
41
for field in fields]):
48
class GlobalUsageTable(tables.DataTable):
49
tenant = tables.Column("tenant", verbose_name=_("Tenant"), sortable=True,
50
filters=(lambda (t): getattr(t, 'name', ""),))
51
user = tables.Column("user", verbose_name=_("User"), sortable=True,
52
filters=(lambda (u): getattr(u, 'name', ""),))
53
instance = tables.Column("resource",
54
verbose_name=_("Resource"),
58
class GlobalDiskUsageTable(tables.DataTable):
59
tenant = tables.Column("id", verbose_name=_("Tenant"), sortable=True)
60
disk_read_bytes = tables.Column("disk_read_bytes",
61
filters=(filesizeformat,),
62
verbose_name=_("Disk Read Bytes"),
64
disk_read_requests = tables.Column("disk_read_requests",
65
verbose_name=_("Disk Read Requests"),
67
disk_write_bytes = tables.Column("disk_write_bytes",
68
verbose_name=_("Disk Write Bytes"),
69
filters=(filesizeformat,),
71
disk_write_requests = tables.Column("disk_write_requests",
72
verbose_name=_("Disk Write Requests"),
76
name = "global_disk_usage"
77
verbose_name = _("Global Disk Usage (average of last 30 days)")
78
table_actions = (CommonFilterAction,)
82
class GlobalNetworkTrafficUsageTable(tables.DataTable):
83
tenant = tables.Column("id", verbose_name=_("Tenant"), sortable=True)
84
network_incoming_bytes = tables\
85
.Column("network_incoming_bytes",
86
verbose_name=_("Network Incoming Bytes"),
87
filters=(filesizeformat,),
89
network_incoming_packets = tables\
90
.Column("network_incoming_packets",
91
verbose_name=_("Network Incoming Packets"),
93
network_outgoing_bytes = tables\
94
.Column("network_outgoing_bytes",
95
verbose_name=_("Network Outgoing Bytes"),
96
filters=(filesizeformat,),
98
network_outgoing_packets = tables\
99
.Column("network_outgoing_packets",
100
verbose_name=_("Network Outgoing Packets"),
104
name = "global_network_traffic_usage"
105
verbose_name = _("Global Network Traffic Usage (average "
107
table_actions = (CommonFilterAction,)
111
class GlobalNetworkUsageTable(tables.DataTable):
112
tenant = tables.Column("id", verbose_name=_("Tenant"), sortable=True)
113
network_duration = tables.Column("network",
114
verbose_name=_("Network Duration"),
116
network_creation_requests = tables\
117
.Column("network_create",
118
verbose_name=_("Network Creation Requests"),
120
subnet_duration = tables.Column("subnet",
121
verbose_name=_("Subnet Duration"),
123
subnet_creation = tables.Column("subnet_create",
124
verbose_name=_("Subnet Creation Requests"),
126
port_duration = tables.Column("port",
127
verbose_name=_("Port Duration"),
129
port_creation = tables.Column("port_create",
130
verbose_name=_("Port Creation Requests"),
132
router_duration = tables.Column("router",
133
verbose_name=_("Router Duration"),
135
router_creation = tables.Column("router_create",
136
verbose_name=_("Router Creation Requests"),
138
port_duration = tables.Column("port",
139
verbose_name=_("Port Duration"),
141
port_creation = tables.Column("port_create",
142
verbose_name=_("Port Creation Requests"),
144
ip_floating_duration = tables\
145
.Column("ip_floating",
146
verbose_name=_("Floating IP Duration"),
148
ip_floating_creation = tables\
149
.Column("ip_floating_create",
150
verbose_name=_("Floating IP Creation Requests"),
154
name = "global_network_usage"
155
verbose_name = _("Global Network Usage (average of last 30 days)")
156
table_actions = (CommonFilterAction,)
160
class GlobalObjectStoreUsageUpdateRow(tables.Row):
163
def get_data(self, request, object_id):
164
ceilometer_usage = api.ceilometer.CeilometerUsage(request)
166
query = ceilometer_usage.query_from_object_id(object_id)
168
data = ceilometer_usage.global_object_store_usage(
170
with_statistics=True)
173
exceptions.handle(request,
174
_('Unable to retrieve statistics.'))
179
class GlobalObjectStoreUsageTable(tables.DataTable):
180
tenant = tables.Column("tenant", verbose_name=_("Tenant"), sortable=True,
181
filters=(lambda (t): getattr(t, 'name', ""),))
182
status = tables.Column(get_status(["storage_objects",
183
"storage_objects_size",
184
"storage_objects_incoming_bytes",
185
"storage_objects_outgoing_bytes"]),
186
verbose_name=_("Status"),
188
resource = tables.Column("resource",
189
verbose_name=_("Resource"),
191
storage_incoming_bytes = tables.Column(
192
"storage_objects_incoming_bytes",
193
verbose_name=_("Object Storage Incoming Bytes"),
194
filters=(filesizeformat,),
196
storage_outgoing_bytes = tables.Column(
197
"storage_objects_outgoing_bytes",
198
verbose_name=_("Object Storage Outgoing Bytes"),
199
filters=(filesizeformat,),
201
storage_objects = tables.Column(
203
verbose_name=_("Total Number of Objects"),
205
storage_objects_size = tables.Column(
206
"storage_objects_size",
207
filters=(filesizeformat,),
208
verbose_name=_("Total Size of Objects "),
212
name = "global_object_store_usage"
213
verbose_name = _("Global Object Store Usage (average of last 30 days)")
214
table_actions = (CommonFilterAction,)
215
row_class = GlobalObjectStoreUsageUpdateRow
216
status_columns = ["status"]