1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-16 22:50:10 +03:00

Feature #1179: Add vm history to vm tab

This commit is contained in:
Hector Sanjuan 2012-03-27 15:46:36 +02:00
parent 04e907bc78
commit aa0469acf6
3 changed files with 113 additions and 14 deletions

View File

@ -46,21 +46,24 @@ var OpenNebula = {
{
switch(type)
{
case "HOST","host":
case "HOST":
case "host":
return ["INIT",
"MONITORING",
"MONITORED",
"ERROR",
"DISABLED"][value];
break;
case "HOST_SIMPLE","host_simple":
case "HOST_SIMPLE":
case "host_simple":
return ["ON",
"ON",
"ON",
"ERROR",
"OFF"][value];
break;
case "VM","vm":
case "VM":
case "vm":
return ["INIT",
"PENDING",
"HOLD",
@ -70,7 +73,8 @@ var OpenNebula = {
"DONE",
"FAILED"][value];
break;
case "VM_LCM","vm_lcm":
case "VM_LCM":
case "vm_lcm":
return ["LCM_INIT",
"PROLOG",
"BOOT",
@ -89,7 +93,8 @@ var OpenNebula = {
"CLEANUP",
"UNKNOWN"][value];
break;
case "IMAGE","image":
case "IMAGE":
case "image":
return ["INIT",
"READY",
"USED",
@ -97,6 +102,14 @@ var OpenNebula = {
"LOCKED",
"ERROR"][value];
break;
case "VM_MIGRATE_REASON":
case "vm_migrate_reason":
return ["NONE",
"ERROR",
"STOP_RESUME",
"USER",
"CANCEL"][value];
break;
default:
return;
}

View File

@ -593,6 +593,10 @@ var vm_info_panel = {
"vm_log_tab" : {
title: tr("VM log"),
content: ""
},
"vm_history_tab" : {
title: tr("History information"),
content: "",
}
}
@ -627,11 +631,11 @@ function ip_str(vm){
var ip = '--';
if ($.isArray(nic)) {
ip = '';
$.each(nic, function(index,value){
ip += value.IP+'<br />';
});
$.each(nic, function(index,value){
ip += value.IP+'<br />';
});
} else if (nic && nic.IP) {
ip = nic.IP;
ip = nic.IP;
};
return ip;
};
@ -719,7 +723,69 @@ function updateVMachinesView(request, vmachine_list){
updateView(vmachine_list_array,dataTable_vMachines);
updateDashboard("vms",vmachine_list);
updateVResDashboard("vms",vmachine_list);
}
};
function generateHistoryTable(vm){
var html = ' <table id="vm_history_table" class="info_table" style="width:80%">\
<thead>\
<tr>\
<th>'+tr("Sequence")+'</th>\
<th>'+tr("Hostname")+'</th>\
<th>'+tr("Reason")+'</th>\
<th>'+tr("State change time")+'</th>\
<th>'+tr("Total time")+'</th>\
<th colspan="2">'+tr("Prolog time")+'</th>\
</tr>\
</thead>\
<tbody>';
var history = [];
if ($.isArray(vm.HISTORY_RECORDS.HISTORY))
history = vm.HISTORY_RECORDS.HISTORY;
else if (vm.HISTORY_RECORDS.HISTORY.SEQ)
history = [vm.HISTORY_RECORDS.HISTORY];
var now = Math.round(new Date().getTime() / 1000);
for (var i=0; i < history.length; i++){
// :TIME time calculations copied from onevm_helper.rb
var stime = parseInt(history[i].STIME, 10);
var etime = parseInt(history[i].ETIME, 10)
etime = etime == 0 ? now : etime;
var dtime = etime - stime;
// end :TIME
//:PTIME
var stime2 = parseInt(history[i].PSTIME, 10);
var etime2;
var ptime2 = parseInt(history[i].PETIME, 10);
if (stime2 == 0)
etime2 = 0;
else
etime2 = ptime2 == 0 ? now : ptime2;
var dtime2 = etime2 - stime2;
//end :PTIME
html += ' <tr>\
<td style="width:20%">'+history[i].SEQ+'</td>\
<td style="width:20%">'+history[i].HOSTNAME+'</td>\
<td style="width:16%">'+OpenNebula.Helper.resource_state("VM_MIGRATE_REASON",parseInt(history[i].REASON, 10))+'</td>\
<td style="width:16%">'+pretty_time(history[i].STIME)+'</td>\
<td style="width:16%">'+pretty_time_runtime(dtime)+'</td>\
<td style="width:16%">'+pretty_time_runtime(dtime2)+'</td>\
<td></td>\
</tr>'
};
html += '</tbody>\
</table>';
return html;
};
// Refreshes the information panel for a VM
@ -821,7 +887,7 @@ function updateVMInfo(request,vm){
</tr>\
</tbody>\
</table>'
}
};
var template_tab = {
title: tr("VM Template"),
@ -830,21 +896,27 @@ function updateVMInfo(request,vm){
<thead><tr><th colspan="2">'+tr("VM template")+'</th></tr></thead>'+
prettyPrintJSON(vm_info.TEMPLATE)+
'</table>'
}
};
var log_tab = {
title: tr("VM log"),
content: '<div>'+spinner+'</div>'
}
};
var monitoring_tab = {
title: tr("Monitoring information"),
content: generateMonitoringDivs(vm_graphs,"vm_monitor_")
}
};
var history_tab = {
title: tr("History information"),
content: generateHistoryTable(vm_info),
};
Sunstone.updateInfoPanelTab("vm_info_panel","vm_info_tab",info_tab);
Sunstone.updateInfoPanelTab("vm_info_panel","vm_template_tab",template_tab);
Sunstone.updateInfoPanelTab("vm_info_panel","vm_log_tab",log_tab);
Sunstone.updateInfoPanelTab("vm_info_panel","vm_history_tab",history_tab);
Sunstone.updateInfoPanelTab("vm_info_panel","vm_monitoring_tab",monitoring_tab);
//Pop up the info panel and asynchronously get vm_log and stats

View File

@ -60,6 +60,20 @@ function pretty_time_axis(time){
return hour + ":" + mins + ":" + secs;// + "&nbsp;" + month + "/" + day;
}
function pretty_time_runtime(time){
var d = new Date();
d.setTime(time*1000);
var secs = pad(d.getUTCSeconds(),2);
var hour = pad(d.getUTCHours(),2);
var mins = pad(d.getUTCMinutes(),2);
var day = d.getUTCDate()-1;
var month = pad(d.getUTCMonth()+1,2); //getMonths returns 0-11
var year = d.getUTCFullYear();
return day + "d " + hour + ":" + mins;// + ":" + secs;// + "&nbsp;" + month + "/" + day;
}
//returns a human readable size in Kilo, Mega, Giga or Tera bytes
function humanize_size(value) {
if (typeof(value) === "undefined") {