-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontroller.js
More file actions
287 lines (277 loc) · 7.52 KB
/
Copy pathcontroller.js
File metadata and controls
287 lines (277 loc) · 7.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
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
215
216
217
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/**
* OpenStack client in Javascript.
* mds900 20150703
*/
// TODO: Restrict the scope of this
"use strict";
var keystone, nova;
function populateTenantSelector(tenants) {
var target = $("#tenantSelect").empty();
$(tenants).each(function(i, tenant) {
target.append(
$("<option>")
.attr({ label: tenant.name, value: tenant.id })
.text(tenant.description ? (tenant.description + " (" + tenant.name + ")") : tenant.name)
);
});
}
function populateCatalog(catalog) {
$("#catalog table").DataTable().clear().rows.add(catalog).draw();
}
function populateTenants(tenants) {
$("#tenants table").DataTable().clear().rows.add(tenants).draw();
}
function addDownloadLinks() {
$("table.dataTable").each(function() {
var downloadLink = $("<a>").append("Export to CSV");
$.fn.toCSV.makeDownloadLink(downloadLink, $(this), "export");
$(this).parent().append(downloadLink);
});
}
function populateInstances(instances) {
$(instances).each(function(i, instance) {
var addresses = [];
$.each(instance.addresses, function(j, network) {
$(network).each(function(k, port) {
addresses.push(port.addr);
});
});
instance.addressList = addresses.join(", ");
});
$("#instances table").DataTable().clear().rows.add(instances).draw();
retrieveTenantResourceUse(keystone, instances, function(tenantResourceUse) {
makePieChartDataTenantResource("vcpus", tenantResourceUse, function(pieChartData) {
var dest = $("#pieChartTenantVCPUs");
makePieChart(dest, {
"header": {
"title": {
"text": "vCPU Use"
},
"subtitle": {
"text": "By Tenant"
}
},
"size": {
"canvasHeight": dest.height(),
"canvasWidth": dest.width()
},
tooltips: {
"string": "{label}: {value} vCPUs ({percentage}%)"
},
"data": {
content: pieChartData
}
});
});
makePieChartDataTenantResource("ram", tenantResourceUse, function(pieChartData) {
var dest = $("#pieChartTenantMemory");
makePieChart(dest, {
"header": {
"title": {
"text": "Memory Use"
},
"subtitle": {
"text": "By Tenant"
}
},
"size": {
"canvasHeight": dest.height(),
"canvasWidth": dest.width()
},
tooltips: {
"string": "{label}: {value} MB ({percentage}%)"
},
"data": {
content: pieChartData
}
});
});
makePieChartDataTenantResource("disk", tenantResourceUse, function(pieChartData) {
var dest = $("#pieChartTenantLocalDisk");
makePieChart(dest, {
"header": {
"title": {
"text": "Local Disk Use"
},
"subtitle": {
"text": "By Tenant"
}
},
"size": {
"canvasHeight": dest.height(),
"canvasWidth": dest.width()
},
tooltips: {
"string": "{label}: {value} GB ({percentage}%)"
},
"data": {
content: pieChartData
}
});
});
});
}
function populateHypervisors(hypervisors) {
$("#hypervisors table").DataTable().clear().rows.add(hypervisors).draw();
}
function onAuthenticated(catalog) {
populateCatalog(catalog);
keystone.getTenants(false).done(populateTenantSelector);
keystone.getTenants(true).done(populateTenants);
// Use the catalog to connect to Nova
keystone.getEndpoint({
serviceType: "compute",
endpointType: "public"
}).done(function(novaURL) {
nova = new osclient.Nova({
publicURL: novaURL,
token: keystone.getToken()
});
// Use Nova to retrieve a list of instances
nova.getAllInstancesDetailed().done(populateInstances);
$("#tenantResourceUse .pieChart").on("segmentClicked.d3pie", function(event, data) {
// TODO
console.log("Pie segment for tenant " + data.data.id + " " + (data.expanded ? "un" : "") + "expanded");
});
// Use Nova to retrieve a list of hypervisors
nova.getHypervisorsDetailed().done(populateHypervisors);
retrieveResourceUse(nova, function(resourceUse) {
makePieChartDataResource('vcpus', resourceUse, function(pieChartData) {
var dest = $("#pieChartVCPUs");
makePieChart(dest, {
"header": {
"title": {
"text": "vCPU Use"
},
"subtitle": {
"text": "Total"
}
},
"size": {
"canvasHeight": dest.height(),
"canvasWidth": dest.width()
},
tooltips: {
"string": "{label}: {value} vCPUs ({percentage}%)"
},
"data": {
content: pieChartData
}
});
});
makePieChartDataResource('ram', resourceUse, function(pieChartData) {
var dest = $("#pieChartMemory");
makePieChart(dest, {
"header": {
"title": {
"text": "Memory Use"
},
"subtitle": {
"text": "Total"
}
},
"size": {
"canvasHeight": dest.height(),
"canvasWidth": dest.width()
},
tooltips: {
"string": "{label}: {value} MB ({percentage}%)"
},
"data": {
content: pieChartData
}
});
});
makePieChartDataResource('disk', resourceUse, function(pieChartData) {
var dest = $("#pieChartLocalDisk");
makePieChart(dest, {
"header": {
"title": {
"text": "Local Disk Use"
},
"subtitle": {
"text": "Total"
}
},
"size": {
"canvasHeight": dest.height(),
"canvasWidth": dest.width()
},
tooltips: {
"string": "{label}: {value} GB ({percentage}%)"
},
"data": {
content: pieChartData
}
});
});
});
});
addDownloadLinks();
};
(function($) {
$(function() {
var tenantSelect = $("#tenantSelect");
$("button, input[type=button], input[type=checkbox]").button();
$('input[type=text]').addClass("ui-widget ui-widget-content ui-corner-all");
$('select').menu();
$('textfield.numeric, input.numeric').spinner();
$("#tenants table").DataTable({
columns: [
{ "data": "name", title: "Name" },
{ "data": "description", title: "Description" },
{ "data": "enabled", title: "Enabled" }
]
});
$("#catalog table").DataTable({
columns: [
{ "data": "type", title: "Type" },
{ "data": "name", title: "Name" }
]
});
$("#instances table").DataTable({
columns: [
{ "data": "name", title: "Name" },
{ "data": "status", title: "Status" },
{ "data": "addressList", title: "IP Addresses" },
{ "data": "user_id", title: "User ID" },
{ "data": "tenant_id", title: "Tenant ID" }
// { "data": , title: "" },
]
});
$("#hypervisors table").DataTable({
columns: [
{ "data": "current_workload", title: "Workload" },
{ "data": "disk_available_least", title: "Least Available Disk" },
{ "data": "free_disk_gb", title: "Free Disk" },
{ "data": "free_ram_mb", title: "Free RAM" },
{ "data": "host_ip", title: "IP" },
{ "data": "hypervisor_hostname", title: "Hostname" },
{ "data": "hypervisor_type", title: "Type" },
{ "data": "hypervisor_version", title: "Version" },
{ "data": "id", title: "ID" },
{ "data": "local_gb", title: "Local GB" },
{ "data": "local_gb_used", title: "Local GB Used" },
{ "data": "memory_mb", title: "Memory" },
{ "data": "memory_mb_used", title: "Memory Used" },
{ "data": "running_vms", title: "Running VMs" },
{ "data": "vcpus", title: "VCPUs" },
{ "data": "vcpus_used", title: "VCPUs Used" }
]
});
tenantSelect.on("change", function() {
keystone.setTenantID(tenantSelect.val());
keystone.authenticate().done(onAuthenticated);
});
$("#goButton").on("click", function() {
keystone = new osclient.Keystone({
authURL: $("#keystoneBaseURL").val(),
domainName: 'default',
username: $("#username").val(),
password: $("#password").val()
});
keystone.authenticate().done(onAuthenticated);
return false;
});
});
})(jQuery);