1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

feature #3748: Add vm placement panel

This commit is contained in:
Daniel Molina 2015-06-09 18:13:36 +02:00
parent 2b350794f9
commit 7d393820a6
3 changed files with 186 additions and 0 deletions

View File

@ -22,6 +22,7 @@ define(function(require) {
require('./vms-tab/panels/storage'),
require('./vms-tab/panels/network'),
require('./vms-tab/panels/snapshots'),
require('./vms-tab/panels/placement'),
// require('./vms-tab/panels/template')
];

View File

@ -0,0 +1,182 @@
define(function(require) {
/*
DEPENDENCIES
*/
var Locale = require('utils/locale');
var Humanize = require('utils/humanize');
var OpenNebulaVM = require('opennebula/vm');
/*
CONSTANTS
*/
var TAB_ID = require('../tabId');
var PANEL_ID = require('./placement/panelId');
var RESOURCE = "VM";
var XML_ROOT = "VM";
/*
CONSTRUCTOR
*/
function Panel(info) {
this.panelId = PANEL_ID;
this.title = Locale.tr("Placement");
this.icon = "fa-sitemap";
this.element = info[XML_ROOT];
return this;
};
Panel.PANEL_ID = PANEL_ID;
Panel.prototype.html = _html;
Panel.prototype.setup = _setup;
return Panel;
/*
FUNCTION DEFINITIONS
*/
function _html() {
var that = this;
var html = '<div class="row"><div class="large-12 columns">\
<table id="vm_history_table" class="extended_table dataTable">\
<thead>\
<tr>\
<th>' + Locale.tr("#") + '</th>\
<th>' + Locale.tr("Host") + '</th>\
<th>' + Locale.tr("Datastore") + '</th>\
<th>' + Locale.tr("Action") + '</th>\
<th>' + Locale.tr("Reason") + '</th>\
<th>' + Locale.tr("Chg time") + '</th>\
<th>' + Locale.tr("Total time") + '</th>\
<th colspan="2">' + Locale.tr("Prolog time") + '</th>\
</tr>\
</thead>\
<tbody>' ;
var history = [];
if (that.element.HISTORY_RECORDS.HISTORY) {
if ($.isArray(that.element.HISTORY_RECORDS.HISTORY))
history = that.element.HISTORY_RECORDS.HISTORY;
else if (that.element.HISTORY_RECORDS.HISTORY.SEQ)
history = [that.element.HISTORY_RECORDS.HISTORY];
} else {
html += ' <tr>\
<td colspan="8" style="width:5%">' + Locale.tr("No data available in table") + '</td>\
</tr>'
}
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:5%">' + history[i].SEQ + '</td>\
<td style="width:15%">' + history[i].HOSTNAME + '</td>\
<td style="width:5%">' + history[i].DS_ID + '</td>\
<td style="width:16%">' + OpenNebulaVM.migrateActionStr(parseInt(history[i].ACTION, 10)) + '</td>\
<td style="width:10%">' + OpenNebulaVM.migrateReasonStr(parseInt(history[i].REASON, 10)) + '</td>\
<td style="width:16%">' + Humanize.prettyTime(history[i].STIME) + '</td>\
<td style="width:16%">' + Humanize.prettyDuration(dtime) + '</td>\
<td style="width:16%">' + Humanize.prettyDuration(dtime2) + '</td>\
<td></td>\
</tr>'
};
html += '</tbody>\
</table>\
</div>\
</div>' ;
if (that.element.USER_TEMPLATE.SCHED_MESSAGE) {
html += '<div class="row">\
<div class="large-12 columns">\
<table id="vm_ds_placement_table" class="extended_table dataTable">\
<thead>\
<tr>\
<th align="center">' + Locale.tr("Sched Message") + '</th>\
</tr>\
</thead>\
<tbody>\
<tr>\
<td>' + that.element.USER_TEMPLATE.SCHED_MESSAGE + '</td>\
</tr>\
</tbody>\
</table>\
</div>\
</div>' ;
}
var requirements_str = that.element.USER_TEMPLATE.SCHED_REQUIREMENTS ? that.element.USER_TEMPLATE.SCHED_REQUIREMENTS : "-";
var rank_str = that.element.USER_TEMPLATE.SCHED_RANK ? that.element.USER_TEMPLATE.SCHED_RANK : "-";
var ds_requirements_str = that.element.USER_TEMPLATE.SCHED_DS_REQUIREMENTS ? that.element.USER_TEMPLATE.SCHED_DS_REQUIREMENTS : "-";
var ds_rank_str = that.element.USER_TEMPLATE.SCHED_DS_RANK ? that.element.USER_TEMPLATE.SCHED_DS_RANK : "-";
html += '<div class="row">\
<div class="large-9 columns">\
<table id="vm_placement_table" class="extended_table dataTable">\
<thead>\
<tr>\
<th colspan="2" align="center">' + Locale.tr("Placement - Host") + '</th>\
</tr>\
</thead>\
<tbody>\
<tr>\
<td>' + Locale.tr("Requirements") + '</td>\
<td>' + requirements_str + '</td>\
</tr>\
<tr>\
<td>' + Locale.tr("Rank") + '</td>\
<td>' + rank_str + '</td>\
</tr>\
</tbody>\
</table>\
<table id="vm_ds_placement_table" class="extended_table dataTable">\
<thead>\
<tr>\
<th colspan="2" align="center">' + Locale.tr("Placement - Datastore") + '</th>\
</tr>\
</thead>\
<tbody>\
<tr>\
<td>' + Locale.tr("DS Requirements") + '</td>\
<td>' + ds_requirements_str + '</td>\
</tr>\
<tr>\
<td>' + Locale.tr("DS Rank") + '</td>\
<td>' + ds_rank_str + '</td>\
</tr>\
</tbody>\
</table>\
</div>\
</div>' ;
return html;
}
function _setup(context) {
}
});

View File

@ -0,0 +1,3 @@
define(function(require) {
return 'vm_placement_tab';
});