diff --git a/src/sunstone/public/app/tabs/provision-tab.js b/src/sunstone/public/app/tabs/provision-tab.js
index a42f4e12df..068dce2ea4 100644
--- a/src/sunstone/public/app/tabs/provision-tab.js
+++ b/src/sunstone/public/app/tabs/provision-tab.js
@@ -16,6 +16,12 @@ define(function(require) {
var QuotaLimits = require('utils/quotas/quota-limits');
var Graphs = require('utils/graphs');
+ var ProvisionQuotaWidget = require('./provision-tab/users/quota-widget');
+
+ var ProvisionVmsList = require('./provision-tab/vms/list');
+ var ProvisionUsersList = require('./provision-tab/users/list');
+ var ProvisionFlowsList = require('./provision-tab/flows/list');
+
// Templates
var TemplateContent = require('hbs!./provision-tab/content');
var TemplateHeader = require('hbs!./provision-tab/header');
@@ -26,141 +32,11 @@ define(function(require) {
var TemplateDashboardVdcVms = require('hbs!./provision-tab/dashboard/vdc-vms');
var TemplateDashboardUsers = require('hbs!./provision-tab/dashboard/users');
- var TemplateVmsList = require('hbs!./provision-tab/vms/list');
- var TemplateFlowsList = require('hbs!./provision-tab/flows/list');
- var TemplateUsersList = require('hbs!./provision-tab/users/list');
var TemplateGroupInfo = require('hbs!./provision-tab/group/info');
var TemplateTemplatesList = require('hbs!./provision-tab/templates/list');
var TAB_ID = require('./provision-tab/tabId');
- function setup_provision_quota_widget(context){
- // Mode selector, for the 3 sliders
- $("select.provision_quota_select", context).on('change', function(){
- var row = $(this).closest(".row");
-
- switch($(this).val()) {
- case "edit":
- $("div.provision_quota_edit", row).show();
- $("div.provision_quota_default", row).hide();
- $("div.provision_quota_unlimited", row).hide();
-
- $("input", row).change();
-
- break;
-
- case "default":
- $("div.provision_quota_edit", row).hide();
- $("div.provision_quota_default", row).show();
- $("div.provision_quota_unlimited", row).hide();
-
- break;
-
- case "unlimited":
- $("div.provision_quota_edit", row).hide();
- $("div.provision_quota_default", row).hide();
- $("div.provision_quota_unlimited", row).show();
-
- break;
- }
-
- return false;
- });
-
- var provision_rvms_quota_input = $(".provision_rvms_quota_input", context);
-
- $( ".provision_rvms_quota_slider", context).on('change', function(){
- provision_rvms_quota_input.val($(this).attr('data-slider'))
- });
-
- provision_rvms_quota_input.change(function() {
- $( ".provision_rvms_quota_slider", context).foundation(
- 'slider', 'set_value', this.value);
- });
-
- var provision_cpu_quota_input = $(".provision_cpu_quota_input", context);
-
- $( ".provision_cpu_quota_slider", context).on('change', function(){
- provision_cpu_quota_input.val($(this).attr('data-slider'))
- });
-
- provision_cpu_quota_input.change(function() {
- $( ".provision_cpu_quota_slider", context).foundation(
- 'slider', 'set_value', this.value);
- });
-
- var provision_memory_quota_input = $(".provision_memory_quota_input", context);
- var provision_memory_quota_tmp_input = $(".provision_memory_quota_tmp_input", context);
-
- var update_final_memory_input = function() {
- var value = provision_memory_quota_tmp_input.val();
- if (value > 0) {
- provision_memory_quota_input.val( Math.floor(value * 1024) );
- } else {
- provision_memory_quota_input.val(value);
- }
- }
-
- $( ".provision_memory_quota_slider", context).on('change', function(){
- provision_memory_quota_tmp_input.val($(this).attr('data-slider'));
- update_final_memory_input();
- });
-
- provision_memory_quota_tmp_input.change(function() {
- update_final_memory_input();
- $( ".provision_memory_quota_slider", context).foundation(
- 'slider', 'set_value', this.value);
- });
-
- $(".provision_rvms_quota_input", context).val('').change();
- $(".provision_memory_quota_input", context).val('').change();
- $(".provision_memory_quota_tmp_input", context).val('').change();
- $(".provision_cpu_quota_input", context).val('').change();
- }
-
- function reset_provision_quota_widget(context){
- $("select.provision_quota_select", context).val('edit').change();
-
- $(".provision_rvms_quota_input", context).val('').change();
- $(".provision_memory_quota_input", context).val('').change();
- $(".provision_memory_quota_tmp_input", context).val('').change();
- $(".provision_cpu_quota_input", context).val('').change();
- }
-
- function retrieve_provision_quota_widget(context){
- var retrieve_quota = function(select, input){
- switch(select.val()) {
- case "edit":
- return input.val();
- case "default":
- return QuotaLimits.QUOTA_LIMIT_DEFAULT;
- case "unlimited":
- return QuotaLimits.QUOTA_LIMIT_UNLIMITED;
- }
- }
-
- var vms_limit = retrieve_quota(
- $(".provision_rvms_quota select.provision_quota_select", context),
- $(".provision_rvms_quota_input", context));
-
- var cpu_limit = retrieve_quota(
- $(".provision_cpu_quota select.provision_quota_select", context),
- $(".provision_cpu_quota_input", context));
-
- var mem_limit = retrieve_quota(
- $(".provision_memory_quota select.provision_quota_select", context),
- $(".provision_memory_quota_input", context));
-
- return {
- "VM" : {
- "VOLATILE_SIZE": QuotaLimits.QUOTA_LIMIT_DEFAULT,
- "VMS": vms_limit,
- "MEMORY": mem_limit,
- "CPU": cpu_limit
- }
- };
- }
-
var provision_user_info = '
'+
'
'+
'
'+
@@ -400,13 +276,6 @@ define(function(require) {
'
'+
'
';
-
- var list_users_accordion_id = 0;
- function provision_list_users(opts_arg){
- list_users_accordion_id += 1;
- return TemplateUsersList({'accordionId': list_users_accordion_id});
- }
-
var list_templates_accordion_id = 0;
function provision_list_templates(opts_arg){
opts = $.extend({
@@ -421,32 +290,6 @@ define(function(require) {
return TemplateTemplatesList({'accordionId': list_templates_accordion_id, 'opts': opts});
}
- var list_vms_accordion_id = 0;
- function provision_list_vms(opts_arg){
- opts = $.extend({
- title: Locale.tr("Virtual Machines"),
- refresh: true,
- create: true,
- filter: true
- },opts_arg)
-
- list_vms_accordion_id += 1;
- return TemplateVmsList({'accordionId': list_vms_accordion_id, 'opts': opts});
- }
-
- var list_flows_accordion_id = 0;
- function provision_list_flows(opts_arg){
- opts = $.extend({
- title: Locale.tr("Services"),
- active: true,
- refresh: true,
- create: true,
- filter: true
- },opts_arg)
-
- list_flows_accordion_id += 1;
- return TemplateVmsList({'accordionId': list_flows_accordion_id, 'opts': opts});
- }
var povision_actions = {
"Provision.User.show" : {
@@ -483,7 +326,7 @@ define(function(require) {
if ( $("div#provision_create_user_manual_quota",
$("#provision_create_user")).hasClass("active") ){
- quota_json = retrieve_provision_quota_widget($("#provision_create_user"));
+ quota_json = ProvisionQuotaWidget.retrieve($("#provision_create_user"));
Sunstone.runAction("Provision.User.set_quota",
[response.USER.ID], quota_json);
@@ -515,7 +358,7 @@ define(function(require) {
call: OpenNebula.ServiceTemplate.instantiate,
callback: function(){
OpenNebula.Action.clear_cache("SERVICE");
- show_provision_flow_list(0);
+ ProvisionFlowsList.show(0);
var context = $("#provision_create_flow");
$("#flow_name", context).val('');
//$(".provision_selected_networks").html("");
@@ -1352,7 +1195,7 @@ define(function(require) {
var deploying = 0;
$.each(item_list, function(index, vm){
- var state = get_provision_vm_state(vm.VM);
+ var state = ProvisionVmsList.state(vm.VM);
total = total + 1;
@@ -1572,30 +1415,6 @@ define(function(require) {
$(document).foundation();
}
- function show_provision_vm_list(timeout, context) {
- $(".section_content").hide();
- $(".provision_vms_list_section").fadeIn();
-
- $("dd:not(.active) .provision_back", $(".provision_vms_list_section")).trigger("click");
- $(".provision_vms_list_refresh_button", $(".provision_vms_list_section")).trigger("click");
- }
-
- function show_provision_flow_list(timeout) {
- $(".section_content").hide();
- $(".provision_flows_list_section").fadeIn();
-
- $("dd:not(.active) .provision_back", $(".provision_flows_list_section")).trigger("click");
- $(".provision_flows_list_refresh_button", $(".provision_flows_list_section")).trigger("click");
- }
-
- function show_provision_user_list(timeout) {
- $(".section_content").hide();
- $(".provision_users_list_section").fadeIn();
-
- $("dd:not(.active) .provision_back", $(".provision_users_list_section")).trigger("click");
- $(".provision_users_list_refresh_button", $(".provision_users_list_section")).trigger("click");
- }
-
function show_provision_vdc_info() {
$(".section_content").hide();
$("#provision_manage_vdc").fadeIn();
@@ -1704,7 +1523,6 @@ define(function(require) {
});
}
-
function update_provision_flow_templates_datatable(datatable, timeout) {
datatable.html('
'+
'
'+
@@ -1743,1113 +1561,6 @@ define(function(require) {
}, timeout);
}
-
- function update_provision_users_datatable(datatable, timeout) {
- datatable.html(''+
- ''+
- ' '+
- ' '+
- ' '+
- ' '+
- ' '+
- ''+
- ' '+
- '
');
-
- setTimeout( function(){
- OpenNebula.User.list({
- timeout: true,
- success: function (request, item_list, quotas_list){
- datatable.fnClearTable(true);
- if (item_list.length == 0) {
- datatable.html(''+
- ''+
- ' '+
- ' '+
- ' '+
- ' '+
- ' '+
- ''+
- Locale.tr("The list of users is empty")+
- ' '+
- '
');
- } else {
- provision_quotas_list = quotas_list;
- datatable.fnAddData(item_list);
- }
- },
- error: Notifier.onError
- })
- }, timeout );
- }
-
- function fill_provision_vms_datatable(datatable, item_list){
- datatable.fnClearTable(true);
- if (item_list.length == 0) {
- datatable.html(''+
- ''+
- ' '+
- ' '+
- ' '+
- ' '+
- ' '+
- ''+
- Locale.tr("There are no Virtual Machines")+
- ' '+
- ' '+
- ' '+
- '
');
- } else {
- datatable.fnAddData(item_list);
- }
- }
-
- function update_provision_vms_datatable(datatable, timeout) {
- datatable.html(''+
- ''+
- ' '+
- ' '+
- ' '+
- ' '+
- ' '+
- ''+
- ' '+
- '
');
-
- var data = datatable.data('opennebula');
- if (data) {
- fill_provision_vms_datatable(datatable, data)
- } else {
- setTimeout( function(){
- OpenNebula.VM.list({
- timeout: true,
- success: function (request, item_list){
- fill_provision_vms_datatable(datatable, item_list)
- },
- error: Notifier.onError
- })
- }, timeout );
- }
- }
-
- function update_provision_flows_datatable(datatable, timeout) {
- datatable.html(''+
- ''+
- ' '+
- ' '+
- ' '+
- ' '+
- ' '+
- ''+
- ' '+
- '
');
-
- setTimeout( function(){
- OpenNebula.Service.list({
- timeout: true,
- success: function (request, item_list){
- $(".flow_error_message").hide();
- datatable.fnClearTable(true);
- if (item_list.length == 0) {
- datatable.html(''+
- ''+
- ' '+
- ' '+
- ' '+
- ' '+
- ' '+
- ''+
- Locale.tr("There are no Services")+
- ' '+
- ' '+
- ' '+
- '
');
- } else {
- datatable.fnAddData(item_list);
- }
- },
- error: function(request, error_json) {
- datatable.html(''+
- '
'+
- '
'+
- '
'+
- '
'+
- '
'+Locale.tr("Cannot connect to OneFlow server")+'
'+
- '
'+
- '
'+
- '
'+
- '
'+
- '
'+
- ' '+
- '
');
-
- Notifier.onError(request, error_json, $(".flow_error_message"));
- }
- })
- }, timeout );
- }
-
-
- function get_provision_flow_start_time(data) {
- if (data.log) {
- return data.log[0].timestamp
- } else {
- return null;
- }
- }
-
- // @params
- // data: and BODY object of the Document representing the Service
- // Example: data.ID
- // @returns and object containing the following properties
- // color: css class for this state.
- // color + '-color' font color class
- // color + '-bg' background class
- // str: user friendly state string
- function get_provision_flow_state(data) {
- var state = OpenNebula.Service.state(data.state);
- var state_color;
- var state_str;
-
- switch (state) {
- case Locale.tr("PENDING"):
- state_color = 'deploying';
- state_str = Locale.tr("PENDING");
- break;
- case Locale.tr("DEPLOYING"):
- state_color = 'deploying';
- state_str = Locale.tr("DEPLOYING");
- break;
- case Locale.tr("UNDEPLOYING"):
- state_color = 'powering_off';
- state_str = Locale.tr("UNDEPLOYING");
- break;
- case Locale.tr("FAILED_UNDEPLOYING"):
- state_color = 'error';
- state_str = Locale.tr("FAILED UNDEPLOYING");
- break;
- case Locale.tr("FAILED_DEPLOYING"):
- state_color = 'error';
- state_str = Locale.tr("FAILED DEPLOYING");
- break;
- case Locale.tr("FAILED_SCALING"):
- state_color = 'error';
- state_str = Locale.tr("FAILED SCALING");
- break;
- case Locale.tr("WARNING"):
- state_color = 'error';
- state_str = Locale.tr("WARNING");
- break;
- case Locale.tr("RUNNING"):
- state_color = 'running';
- state_str = Locale.tr("RUNNING");
- break;
- case Locale.tr("SCALING"):
- state_color = 'deploying';
- state_str = Locale.tr("SCALING");
- break;
- case Locale.tr("COOLDOWN"):
- state_color = 'error';
- state_str = Locale.tr("COOLDOWN");
- break;
- case Locale.tr("DONE"):
- state_color = 'off';
- state_str = Locale.tr("DONE");
- break;
- default:
- state_color = 'powering_off';
- state_str = Locale.tr("UNKNOWN");
- break;
- }
-
- return {
- color: state_color,
- str: state_str
- }
- }
-
- // @params
- // data: and VM object
- // Example: data.ID
- // @returns and object containing the following properties
- // color: css class for this state.
- // color + '-color' font color class
- // color + '-bg' background class
- // str: user friendly state string
- function get_provision_vm_state(data) {
- var state = OpenNebula.VM.stateStr(data.STATE);
- var state_color;
- var state_str;
-
- switch (state) {
- case "INIT":
- case "PENDING":
- case "HOLD":
- state_color = 'deploying';
- state_str = Locale.tr("DEPLOYING") + " (1/3)";
- break;
- case "FAILED":
- state_color = 'error';
- state_str = Locale.tr("ERROR");
- break;
- case "ACTIVE":
- var lcm_state = OpenNebula.VM.shortLcmStateStr(data.LCM_STATE);
-
- switch (lcm_state) {
- case "LCM_INIT":
- state_color = 'deploying';
- state_str = Locale.tr("DEPLOYING") + " (1/3)";
- break;
- case "PROLOG":
- state_color = 'deploying';
- state_str = Locale.tr("DEPLOYING") + " (2/3)";
- break;
- case "BOOT":
- state_color = 'deploying';
- state_str = Locale.tr("DEPLOYING") + " (3/3)";
- break;
- case "RUNNING":
- case "SNAPSHOT":
- case "MIGRATE":
- state_color = 'running';
- state_str = Locale.tr("RUNNING");
- break;
- case "HOTPLUG":
- state_color = 'deploying';
- state_str = Locale.tr("SAVING IMAGE");
- break;
- case "FAILURE":
- state_color = 'error';
- state_str = Locale.tr("ERROR");
- break;
- case "SAVE":
- case "EPILOG":
- case "SHUTDOWN":
- case "CLEANUP":
- state_color = 'powering_off';
- state_str = Locale.tr("POWERING OFF");
- break;
- case "UNKNOWN":
- state_color = 'powering_off';
- state_str = Locale.tr("UNKNOWN");
- break;
- default:
- state_color = 'powering_off';
- state_str = Locale.tr("UNKNOWN");
- break;
- }
-
- break;
- case "STOPPED":
- case "SUSPENDED":
- case "POWEROFF":
- state_color = 'off';
- state_str = Locale.tr("OFF");
-
- break;
- default:
- state_color = 'powering_off';
- state_str = Locale.tr("UNKNOWN");
- break;
- }
-
- return {
- color: state_color,
- str: state_str
- }
- }
-
- function get_provision_disk_image(data) {
- var disks = []
- if ($.isArray(data.TEMPLATE.DISK))
- disks = data.TEMPLATE.DISK
- else if (!$.isEmptyObject(data.TEMPLATE.DISK))
- disks = [data.TEMPLATE.DISK]
-
- if (disks.length > 0) {
- return ' ' + disks[0].IMAGE;
- } else {
- return ' -';
- }
- }
-
- function get_provision_ips(data) {
- return ' ' + OpenNebula.VM.ipsStr(data);
- }
-
- // @params
- // data: and IMAGE object
- // Example: data.ID
- // @returns and object containing the following properties
- // color: css class for this state.
- // color + '-color' font color class
- // color + '-bg' background class
- // str: user friendly state string
- function get_provision_image_state(data) {
- var state = OpenNebula.Image.stateStr(data.STATE);
- var state_color;
- var state_str;
-
- switch (state) {
- case "READY":
- case "USED":
- state_color = 'running';
- state_str = Locale.tr("READY");
- break;
- case "DISABLED":
- case "USED_PERS":
- state_color = 'off';
- state_str = Locale.tr("OFF");
- break;
- case "LOCKED":
- case "CLONE":
- case "INIT":
- state_color = 'deploying';
- state_str = Locale.tr("DEPLOYING") + " (1/3)";
- break;
- case "ERROR":
- state_color = 'error';
- state_str = Locale.tr("ERROR");
- break;
- case "DELETE":
- state_color = 'error';
- state_str = Locale.tr("DELETING");
- break;
- default:
- state_color = 'powering_off';
- state_str = Locale.tr("UNKNOWN");
- break;
- }
-
- return {
- color: state_color,
- str: state_str
- }
- }
-
- function setup_info_vm(context) {
- function update_provision_vm_info(vm_id, context) {
- //var tempScrollTop = $(window).scrollTop();
- $(".provision_info_vm_name", context).text("");
- $(".provision_info_vm_loading", context).show();
- $(".provision_info_vm", context).css('visibility', 'hidden');
-
- OpenNebula.VM.show({
- data : {
- id: vm_id
- },
- error: Notifier.onError,
- success: function(request, response){
- var data = response.VM
- var state = get_provision_vm_state(data);
-
- switch (state.color) {
- case "deploying":
- $(".provision_reboot_confirm_button", context).hide();
- $(".provision_poweroff_confirm_button", context).hide();
- $(".provision_poweron_button", context).hide();
- $(".provision_delete_confirm_button", context).show();
- $(".provision_shutdownhard_confirm_button", context).hide();
- $(".provision_snapshot_button", context).hide();
- $(".provision_vnc_button", context).hide();
- $(".provision_snapshot_button_disabled", context).hide();
- $(".provision_vnc_button_disabled", context).hide();
- break;
- case "running":
- $(".provision_reboot_confirm_button", context).show();
- $(".provision_poweroff_confirm_button", context).show();
- $(".provision_poweron_button", context).hide();
- $(".provision_delete_confirm_button", context).hide();
- $(".provision_shutdownhard_confirm_button", context).show();
- $(".provision_snapshot_button", context).hide();
- $(".provision_vnc_button", context).show();
- $(".provision_snapshot_button_disabled", context).show();
- $(".provision_vnc_button_disabled", context).hide();
- break;
- case "off":
- $(".provision_reboot_confirm_button", context).hide();
- $(".provision_poweroff_confirm_button", context).hide();
- $(".provision_poweron_button", context).show();
- $(".provision_delete_confirm_button", context).show();
- $(".provision_shutdownhard_confirm_button", context).hide();
- $(".provision_snapshot_button", context).show();
- $(".provision_vnc_button", context).hide();
- $(".provision_snapshot_button_disabled", context).hide();
- $(".provision_vnc_button_disabled", context).show();
- break;
- case "powering_off":
- case "error":
- $(".provision_reboot_confirm_button", context).hide();
- $(".provision_poweroff_confirm_button", context).hide();
- $(".provision_poweron_button", context).hide();
- $(".provision_delete_confirm_button", context).show();
- $(".provision_shutdownhard_confirm_button", context).hide();
- $(".provision_snapshot_button", context).hide();
- $(".provision_vnc_button", context).hide();
- $(".provision_snapshot_button_disabled", context).hide();
- $(".provision_vnc_button_disabled", context).hide();
- break;
- default:
- color = 'secondary';
- $(".provision_reboot_confirm_button", context).hide();
- $(".provision_poweroff_confirm_button", context).hide();
- $(".provision_poweron_button", context).hide();
- $(".provision_delete_confirm_button", context).show();
- $(".provision_shutdownhard_confirm_button", context).hide();
- $(".provision_snapshot_button", context).hide();
- $(".provision_vnc_button", context).hide();
- $(".provision_snapshot_button_disabled", context).hide();
- $(".provision_vnc_button_disabled", context).hide();
- break;
- }
-
- if (!OpenNebula.VM.isVNCSupported(data) && !OpenNebula.VM.isSPICESupported(data)) {
- $(".provision_vnc_button", context).hide();
- $(".provision_vnc_button_disabled", context).hide();
- }
-
- $(".provision_info_vm", context).attr("vm_id", data.ID);
- $(".provision_info_vm", context).data("vm", data);
-
- $(".provision_info_vm_name", context).text(data.NAME);
-
- $(".provision-pricing-table_vm_info", context).html(
- ''+
- ''+
- ' '+
- state.str+
- ' '+
- ' '+
- ''+
- ' '+
- ' '+
- ''+
- ''+
- ' '+
- 'x'+data.TEMPLATE.CPU+' - '+
- ((data.TEMPLATE.MEMORY > 1000) ?
- (Math.floor(data.TEMPLATE.MEMORY/1024)+'GB') :
- (data.TEMPLATE.MEMORY+'MB'))+
- ' '+
- ' '+
- ''+
- ''+
- get_provision_disk_image(data) +
- ' '+
- ' '+
- ''+
- ''+
- get_provision_ips(data) +
- ' '+
- ' '+
- //''+
- // ''+
- // "ID: " +
- // data.ID+
- // ' ' +
- //' '+
- ''+
- ' '+
- ' '+
- ''+
- ''+
- ' '+
- Humanize.prettyTimeAgo(data.STIME)+
- ' '+
- ' '+
- ''+
- ''+
- ' '+
- data.UNAME+
- ' '+
- ' '+
- ''+
- ''+
- ' '+
- data.ID+
- ' '+
- ' '+
- ''+
- ' ');
-
- $(".provision_confirm_action:first", context).html("");
-
- $(".provision_info_vm", context).css('visibility', 'visible');
- $(".provision_info_vm_loading", context).hide();
-
- //$(window).scrollTop(tempScrollTop);
-
- OpenNebula.VM.monitor({
- data : {
- timeout: true,
- id: data.ID,
- monitor: {
- monitor_resources : "CPU,MEMORY,NET_TX,NET_RX"
- }
- },
- success: function(request, response){
- var vm_graphs = [
- {
- monitor_resources : "CPU",
- labels : "Real CPU",
- humanize_figures : false,
- div_graph : $(".vm_cpu_graph", context)
- },
- {
- monitor_resources : "MEMORY",
- labels : "Real MEM",
- humanize_figures : true,
- div_graph : $(".vm_memory_graph", context)
- },
- {
- labels : "Network reception",
- monitor_resources : "NET_RX",
- humanize_figures : true,
- convert_from_bytes : true,
- div_graph : $(".vm_net_rx_graph", context)
- },
- {
- labels : "Network transmission",
- monitor_resources : "NET_TX",
- humanize_figures : true,
- convert_from_bytes : true,
- div_graph : $(".vm_net_tx_graph", context)
- },
- {
- labels : "Network reception speed",
- monitor_resources : "NET_RX",
- humanize_figures : true,
- convert_from_bytes : true,
- y_sufix : "B/s",
- derivative : true,
- div_graph : $(".vm_net_rx_speed_graph", context)
- },
- {
- labels : "Network transmission speed",
- monitor_resources : "NET_TX",
- humanize_figures : true,
- convert_from_bytes : true,
- y_sufix : "B/s",
- derivative : true,
- div_graph : $(".vm_net_tx_speed_graph", context)
- }
- ];
-
- for(var i=0; i'+
- ''+
- '
'+
- ''+
- Locale.tr("This Virtual Machine will be saved in a new Template. Only the main disk will be preserved!")+
- ' '+
- Locale.tr("You can then create a new Virtual Machine using this Template")+
- ' '+
- '
'+
- '
'+
- ' '+
- ''+
- ' '+
- ''+
- '× '+
- ' ');
- });
-
- context.on("click", ".provision_snapshot_create_button", function(){
- var button = $(this);
- button.attr("disabled", "disabled");
- var context = $(".provision_info_vm[vm_id]");
-
- var vm_id = context.attr("vm_id");
- var template_name = $('.provision_snapshot_name', context).val();
-
- OpenNebula.VM.save_as_template({
- data : {
- id: vm_id,
- extra_param: {
- name : template_name
- }
- },
- success: function(request, response){
- OpenNebula.Action.clear_cache("VMTEMPLATE");
- Notifier.notifyMessage(Locale.tr("Image") + ' ' + request.request.data[0][1].name + ' ' + Locale.tr("saved successfully"))
- update_provision_vm_info(vm_id, context);
- button.removeAttr("disabled");
- },
- error: function(request, response){
- Notifier.onError(request, response);
- button.removeAttr("disabled");
- }
- })
-
- return false;
- });
- }
-
- context.on("click", ".provision_delete_confirm_button", function(){
- $(".provision_confirm_action:first", context).html(
- '
'+
- '
'+
- '
'+
- ''+
- Locale.tr("Be careful, this action will inmediately destroy your Virtual Machine")+
- ' '+
- Locale.tr("All the information will be lost!")+
- ' '+
- '
'+
- '
'+
- '
'+
- '
× '+
- '
');
- });
-
- context.on("click", ".provision_shutdownhard_confirm_button", function(){
- $(".provision_confirm_action:first", context).html(
- '
'+
- '
'+
- '
'+
- ''+
- Locale.tr("Be careful, this action will inmediately destroy your Virtual Machine")+
- ' '+
- Locale.tr("All the information will be lost!")+
- ' '+
- '
'+
- '
'+
- '
'+
- '
× '+
- '
');
- });
-
- context.on("click", ".provision_poweroff_confirm_button", function(){
- $(".provision_confirm_action:first", context).html(
- '
'+
- '
'+
- '
'+
- ''+
- Locale.tr("This action will power off this Virtual Machine. The Virtual Machine will remain in the poweroff state, and can be powered on later")+
- ' '+
- ' '+
- Locale.tr("You can send the power off signal to the Virtual Machine (this is equivalent to execute the command from the console). If that doesn't effect your Virtual Machine, try to Power off the machine (this is equivalent to pressing the power off button in a physical computer).")+
- ' '+
- '
'+
- '
'+
- '
'+
- '
'+
- '
× '+
- '
');
- });
-
- context.on("click", ".provision_reboot_confirm_button", function(){
- $(".provision_confirm_action:first", context).html(
- '
'+
- '
'+
- '
'+
- ''+
- Locale.tr("This action will reboot this Virtual Machine.")+
- ' '+
- ' '+
- Locale.tr("You can send the reboot signal to the Virtual Machine (this is equivalent to execute the reboot command form the console). If that doesn't effect your Virtual Machine, try to Reboot the machine (this is equivalent to pressing the reset button a physical computer).")+
- ' '+
- '
'+
- '
'+
- '
'+
- '
'+
- '
× '+
- '
');
- });
-
- context.on("click", ".provision_delete_button", function(){
- var button = $(this);
- button.attr("disabled", "disabled");
- var vm_id = $(".provision_info_vm", context).attr("vm_id");
-
- OpenNebula.VM.del({
- data : {
- id: vm_id
- },
- success: function(request, response){
- $(".provision_back", context).click();
- $(".provision_vms_list_refresh_button", context).click();
- button.removeAttr("disabled");
- },
- error: function(request, response){
- Notifier.onError(request, response);
- button.removeAttr("disabled");
- }
- })
-
- return false;
- });
-
- context.on("click", ".provision_shutdownhard_button", function(){
- var button = $(this);
- button.attr("disabled", "disabled");
- var vm_id = $(".provision_info_vm", context).attr("vm_id");
-
- OpenNebula.VM.cancel({
- data : {
- id: vm_id
- },
- success: function(request, response){
- $(".provision_back", context).click();
- $(".provision_vms_list_refresh_button", context).click();
- button.removeAttr("disabled");
- },
- error: function(request, response){
- Notifier.onError(request, response);
- button.removeAttr("disabled");
- }
- })
-
- return false;
- });
-
- context.on("click", ".provision_poweroff_button", function(){
- var button = $(this);
- button.attr("disabled", "disabled");
- var vm_id = $(".provision_info_vm", context).attr("vm_id");
- var poweroff_action = $('input[name=provision_poweroff_radio]:checked').val()
-
- OpenNebula.VM[poweroff_action]({
- data : {
- id: vm_id
- },
- success: function(request, response){
- update_provision_vm_info(vm_id, context);
- button.removeAttr("disabled");
- },
- error: function(request, response){
- Notifier.onError(request, response);
- button.removeAttr("disabled");
- }
- })
-
- return false;
- });
-
- context.on("click", ".provision_reboot_button", function(){
- var button = $(this);
- button.attr("disabled", "disabled");
-
- var vm_id = $(".provision_info_vm", context).attr("vm_id");
- var reboot_action = $('input[name=provision_reboot_radio]:checked').val()
-
- OpenNebula.VM[reboot_action]({
- data : {
- id: vm_id
- },
- success: function(request, response){
- update_provision_vm_info(vm_id, context);
- button.removeAttr("disabled");
- },
- error: function(request, response){
- Notifier.onError(request, response);
- button.removeAttr("disabled");
- }
- })
-
- return false;
- });
-
- context.on("click", ".provision_poweron_button", function(){
- var button = $(this);
- button.attr("disabled", "disabled");
- var vm_id = $(".provision_info_vm", context).attr("vm_id");
-
- OpenNebula.VM.resume({
- data : {
- id: vm_id
- },
- success: function(request, response){
- update_provision_vm_info(vm_id, context);
- button.removeAttr("disabled");
- },
- error: function(request, response){
- Notifier.onError(request, response);
- button.removeAttr("disabled");
- }
- })
-
- return false;
- });
-
- context.on("click", ".provision_vnc_button", function(){
- var button = $(this);
- button.attr("disabled", "disabled");
- var vm_id = $(".provision_info_vm", context).attr("vm_id");
- var vm_data = $(".provision_info_vm", context).data("vm");
-
- OpenNebula.VM.vnc({
- data : {
- id: vm_id
- },
- success: function(request, response){
- if (OpenNebula.VM.isVNCSupported(vm_data)) {
- var proxy_host = window.location.hostname;
- var proxy_port = config['system_config']['vnc_proxy_port'];
- var pw = response["password"];
- var token = response["token"];
- var vm_name = response["vm_name"];
- var path = '?token='+token;
-
- var url = "vnc?";
- url += "host=" + proxy_host;
- url += "&port=" + proxy_port;
- url += "&token=" + token;
- url += "&password=" + pw;
- url += "&encrypt=" + config['user_config']['vnc_wss'];
- url += "&title=" + vm_name;
-
- window.open(url, '', '_blank');
- button.removeAttr("disabled");
- } else if (OpenNebula.VM.isSPICESupported(vm_data)) {
- var host, port, password, scheme = "ws://", uri, token, vm_name;
-
- if (config['user_config']['vnc_wss'] == "yes") {
- scheme = "wss://";
- }
-
- host = window.location.hostname;
- port = config['system_config']['vnc_proxy_port'];
- password = response["password"];
- token = response["token"];
- vm_name = response["vm_name"];
-
- uri = scheme + host + ":" + port + "?token=" + token;
-
- var url = "spice?";
- url += "host=" + host;
- url += "&port=" + port;
- url += "&token=" + token;
- url += "&password=" + password;
- url += "&encrypt=" + config['user_config']['vnc_wss'];
- url += "&title=" + vm_name;
-
- window.open(url, '', '_blank');
- button.removeAttr("disabled");
- } else {
- Notifier.notifyError("The remote console is not enabled for this VM")
- }
- },
- error: function(request, response){
- Notifier.onError(request, response);
- button.removeAttr("disabled");
- }
- })
-
- return false;
- });
-
- context.on("click", ".provision_refresh_info", function(){
- var vm_id = $(".provision_info_vm", context).attr("vm_id");
- update_provision_vm_info(vm_id, context);
- return false;
- });
-
- //
- // Info VM
- //
-
- $(".provision_list_vms", context).on("click", ".provision_info_vm_button", function(){
- $("a.provision_show_vm_accordion", context).trigger("click");
- // TODO loading
-
- var vm_id = $(this).parents(".provision-pricing-table").attr("opennebula_id")
- update_provision_vm_info(vm_id, context);
- return false;
- })
- }
-
- function setup_provision_vms_list(context, opts) {
- var provision_vms_datatable = $('.provision_vms_table', context).dataTable({
- "iDisplayLength": 6,
- "sDom" : '<"H">t<"F"lp>',
- "aLengthMenu": [[6, 12, 36, 72], [6, 12, 36, 72]],
- "aaSorting" : [[0, "desc"]],
- "aoColumnDefs": [
- { "bVisible": false, "aTargets": ["all"]}
- ],
- "aoColumns": [
- { "mDataProp": "VM.ID" },
- { "mDataProp": "VM.NAME" },
- { "mDataProp": "VM.UID" }
- ],
- "fnPreDrawCallback": function (oSettings) {
- // create a thumbs container if it doesn't exist. put it in the dataTables_scrollbody div
- if (this.$('tr', {"filter": "applied"} ).length == 0) {
- this.html('
'+
- ''+
- ' '+
- ' '+
- ' '+
- ' '+
- ' '+
- ''+
- Locale.tr("There are no Virtual Machines")+
- ' '+
- '
');
- } else {
- $(".provision_vms_table", context).html('
');
- }
-
- return true;
- },
- "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
- var data = aData.VM;
- var state = get_provision_vm_state(data);
-
- $(".provision_vms_ul", context).append('
'+
- ''+
- ''+
- ''+ data.NAME + ' '+
- ' '+
- ' '+
- ''+
- ''+
- ' '+
- state.str+
- ' '+
- ' '+
- //''+
- // '
'+
- //' '+
- ''+
- ' '+
- 'x'+data.TEMPLATE.CPU+' - '+
- ((data.TEMPLATE.MEMORY > 1000) ?
- (Math.floor(data.TEMPLATE.MEMORY/1024)+'GB') :
- (data.TEMPLATE.MEMORY+'MB'))+
- ' '+
- ''+
- get_provision_disk_image(data) +
- ' '+
- ''+
- get_provision_ips(data) +
- ' '+
- ''+
- ''+
- ' '+
- data.UNAME+
- ' '+
- ''+
- ' '+
- Humanize.prettyTimeAgo(data.STIME)+
- ' '+
- ' '+
- ' '+
- ' ');
-
- return nRow;
- }
- });
-
- $('.provision_list_vms_search', context).keyup(function(){
- provision_vms_datatable.fnFilter( $(this).val() );
- })
-
- $('.provision_list_vms_search', context).change(function(){
- provision_vms_datatable.fnFilter( $(this).val() );
- })
-
- context.on("click", ".provision_vms_list_refresh_button", function(){
- OpenNebula.Action.clear_cache("VM");
- update_provision_vms_datatable(provision_vms_datatable, 0);
- return false;
- });
-
- $(".provision_list_vms_filter", context).on("change", ".resource_list_select", function(){
- if ($(this).val() != "-2"){
- provision_vms_datatable.fnFilter("^" + $(this).val() + "$", 2, true, false);
- } else {
- provision_vms_datatable.fnFilter("", 2);
- }
- })
-
- ResourceSelect.insert(
- ".provision_list_vms_filter",
- context,
- "User",
- (opts.filter_expression ? opts.filter_expression : "-2"),
- false,
- '
'+Locale.tr("ALL")+' ',
- null,
- null,
- true,
- true);
-
- context.on("click", ".provision_vms_list_filter_button", function(){
- $(".provision_list_vms_filter", context).fadeIn();
- return false;
- });
-
- OpenNebula.Action.clear_cache("VM");
- update_provision_vms_datatable(provision_vms_datatable, 0);
-
- $(document).foundation();
- }
-
- function generate_provision_vms_list(context, opts) {
- context.off();
- context.html(provision_list_vms(opts));
-
- if (opts.data) {
- $(".provision_vms_table", context).data("opennebula", opts.data)
- }
-
- setup_provision_vms_list(context, opts);
- setup_info_vm(context);
- }
-
-
function setup_provision_templates_list(context, opts) {
var provision_templates_datatable = $('.provision_templates_table', context).dataTable({
"iDisplayLength": 8,
@@ -2888,7 +1599,6 @@ define(function(require) {
},
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var data = aData.VMTEMPLATE;
- //var state = get_provision_image_state(data);
var actions_html = "";
if (Config.isTabActionEnabled("provision-tab", "Template.chmod")) {
if (data.UID == config['user_id']) {
@@ -3183,1239 +1893,17 @@ define(function(require) {
setup_provision_templates_list(context, opts);
}
- function setup_info_flow(context) {
- function update_provision_flow_info(flow_id, context, role_id) {
- $(".provision_info_flow_name", context).text("");
- $(".provision_info_flow", context).css('visibility', 'hidden');
- $(".provision_info_flow_loading", context).fadeIn();
- $(".provision_role_vms_container").html("");
-
- OpenNebula.Service.show({
- data : {
- id: flow_id
- },
- error: Notifier.onError,
- success: function(request, response){
- var data = response.DOCUMENT
- var body = data.TEMPLATE.BODY;
- var state = get_provision_flow_state(body);
- var start_time = get_provision_flow_start_time(body);
-
- switch (state.color) {
- case "deploying":
- $(".provision_recover_button", context).hide();
- $(".provision_delete_confirm_button", context).show();
- $(".provision_shutdown_confirm_button", context).show();
- break;
- case "running":
- $(".provision_recover_button", context).hide();
- $(".provision_delete_confirm_button", context).show();
- $(".provision_shutdown_confirm_button", context).show();
- break;
- case "off":
- $(".provision_recover_button", context).hide();
- $(".provision_delete_confirm_button", context).show();
- $(".provision_shutdown_confirm_button", context).hide();
- break;
- case "powering_off":
- case "error":
- $(".provision_recover_button", context).show();
- $(".provision_delete_confirm_button", context).show();
- $(".provision_shutdown_confirm_button", context).show();
- break;
- default:
- $(".provision_recover_button", context).show();
- $(".provision_delete_confirm_button", context).show();
- $(".provision_shutdown_confirm_button", context).show();
- break;
- }
-
- $(".provision_info_flow", context).attr("flow_id", data.ID);
- $(".provision_info_flow_name", context).text(data.NAME);
-
- $(".provision-pricing-table_flow_info", context).html(
- '
'+
- ''+
- ' '+
- state.str+
- ' '+
- ' '+
- '
'+
- ' '+
- ' '+
- '
'+
- ''+
- ' '+
- (start_time ? Humanize.prettyTimeAgo(start_time) : "-") +
- ' '+
- ' '+
- '
'+
- ''+
- ' '+
- data.UNAME+
- ' '+
- ' '+
- '
'+
- ''+
- ' '+
- data.ID+
- ' '+
- ' '+
- '
'+
- ' '+
- '');
-
- $(".provision_roles_ul", context).html("");
- if (body.roles) {
- $.each(body.roles, function(index, role) {
- var role_state = get_provision_flow_state(role);
- var rvms = {
- str : (role.nodes ? role.nodes.length : 0) + " / " + role.cardinality ,
- percentage : Math.floor((role.nodes ? role.nodes.length : 0) / role.cardinality)*100
- }
-
- var li = $(
- '
'+
- ''+
- ''+
- ' '+
- role.name+
- ' '+
- ''+
- ''+
- ' '+
- '
'+
- ' '+
- ''+
- ''+
- role_state.str+
- ' '+
- ''+rvms.str+" VMs "+
- ' '+
- ''+
- ' '+
- ' '+
- ''+
- ''+
- ' '+
- ' '+
- ''+
- ' '+
- ' '+
- ' '+
- ' '+
- ' ').appendTo($(".provision_roles_ul", context));
-
- $(".provision_role_ul", li).data("role", role);
- if (role_id && role_id == role.name) {
- $(".provision_role_vms_button", li).trigger("click");
- }
- });
- }
-
- $(".provision_info_flow_state_hr", context).html('
');
-
- $(".provision_confirm_action:first", context).html("");
-
- $(".provision_info_flow_loading", context).hide();
- $(".provision_info_flow", context).css('visibility', 'visible');
- }
- })
- }
-
- context.on("click", ".provision_role_vms_button", function(){
- $(".provision_role_vms_container", context).html('
'+
- ''+
- ' '+
- ' '+
- ' '+
- ' '+
- ' '+
- ''+
- ' '+
- '
');
-
- var role = $(this).closest(".provision_role_ul").data('role');
- $(".provision_info_flow", context).data("role_id", role.name);
- var vms = []
-
- if (role.nodes && role.nodes.length > 0) {
- $.each(role.nodes, function(index, node){
- vms.push(node.vm_info);
- })
- }
-
- generate_provision_vms_list(
- $(".provision_role_vms_container", context),
- {
- title: role.name + ' ' + Locale.tr("VMs"),
- active: true,
- refresh: false,
- create: false,
- filter: false,
- data: vms
- });
- })
-
- context.on("click", ".provision_role_cardinality_button", function(){
- var role = $(this).closest(".provision_role_ul").data('role');
- var min_vms = (role.min_vms||1);
- var max_vms = (role.max_vms||100);
-
- $(".provision_confirm_action:first", context).html(
- '
'+
- '
'+
- '
'+
- '
'+
- '
'+
- ''+role.cardinality+' '+
- ' '+
- ''+role.name + ' ' + Locale.tr("VMs")+' '+
- '
'+
- '
'+
- '
'+
- '
'+
- ' '+
- ' '+
- ''+Locale.tr("The cardinality for this role cannot be changed")+' '+
- '
'+
- '
'+
- '
'+
- '
'+
- '
× '+
- '
');
-
-
- if (max_vms > min_vms) {
- $( ".cardinality_slider_div", context).show();
- $( ".cardinality_no_slider_div", context).hide();
-
- var provision_cardinality_slider = $( ".cardinality_slider", context).noUiSlider({
- handles: 1,
- connect: "lower",
- range: [min_vms, max_vms],
- step: 1,
- start: role.cardinality,
- value: role.cardinality,
- slide: function(type) {
- if ( type != "move"){
- if ($(this).val()) {
- $(".cardinality_value", context).html($(this).val());
- }
- }
- }
- });
-
- provision_cardinality_slider.val(role.cardinality)
-
- provision_cardinality_slider.addClass("noUiSlider");
- } else {
- $( ".cardinality_slider_div", context).hide();
- $( ".cardinality_no_slider_div", context).show();
- }
-
- return false;
- });
-
- context.on("click", ".provision_change_cardinality_button", function(){
- var flow_id = $(".provision_info_flow", context).attr("flow_id");
- var cardinality = $(".cardinality_slider", context).val()
-
- OpenNebula.Role.update({
- data : {
- id: flow_id + '/role/' + $(this).attr("role_id"),
- extra_param: {
- cardinality: cardinality
- }
- },
- success: function(request, response){
- OpenNebula.Action.clear_cache("SERVICE");
- $(".provision_refresh_info", context).trigger("click");
- },
- error: Notifier.onError
- })
- });
-
- context.on("click", ".provision_delete_confirm_button", function(){
- $(".provision_confirm_action:first", context).html(
- '
'+
- '
'+
- '
'+
- ''+
- Locale.tr("Be careful, this action will inmediately destroy your Service")+
- ' '+
- Locale.tr("All the information will be lost!")+
- ' '+
- '
'+
- '
'+
- '
'+
- '
× '+
- '
');
- });
-
- context.on("click", ".provision_shutdown_confirm_button", function(){
- $(".provision_confirm_action:first", context).html(
- '
'+
- '
'+
- '
'+
- ''+
- Locale.tr("Be careful, this action will inmediately shutdown your Service")+
- ' '+
- Locale.tr("All the information will be lost!")+
- ' '+
- '
'+
- '
'+
- '
'+
- '
× '+
- '
');
- });
-
- context.on("click", ".provision_recover_button", function(){
- var flow_id = $(".provision_info_flow", context).attr("flow_id");
-
- OpenNebula.Service.recover({
- data : {
- id: flow_id
- },
- success: function(request, response){
- update_provision_flow_info(flow_id, context);
- },
- error: Notifier.onError
- })
- });
-
- context.on("click", ".provision_shutdown_button", function(){
- var flow_id = $(".provision_info_flow", context).attr("flow_id");
-
- OpenNebula.Service.shutdown({
- data : {
- id: flow_id
- },
- success: function(request, response){
- update_provision_flow_info(flow_id, context);
- },
- error: Notifier.onError
- })
- });
-
- context.on("click", ".provision_delete_button", function(){
- var button = $(this);
- button.attr("disabled", "disabled");
- var flow_id = $(".provision_info_flow", context).attr("flow_id");
-
- OpenNebula.Service.del({
- data : {
- id: flow_id
- },
- success: function(request, response){
- $(".provision_back", context).click();
- $(".provision_flows_list_refresh_button", context).click();
- button.removeAttr("disabled");
- },
- error: function(request, response){
- Notifier.onError(request, response);
- button.removeAttr("disabled");
- }
- })
- });
-
- context.on("click", ".provision_refresh_info", function(){
- var flow_id = $(".provision_info_flow", context).attr("flow_id");
- var role_id = $(".provision_info_flow", context).data("role_id");
- update_provision_flow_info(flow_id, context, role_id);
- //$(".provision_flows_list_refresh_button", $(".provision_flows_list_section")).trigger("click");
- return false;
- });
-
- //
- // Info Flow
- //
-
- $(".provision_list_flows", context).on("click", ".provision_info_flow_button", function(){
- $("a.provision_show_flow_accordion", context).trigger("click");
-
- var flow_id = $(this).parents(".provision-pricing-table").attr("opennebula_id")
- update_provision_flow_info(flow_id, context);
- return false;
- })
- }
-
- function setup_provision_flows_list(context, opts){
- //
- // List Flows
- //
-
- provision_flows_datatable = $('.provision_flows_table', context).dataTable({
- "iDisplayLength": 6,
- "sDom" : '<"H">t<"F"lp>',
- "aLengthMenu": [[6, 12, 36, 72], [6, 12, 36, 72]],
- "aaSorting" : [[0, "desc"]],
- "aoColumnDefs": [
- { "bVisible": false, "aTargets": ["all"]}
- ],
- "aoColumns": [
- { "mDataProp": "DOCUMENT.ID" },
- { "mDataProp": "DOCUMENT.NAME" },
- { "mDataProp": "DOCUMENT.UID" }
- ],
- "fnPreDrawCallback": function (oSettings) {
- // create a thumbs container if it doesn't exist. put it in the dataTables_scrollbody div
- if (this.$('tr', {"filter": "applied"} ).length == 0) {
- this.html('
'+
- '
'+
- ' '+
- ' '+
- ' '+
- '
'+
- '
'+
- '
'+
- Locale.tr("Looks like you don't have any Service. Click the button below to get started")+
- ' '+
- '
'+
- '
'+
- '
'+
- '
'+
- '
'+
- '
');
- } else {
- $(".provision_flows_table", context).html('
');
- }
-
- return true;
- },
- "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
- var data = aData.DOCUMENT;
- var body = data.TEMPLATE.BODY;
- var state = get_provision_flow_state(body);
- var start_time = get_provision_flow_start_time(body);
-
- var roles_li = "";
- if (body.roles) {
- $.each(body.roles, function(index, role) {
- var role_state = get_provision_flow_state(role);
- var rvms = {
- str : (role.nodes ? role.nodes.length : 0) + " / " + role.cardinality ,
- percentage : Math.floor((role.nodes ? role.nodes.length : 0) / role.cardinality)*100
- }
-
- roles_li +=
- '
'+
- ' '+
- role.name+
- ' '+
- '
'+
- ''+
- ' '+
- '
'+
- ' '+
- '
'+
- //''+
- // state.str+
- //' '+
- ''+rvms.str+" VMs "+
- ' ';
- });
- }
-
- $(".provision_flows_ul", context).append('
'+
- ''+
- ''+
- ''+ data.NAME + ' '+
- ' '+
- ' '+
- ''+
- ''+
- ' '+
- state.str+
- ' '+
- ' '+
- roles_li +
- ''+
- ''+
- ' '+
- data.UNAME+
- ' '+
- ''+
- ' '+
- (start_time ? Humanize.prettyTimeAgo(start_time) : '-') +
- ' '+
- ' '+
- ' '+
- ' ');
-
- return nRow;
- }
- });
-
- $('.provision_list_flows_search', context).keyup(function(){
- provision_flows_datatable.fnFilter( $(this).val() );
- })
-
- $('.provision_list_flows_search', context).change(function(){
- provision_flows_datatable.fnFilter( $(this).val() );
- })
-
- context.on("click", ".provision_flows_list_refresh_button", function(){
- OpenNebula.Action.clear_cache("SERVICE");
- update_provision_flows_datatable(provision_flows_datatable, 0);
- return false;
- });
-
- context.on("click", ".provision_flows_list_search_button", function(){
- $(".provision_list_flows_search", context).fadeIn();
- });
-
- $(".provision_list_flows_filter", context).on("change", ".resource_list_select", function(){
- if ($(this).val() != "-2"){
- provision_flows_datatable.fnFilter("^" + $(this).val() + "$", 2, true, false);
- } else {
- provision_flows_datatable.fnFilter("", 2);
- }
- })
-
- ResourceSelect.insert(
- ".provision_list_flows_filter",
- context,
- "User",
- (opts.filter_expression ? opts.filter_expression : "-2"),
- false,
- '
'+Locale.tr("ALL")+' ',
- null,
- null,
- true,
- true);
-
- context.on("click", ".provision_flows_list_filter_button", function(){
- $(".provision_list_flows_filter", context).fadeIn();
- return false;
- });
-
- OpenNebula.Action.clear_cache("SERVICE");
- update_provision_flows_datatable(provision_flows_datatable, 0);
-
- $(document).foundation();
- }
-
- function generate_provision_flows_list(context, opts) {
- context.off();
- context.html(provision_list_flows(opts));
- setup_provision_flows_list(context, opts);
- setup_info_flow(context);
- }
-
- function setup_provision_user_info(context) {
- function update_provision_vdc_user_info(user_id, context) {
- $(".provision_info_vdc_user_name", context).text("");
- $(".provision_vdc_info_container", context).html("");
- $(".provision_info_vdc_user", context).hide();
- $(".provision_info_vdc_user_loading", context).fadeIn();
-
- OpenNebula.User.show({
- data : {
- id: user_id
- },
- error: Notifier.onError,
- success: function(request, response){
- var data = response.USER
-
- $(".provision_vdc_user_confirm_action",context).html("");
- $(".provision_info_vdc_user_acct",context).html("");
-
- $(".provision_info_vdc_user", context).attr("opennebula_id", data.ID);
- $(".provision_info_vdc_user", context).attr("uname", data.NAME);
- $(".provision_info_vdc_user", context).attr("quotas", JSON.stringify(data.VM_QUOTA));
- $(".provision_info_vdc_user_name", context).text(data.NAME);
-
- $(".provision-pricing-table_user_info", context).html("");
-
- QuotaWidgets.initEmptyQuotas(data);
-
- if (!$.isEmptyObject(data.VM_QUOTA)){
- var default_user_quotas = QuotaDefaults.default_quotas(data.DEFAULT_USER_QUOTAS);
- quotas = QuotaWidgets.quotaFloatInfo(
- data.VM_QUOTA.VM.VMS_USED,
- data.VM_QUOTA.VM.VMS,
- default_user_quotas.VM_QUOTA.VM.VMS,
- true);
-
- $(".provision-pricing-table_user_info", context).append('
'+
- Locale.tr("Running VMs")+
- ''+quotas.str+" "+
- ' '+
- '
'+
- ''+
- ' '+
- '
'+
- ' ');
-
- quotas = QuotaWidgets.quotaFloatInfo(
- data.VM_QUOTA.VM.CPU_USED,
- data.VM_QUOTA.VM.CPU,
- default_user_quotas.VM_QUOTA.VM.CPU,
- true);
-
- $(".provision-pricing-table_user_info", context).append('
'+
- Locale.tr("CPU")+
- ''+quotas.str+" "+
- ' '+
- '
'+
- ''+
- ' '+
- '
'+
- ' ');
-
- quotas = QuotaWidgets.quotaMBInfo(
- data.VM_QUOTA.VM.MEMORY_USED,
- data.VM_QUOTA.VM.MEMORY,
- default_user_quotas.VM_QUOTA.VM.MEMORY,
- true);
-
- $(".provision-pricing-table_user_info", context).append('
'+
- Locale.tr("Memory")+
- ''+quotas.str+" "+
- ' '+
- '
'+
- ''+
- ' '+
- '
'+
- ' ');
- } else {
- quotas = QuotaWidgets.quotaFloatInfo(0, 0, null, true);
-
- $(".provision-pricing-table_user_info", context).append('
'+
- Locale.tr("Running VMs")+
- ''+quotas.str+" "+
- ' '+
- '
'+
- ''+
- ' '+
- '
'+
- ' ');
-
- quotas = QuotaWidgets.quotaFloatInfo(0, 0, null, true);
-
- $(".provision-pricing-table_user_info", context).append('
'+
- Locale.tr("CPU")+
- ''+quotas.str+" "+
- ' '+
- '
'+
- ''+
- ' '+
- '
'+
- ' ');
-
- quotas = QuotaWidgets.quotaMBInfo(0, 0, null, true);
-
- $(".provision-pricing-table_user_info", context).append('
'+
- Locale.tr("Memory")+
- ''+quotas.str+" "+
- ' '+
- '
'+
- ''+
- ' '+
- '
'+
- ' ');
- }
-
- $(".provision-pricing-table_user_info", context).append(
- '
'+
- ' '+
- ' '+
- '
'+
- ''+
- ' '+
- ' '+
- ''+
- ' '+
- ' '+
- ''+
- ' '+
- ' '+
- ''+
- ' '+
- ' '+
- (Config.isFeatureEnabled("showback") ? ''+
- ' '+
- ' ' : '') +
- ' '+
- '
'+
- ' ')
-
- var start_time = Math.floor(new Date().getTime() / 1000);
- // ms to s
-
- // 604800 = 7 days = 7*24*60*60
- start_time = start_time - 604800;
-
- // today
- var end_time = -1;
-
- var options = {
- "start_time": start_time,
- "end_time": end_time,
- "userfilter": user_id
- }
-
- var no_table = true;
-
- OpenNebula.VM.accounting({
- success: function(req, response){
- Accounting.fillAccounting($(".dashboard_vm_accounting", context), req, response, no_table);
- },
- error: Notifier.onError,
- data: options
- });
-
- $(".provision_info_vdc_user", context).show();
- $(".provision_info_vdc_user_loading", context).hide();
-
- $(document).foundation();
- //$("#provision_info_vdc_quotas").html(quotas_html);
- }
- })
- }
- //
- // Info User
- //
-
- $(".provision_list_users", context).on("click", ".provision_info_user_button", function(){
- $("a.provision_show_user_accordion", context).trigger("click");
- // TODO loading
-
- var user_id = $(this).parents(".provision-pricing-table").attr("opennebula_id")
- update_provision_vdc_user_info(user_id, context);
- })
-
- context.on("click", ".provision_vdc_user_info_show_vms", function(){
- $(".provision_vdc_info_container", context).html('
'+
- ''+
- ' '+
- ' '+
- ' '+
- ' '+
- ' '+
- ''+
- ' '+
- '
');
-
- generate_provision_vms_list(
- $(".provision_vdc_info_container", context),
- {
- title: $(".provision_info_vdc_user", context).attr("uname") + ' ' + Locale.tr("VMs"),
- active: true,
- refresh: true,
- create: false,
- filter: false,
- filter_expression: $(".provision_info_vdc_user", context).attr("opennebula_id")
- });
- })
-
- context.on("click", ".provision_vdc_user_info_show_templates", function(){
- $(".provision_vdc_info_container", context).html('
'+
- ''+
- ' '+
- ' '+
- ' '+
- ' '+
- ' '+
- ''+
- ' '+
- '
');
-
- generate_provision_templates_list(
- $(".provision_vdc_info_container", context),
- {
- title: $(".provision_info_vdc_user", context).attr("uname") + ' ' + Locale.tr("Templates"),
- active: true,
- refresh: true,
- create: false,
- filter: false,
- filter_expression: $(".provision_info_vdc_user", context).attr("opennebula_id")
- });
- })
-
- context.on("click", ".provision_vdc_user_info_show_flows", function(){
- $(".provision_vdc_info_container", context).html('
'+
- ''+
- ' '+
- ' '+
- ' '+
- ' '+
- ' '+
- ''+
- ' '+
- '
');
-
- generate_provision_flows_list(
- $(".provision_vdc_info_container", context),
- {
- title: $(".provision_info_vdc_user", context).attr("uname") + ' ' + Locale.tr("Services"),
- active: true,
- refresh: true,
- create: false,
- filter: false,
- filter_expression: $(".provision_info_vdc_user", context).attr("opennebula_id")
- });
- })
-
-
- context.on("click", ".provision_vdc_user_info_show_acct", function(){
- $(".provision_vdc_info_container", context).html("");
-
- $(".provision_vdc_info_container", context).html(Accounting.html());
- Accounting.setup(
- $(".provision_vdc_info_container", context),
- { fixed_user: $(".provision_info_vdc_user", context).attr("opennebula_id"),
- init_group_by: "vm" });
-
- $(".provision_vdc_info_container", context).prepend(
- '')
- })
-
- if (Config.isFeatureEnabled("showback")) {
- context.on("click", ".provision_vdc_user_info_show_showback", function(){
- $(".provision_vdc_info_container", context).html("");
-
- $(".provision_vdc_info_container", context).html(Showback.html());
- Showback.setup(
- $(".provision_vdc_info_container", context),
- { fixed_user: $(".provision_info_vdc_user", context).attr("opennebula_id"),
- fixed_group: "" });
-
- $(".provision_vdc_info_container", context).prepend(
- '')
- })
- };
-
- context.on("click", ".provision_vdc_user_delete_confirm_button", function(){
- $(".provision_vdc_user_confirm_action", context).html(
- '
'+
- '
'+
- '
'+
- ''+
- Locale.tr("Be careful, this action will inmediately remove the User from OpenNebula")+
- ' '+
- '
'+
- '
'+
- '
'+
- '
'+
- '
× '+
- '
');
- });
-
- context.on("click", ".provision_vdc_user_password_confirm_button", function(){
- $(".provision_vdc_user_confirm_action", context).html(
- '
'+
- '
'+
- '
'+
- '
'+
- ' '+
- ' '+
- '
'+
- '
'+
- '
'+
- '
'+
- ''+Locale.tr("Update Password")+' '+
- '
'+
- '
'+
- '
× '+
- '
');
-
- context.on("click", ".provision_vdc_user_change_password_button", function(){
- var button = $(this);
- button.attr("disabled", "disabled");
- var user_id = $(".provision_info_vdc_user", context).attr("opennebula_id");
- var pw = $('.provision_vdc_user_new_password', context).val();
- var confirm_password = $('.provision_vdc_user_new_confirm_password', context).val();
-
- if (!pw.length){
- Notifier.notifyError(Locale.tr("Fill in a new password"));
- return false;
- }
-
- if (pw !== confirm_password){
- Notifier.notifyError(Locale.tr("Passwords do not match"));
- return false;
- }
-
- OpenNebula.User.passwd({
- data : {
- id: user_id,
- extra_param: pw
- },
- success: function(request, response){
- update_provision_vdc_user_info(user_id, context);
- button.removeAttr("disabled");
- },
- error: function(request, response){
- Notifier.onError(request, response);
- button.removeAttr("disabled");
- }
- })
- return false;
- });
- });
-
-
-
- context.on("click", ".provision_vdc_user_quota_confirm_button", function(){
- $(".provision_vdc_user_confirm_action", context).html(
- '
'+
- provision_quota_widget+
- '
'+
- '
'+
- '
'+
- '
× '+
- '
');
-
- setup_provision_quota_widget(context);
-
- $(document).foundation();
-
- var quotas_str = $(".provision_info_vdc_user", context).attr("quotas");
- if (quotas_str) {
- var quotas = JSON.parse(quotas_str);
-
- var vms_limit = QuotaLimits.QUOTA_LIMIT_DEFAULT;
- var cpu_limit = QuotaLimits.QUOTA_LIMIT_DEFAULT;
- var mem_limit = QuotaLimits.QUOTA_LIMIT_DEFAULT;
-
- if ( quotas.VM != undefined ){
- vms_limit = quotas.VM.VMS;
- cpu_limit = quotas.VM.CPU;
- mem_limit = quotas.VM.MEMORY;
-
- if(mem_limit != QuotaLimits.QUOTA_LIMIT_UNLIMITED &&
- mem_limit != QuotaLimits.QUOTA_LIMIT_DEFAULT){
-
- mem_limit = quotas.VM.MEMORY/1024;
- }
- }
-
- var fill_limits = function(limit, select, input){
- switch(limit){
- case QuotaLimits.QUOTA_LIMIT_DEFAULT:
- select.val('default').change();
- input.val('').change();
- break;
-
- case QuotaLimits.QUOTA_LIMIT_UNLIMITED:
- select.val('unlimited').change();
- input.val('').change();
- break;
-
- default:
- select.val('edit').change();
- input.val(limit).change();
- }
- }
-
- fill_limits(
- vms_limit,
- $("div.provision_rvms_quota select.provision_quota_select", context),
- $(".provision_rvms_quota_input", context) );
-
- fill_limits(
- cpu_limit,
- $("div.provision_cpu_quota select.provision_quota_select", context),
- $(".provision_cpu_quota_input", context) );
-
- fill_limits(
- mem_limit,
- $("div.provision_memory_quota select.provision_quota_select", context),
- $(".provision_memory_quota_tmp_input", context) );
- }
- });
-
- context.on("click", ".provision_delete_button", function(){
- var button = $(this);
- button.attr("disabled", "disabled");
- var user_id = $(".provision_info_vdc_user", context).attr("opennebula_id");
- OpenNebula.User.del({
- data : {
- id: user_id
- },
- success: function(request, response){
- $(".provision_back", context).click();
- $(".provision_users_list_refresh_button", context).click();
- button.removeAttr("disabled");
- },
- error: function(request, response){
- Notifier.onError(request, response);
- button.removeAttr("disabled");
- }
- })
- });
-
- context.on("click", ".provision_update_quota_button", function(){
- var button = $(this);
- button.attr("disabled", "disabled");
- var user_id = $(".provision_info_vdc_user", context).attr("opennebula_id");
-
- quota_json = retrieve_provision_quota_widget(context);
-
- OpenNebula.User.set_quota({
- data : {
- id: user_id,
- extra_param: quota_json
- },
- success: function(request, response){
- update_provision_vdc_user_info(user_id, context);
- button.removeAttr("disabled");
- },
- error: function(request, response){
- Notifier.onError(request, response);
- button.removeAttr("disabled");
- }
- })
- });
-
- context.on("click", ".provision_refresh_info", function(){
- var user_id = $(".provision_info_vdc_user", context).attr("opennebula_id");
- update_provision_vdc_user_info(user_id, context);
- return false;
- });
- }
-
- function setup_provision_users_list(context){
- var provision_users_datatable = $('.provision_users_table', context).dataTable({
- "iDisplayLength": 6,
- "sDom" : '<"H">t<"F"lp>',
- "aLengthMenu": [[6, 12, 36, 72], [6, 12, 36, 72]],
- "aaSorting" : [[0, "desc"]],
- "aoColumnDefs": [
- { "bVisible": false, "aTargets": ["all"]}
- ],
- "aoColumns": [
- { "mDataProp": "USER.ID" },
- { "mDataProp": "USER.NAME" }
- ],
- "fnPreDrawCallback": function (oSettings) {
- // create a thumbs container if it doesn't exist. put it in the dataTables_scrollbody div
- if (this.$('tr', {"filter": "applied"} ).length == 0) {
- this.html('
'+
- ''+
- ' '+
- ' '+
- ' '+
- ' '+
- ' '+
- ''+
- Locale.tr("The list of users is empty")+
- ' '+
- '
');
- } else {
- $(".provision_users_table", context).html('
');
- }
-
- return true;
- },
- "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
- var data = aData.USER;
- //var state = get_provision_vm_state(data);
- var vms = "";
- var memory = "";
- var cpu = "";
-
- // Inject the VM user quota. This info is returned separately in the
- // pool info call, but the userElementArray expects it inside the USER,
- // as it is returned by the individual info call
- var q = provision_quotas_list[data.ID];
-
- var quotas_html;
-
- if (q != undefined){
- var quota = q.QUOTAS;
-
- if ($.isEmptyObject(quota.VM_QUOTA)){
- var limit = (data.ID != 0 ? QuotaLimits.QUOTA_LIMIT_DEFAULT : QuotaLimits.QUOTA_LIMIT_UNLIMITED);
-
- quota.VM_QUOTA = {
- VM: {
- VMS : limit,
- VMS_USED : 0,
- CPU : limit,
- CPU_USED : 0,
- MEMORY : limit,
- MEMORY_USED : 0
- }
- }
- }
-
- if (!$.isEmptyObject(quota.VM_QUOTA)){
- var default_user_quotas = QuotaDefaults.getDefaultUserQuotas();
-
- quotas = QuotaWidgets.quotaFloatInfo(
- quota.VM_QUOTA.VM.VMS_USED,
- quota.VM_QUOTA.VM.VMS,
- default_user_quotas.VM_QUOTA.VM.VMS,
- true);
-
- quotas_html = "";
- quotas_html += '
'+
- Locale.tr("Running VMs")+
- ''+quotas.str+" "+
- ' '+
- '
'+
- ''+
- ' '+
- '
'+
- ' ';
-
- quotas = QuotaWidgets.quotaFloatInfo(
- quota.VM_QUOTA.VM.CPU_USED,
- quota.VM_QUOTA.VM.CPU,
- default_user_quotas.VM_QUOTA.VM.CPU,
- true);
-
- quotas_html += '
'+
- Locale.tr("CPU")+
- ''+quotas.str+" "+
- ' '+
- '
'+
- ''+
- ' '+
- '
'+
- ' ';
-
- quotas = QuotaWidgets.quotaMBInfo(
- quota.VM_QUOTA.VM.MEMORY_USED,
- quota.VM_QUOTA.VM.MEMORY,
- default_user_quotas.VM_QUOTA.VM.MEMORY,
- true);
-
- quotas_html += '
'+
- Locale.tr("Memory")+
- ''+quotas.str+" "+
- ' '+
- '
'+
- ''+
- ' '+
- '
'+
- ' ';
- } else {
- quotas = QuotaWidgets.quotaFloatInfo(0, 0, null, true);
-
- quotas_html = "";
- quotas_html += '
'+
- Locale.tr("Running VMs")+
- ''+quotas.str+" "+
- ' '+
- '
'+
- ''+
- ' '+
- '
'+
- ' ';
-
- quotas = QuotaWidgets.quotaFloatInfo(0, 0, null, true);
-
- quotas_html += '
'+
- Locale.tr("CPU")+
- ''+quotas.str+" "+
- ' '+
- '
'+
- ''+
- ' '+
- '
'+
- ' ';
-
- quotas = QuotaWidgets.quotaMBInfo(0, 0, null, true);
-
- quotas_html += '
'+
- Locale.tr("Memory")+
- ''+quotas.str+" "+
- ' '+
- '
'+
- ''+
- ' '+
- '
'+
- ' ';
- }
- }
-
-
- $(".provision_users_ul", context).append('
'+
- ''+
- ' ');
-
- return nRow;
- }
- });
-
-
- $('.provision_list_users_search', context).keyup(function(){
- provision_users_datatable.fnFilter( $(this).val() );
- })
-
- $('.provision_list_users_search', context).change(function(){
- provision_users_datatable.fnFilter( $(this).val() );
- })
-
- context.on("click", ".provision_users_list_refresh_button", function(){
- OpenNebula.Action.clear_cache("USER");
- update_provision_users_datatable(provision_users_datatable, 0);
- return false;
- });
-
- $(document).foundation();
- }
-
- function generate_provision_users_list(context, opts) {
- context.off();
- context.html(provision_list_users(opts));
- setup_provision_users_list(context);
- setup_provision_user_info(context);
- }
-
// Closes and resets the create user wizard
function clear_provision_create_user(){
OpenNebula.Action.clear_cache("USER");
- show_provision_user_list(0);
+ ProvisionUsersList.show(0);
var context = $("#provision_create_user");
$("#username", context).val('');
$("#password", context).val('');
$("#repeat_password", context).val('');
- reset_provision_quota_widget(context);
+ ProvisionQuotaWidget.reset(context);
$(".alert-box-error", context).hide();
$(".alert-box-error", context).html("");
@@ -4437,7 +1925,7 @@ define(function(require) {
var tab = $("#"+tab_name);
if (Config.isTabEnabled(tab_name)) {
- $('.right-header').prepend(TemplateHeader({'logo': Config.provision.logo}))
+ $('.right-header').prepend(TemplateHeader({'logo': Config.provision.logo}));
$(".left-content").remove();
$(".right-content").addClass("large-centered small-centered");
@@ -4460,15 +1948,15 @@ define(function(require) {
show_provision_dashboard();
})
- generate_provision_vms_list($(".provision_vms_list_section"), {active: true});
+ ProvisionVmsList.generate($(".provision_vms_list_section"), {active: true});
if (Config.isTabPanelEnabled("provision-tab", "templates")) {
generate_provision_templates_list($(".provision_templates_list_section"), {active: true});
}
// TODO check if active
- generate_provision_flows_list($(".provision_flows_list_section"), {active: true});
- generate_provision_users_list($(".provision_users_list_section"), {active: true});
+ ProvisionFlowsList.generate($(".provision_flows_list_section"), {active: true});
+ ProvisionUsersList.generate($(".provision_users_list_section"), {active: true});
//
// Dashboard
@@ -4476,9 +1964,14 @@ define(function(require) {
show_provision_dashboard();
+ $('.provision-header').on('click', 'li', function(){
+ $('li', '.provision-header').removeClass("active");
+ $(this).closest('li').addClass("active");
+ })
+
$(document).on("click", ".provision_vms_list_button", function(){
OpenNebula.Action.clear_cache("VM");
- show_provision_vm_list(0);
+ ProvisionVmsList.show(0);
});
$(document).on("click", ".provision_templates_list_button", function(){
@@ -4488,12 +1981,12 @@ define(function(require) {
$(document).on("click", ".provision_flows_list_button", function(){
OpenNebula.Action.clear_cache("SERVICE");
- show_provision_flow_list(0);
+ ProvisionFlowsList.show(0);
});
$(document).on("click", ".provision_users_list_button", function(){
OpenNebula.Action.clear_cache("USER");
- show_provision_user_list(0);
+ ProvisionUsersList.show(0);
});
//
@@ -5258,7 +2751,7 @@ define(function(require) {
var context = $("#provision_create_user");
- setup_provision_quota_widget(context);
+ ProvisionQuotaWidget.setup(context);
// Workaround to fix sliders. Apparently the setup fails while they are hidden
$('a[href="#provision_create_user_manual_quota"]', context).on("click", function(){
diff --git a/src/sunstone/public/app/tabs/provision-tab/header.hbs b/src/sunstone/public/app/tabs/provision-tab/header.hbs
index 3f0a926a30..bc08375551 100644
--- a/src/sunstone/public/app/tabs/provision-tab/header.hbs
+++ b/src/sunstone/public/app/tabs/provision-tab/header.hbs
@@ -1,31 +1,35 @@
-
+
+
-
-
-
-
+
-
+
+
+
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
+
-
-
diff --git a/src/sunstone/public/app/tabs/provision-tab/vms/list.hbs b/src/sunstone/public/app/tabs/provision-tab/vms/list.hbs
index 6bbe5f1ab8..74abe466e8 100644
--- a/src/sunstone/public/app/tabs/provision-tab/vms/list.hbs
+++ b/src/sunstone/public/app/tabs/provision-tab/vms/list.hbs
@@ -1,31 +1,33 @@
-
+
-
+
+
diff --git a/src/sunstone/public/app/tabs/provision-tab/vms/list.js b/src/sunstone/public/app/tabs/provision-tab/vms/list.js
new file mode 100644
index 0000000000..14aecce7e5
--- /dev/null
+++ b/src/sunstone/public/app/tabs/provision-tab/vms/list.js
@@ -0,0 +1,961 @@
+define(function(require) {
+ var OpenNebula = require('opennebula');
+ var Locale = require('utils/locale');
+ var Config = require('sunstone-config');
+ var Notifier = require('utils/notifier');
+ var Humanize = require('utils/humanize');
+ var ResourceSelect = require('utils/resource-select');
+ var Graphs = require('utils/graphs');
+
+ var TemplateVmsList = require('hbs!./list');
+
+ var _accordionId = 0;
+
+ return {
+ 'generate': generate_provision_vms_list,
+ 'show': show_provision_vm_list,
+ 'state': get_provision_vm_state
+ };
+
+ function show_provision_vm_list(timeout, context) {
+ $(".section_content").hide();
+ $(".provision_vms_list_section").fadeIn();
+
+ $("dd:not(.active) .provision_back", $(".provision_vms_list_section")).trigger("click");
+ $(".provision_vms_list_refresh_button", $(".provision_vms_list_section")).trigger("click");
+ }
+
+ function generate_provision_vms_list(context, opts) {
+ context.off();
+ context.html(html(opts));
+
+ if (opts.data) {
+ $(".provision_vms_table", context).data("opennebula", opts.data)
+ }
+
+ setup_provision_vms_list(context, opts);
+ setup_info_vm(context);
+ }
+
+ function html(opts_arg) {
+ opts = $.extend({
+ title: Locale.tr("Virtual Machines"),
+ refresh: true,
+ create: true,
+ filter: true
+ }, opts_arg)
+
+ _accordionId += 1;
+ return TemplateVmsList({'accordionId': _accordionId, 'opts': opts});
+ }
+
+ function fill_provision_vms_datatable(datatable, item_list) {
+ datatable.fnClearTable(true);
+ if (item_list.length == 0) {
+ datatable.html('
' +
+ '' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ '' +
+ Locale.tr("There are no Virtual Machines") +
+ ' ' +
+ ' ' +
+ ' ' +
+ '
');
+ } else {
+ datatable.fnAddData(item_list);
+ }
+ }
+
+ function update_provision_vms_datatable(datatable, timeout) {
+ datatable.html('
' +
+ '' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ '' +
+ ' ' +
+ '
');
+
+ var data = datatable.data('opennebula');
+ if (data) {
+ fill_provision_vms_datatable(datatable, data)
+ } else {
+ setTimeout(function() {
+ OpenNebula.VM.list({
+ timeout: true,
+ success: function (request, item_list) {
+ fill_provision_vms_datatable(datatable, item_list)
+ },
+ error: Notifier.onError
+ })
+ }, timeout);
+ }
+ }
+
+ function setup_provision_vms_list(context, opts) {
+ var provision_vms_datatable = $('.provision_vms_table', context).dataTable({
+ "iDisplayLength": 6,
+ "sDom" : '<"H">t<"F"lp>',
+ "aLengthMenu": [[6, 12, 36, 72], [6, 12, 36, 72]],
+ "aaSorting" : [[0, "desc"]],
+ "aoColumnDefs": [
+ { "bVisible": false, "aTargets": ["all"]}
+ ],
+ "aoColumns": [
+ { "mDataProp": "VM.ID" },
+ { "mDataProp": "VM.NAME" },
+ { "mDataProp": "VM.UID" }
+ ],
+ "fnPreDrawCallback": function (oSettings) {
+ // create a thumbs container if it doesn't exist. put it in the dataTables_scrollbody div
+ if (this.$('tr', {"filter": "applied"} ).length == 0) {
+ this.html('
'+
+ ''+
+ ' '+
+ ' '+
+ ' '+
+ ' '+
+ ' '+
+ ''+
+ Locale.tr("There are no Virtual Machines")+
+ ' '+
+ '
');
+ } else {
+ $(".provision_vms_table", context).html('
');
+ }
+
+ return true;
+ },
+ "fnDrawCallback": function (oSettings) {
+ $(".provision_vms_ul", context).foundation('reflow', 'tooltip');
+
+ return true;
+ },
+ "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
+ var data = aData.VM;
+ var state = get_provision_vm_state(data);
+
+ $(".provision_vms_ul", context).append('
'+
+ ''+
+ ''+
+ ''+
+ ''+
+ ' '+
+ ' '+
+ data.NAME + ' '+
+ ' '+
+ ''+
+ ' '+
+ 'x'+data.TEMPLATE.CPU+' - '+
+ ((data.TEMPLATE.MEMORY > 1000) ?
+ (Math.floor(data.TEMPLATE.MEMORY/1024)+'GB') :
+ (data.TEMPLATE.MEMORY+'MB'))+
+ ' - '+
+ get_provision_disk_image(data) +
+ ' '+
+ ''+
+ ''+
+ get_provision_ips(data) +
+ ' '+
+ ' '+
+ ''+
+ ''+
+ ' '+
+ data.UNAME+
+ ' '+
+ ''+
+ Humanize.prettyTimeAgo(data.STIME)+
+ ' '+
+ ' '+
+ ' '+
+ ' ');
+
+ return nRow;
+ }
+ });
+
+ $('.provision_list_vms_search', context).keyup(function(){
+ provision_vms_datatable.fnFilter( $(this).val() );
+ })
+
+ $('.provision_list_vms_search', context).change(function(){
+ provision_vms_datatable.fnFilter( $(this).val() );
+ })
+
+ context.on("click", ".provision_vms_list_refresh_button", function(){
+ OpenNebula.Action.clear_cache("VM");
+ update_provision_vms_datatable(provision_vms_datatable, 0);
+ return false;
+ });
+
+ $(".provision_list_vms_filter", context).on("change", ".resource_list_select", function(){
+ if ($(this).val() != "-2"){
+ provision_vms_datatable.fnFilter("^" + $(this).val() + "$", 2, true, false);
+ } else {
+ provision_vms_datatable.fnFilter("", 2);
+ }
+ })
+
+ ResourceSelect.insert(
+ ".provision_list_vms_filter",
+ context,
+ "User",
+ (opts.filter_expression ? opts.filter_expression : "-2"),
+ false,
+ '
'+Locale.tr("ALL")+' ',
+ null,
+ null,
+ true,
+ true);
+
+ context.on("click", ".provision_vms_list_filter_button", function(){
+ $(".provision_list_vms_filter", context).fadeIn();
+ return false;
+ });
+
+ OpenNebula.Action.clear_cache("VM");
+ update_provision_vms_datatable(provision_vms_datatable, 0);
+
+ $(document).foundation();
+ }
+
+ function setup_info_vm(context) {
+ function update_provision_vm_info(vm_id, context) {
+ //var tempScrollTop = $(window).scrollTop();
+ $(".provision_info_vm_name", context).text("");
+ $(".provision_info_vm_loading", context).show();
+ $(".provision_info_vm", context).css('visibility', 'hidden');
+
+ OpenNebula.VM.show({
+ data : {
+ id: vm_id
+ },
+ error: Notifier.onError,
+ success: function(request, response){
+ var data = response.VM
+ var state = get_provision_vm_state(data);
+
+ switch (state.color) {
+ case "deploying":
+ $(".provision_reboot_confirm_button", context).hide();
+ $(".provision_poweroff_confirm_button", context).hide();
+ $(".provision_poweron_button", context).hide();
+ $(".provision_delete_confirm_button", context).show();
+ $(".provision_shutdownhard_confirm_button", context).hide();
+ $(".provision_snapshot_button", context).hide();
+ $(".provision_vnc_button", context).hide();
+ $(".provision_snapshot_button_disabled", context).hide();
+ $(".provision_vnc_button_disabled", context).hide();
+ break;
+ case "running":
+ $(".provision_reboot_confirm_button", context).show();
+ $(".provision_poweroff_confirm_button", context).show();
+ $(".provision_poweron_button", context).hide();
+ $(".provision_delete_confirm_button", context).hide();
+ $(".provision_shutdownhard_confirm_button", context).show();
+ $(".provision_snapshot_button", context).hide();
+ $(".provision_vnc_button", context).show();
+ $(".provision_snapshot_button_disabled", context).show();
+ $(".provision_vnc_button_disabled", context).hide();
+ break;
+ case "off":
+ $(".provision_reboot_confirm_button", context).hide();
+ $(".provision_poweroff_confirm_button", context).hide();
+ $(".provision_poweron_button", context).show();
+ $(".provision_delete_confirm_button", context).show();
+ $(".provision_shutdownhard_confirm_button", context).hide();
+ $(".provision_snapshot_button", context).show();
+ $(".provision_vnc_button", context).hide();
+ $(".provision_snapshot_button_disabled", context).hide();
+ $(".provision_vnc_button_disabled", context).show();
+ break;
+ case "powering_off":
+ case "error":
+ $(".provision_reboot_confirm_button", context).hide();
+ $(".provision_poweroff_confirm_button", context).hide();
+ $(".provision_poweron_button", context).hide();
+ $(".provision_delete_confirm_button", context).show();
+ $(".provision_shutdownhard_confirm_button", context).hide();
+ $(".provision_snapshot_button", context).hide();
+ $(".provision_vnc_button", context).hide();
+ $(".provision_snapshot_button_disabled", context).hide();
+ $(".provision_vnc_button_disabled", context).hide();
+ break;
+ default:
+ color = 'secondary';
+ $(".provision_reboot_confirm_button", context).hide();
+ $(".provision_poweroff_confirm_button", context).hide();
+ $(".provision_poweron_button", context).hide();
+ $(".provision_delete_confirm_button", context).show();
+ $(".provision_shutdownhard_confirm_button", context).hide();
+ $(".provision_snapshot_button", context).hide();
+ $(".provision_vnc_button", context).hide();
+ $(".provision_snapshot_button_disabled", context).hide();
+ $(".provision_vnc_button_disabled", context).hide();
+ break;
+ }
+
+ if (!OpenNebula.VM.isVNCSupported(data) && !OpenNebula.VM.isSPICESupported(data)) {
+ $(".provision_vnc_button", context).hide();
+ $(".provision_vnc_button_disabled", context).hide();
+ }
+
+ $(".provision_info_vm", context).attr("vm_id", data.ID);
+ $(".provision_info_vm", context).data("vm", data);
+
+ $(".provision_info_vm_name", context).text(data.NAME);
+
+ $(".provision-pricing-table_vm_info", context).html(
+ '
'+
+ ''+
+ ' '+
+ state.str+
+ ' '+
+ ' '+
+ '
'+
+ ' '+
+ ' '+
+ '
'+
+ ''+
+ ' '+
+ 'x'+data.TEMPLATE.CPU+' - '+
+ ((data.TEMPLATE.MEMORY > 1000) ?
+ (Math.floor(data.TEMPLATE.MEMORY/1024)+'GB') :
+ (data.TEMPLATE.MEMORY+'MB'))+
+ ' '+
+ ' - '+
+ ''+
+ get_provision_disk_image(data) +
+ ' '+
+ ' '+
+ '
'+
+ ''+
+ get_provision_ips(data) +
+ ' '+
+ ' '+
+ //'
'+
+ // ''+
+ // "ID: " +
+ // data.ID+
+ // ' ' +
+ //' '+
+ '
'+
+ ' '+
+ ' '+
+ '
'+
+ ''+
+ ' '+
+ data.UNAME+
+ ' '+
+ ''+
+ ' '+
+ Humanize.prettyTimeAgo(data.STIME)+
+ ' - '+
+ 'ID: '+
+ data.ID+
+ ' '+
+ ' ');
+
+ $(".provision_confirm_action:first", context).html("");
+
+ $(".provision_info_vm", context).css('visibility', 'visible');
+ $(".provision_info_vm_loading", context).hide();
+
+ //$(window).scrollTop(tempScrollTop);
+
+ OpenNebula.VM.monitor({
+ data : {
+ timeout: true,
+ id: data.ID,
+ monitor: {
+ monitor_resources : "CPU,MEMORY,NET_TX,NET_RX"
+ }
+ },
+ success: function(request, response){
+ var vm_graphs = [
+ {
+ monitor_resources : "CPU",
+ labels : "Real CPU",
+ humanize_figures : false,
+ div_graph : $(".vm_cpu_graph", context)
+ },
+ {
+ monitor_resources : "MEMORY",
+ labels : "Real MEM",
+ humanize_figures : true,
+ div_graph : $(".vm_memory_graph", context)
+ },
+ {
+ labels : "Network reception",
+ monitor_resources : "NET_RX",
+ humanize_figures : true,
+ convert_from_bytes : true,
+ div_graph : $(".vm_net_rx_graph", context)
+ },
+ {
+ labels : "Network transmission",
+ monitor_resources : "NET_TX",
+ humanize_figures : true,
+ convert_from_bytes : true,
+ div_graph : $(".vm_net_tx_graph", context)
+ },
+ {
+ labels : "Network reception speed",
+ monitor_resources : "NET_RX",
+ humanize_figures : true,
+ convert_from_bytes : true,
+ y_sufix : "B/s",
+ derivative : true,
+ div_graph : $(".vm_net_rx_speed_graph", context)
+ },
+ {
+ labels : "Network transmission speed",
+ monitor_resources : "NET_TX",
+ humanize_figures : true,
+ convert_from_bytes : true,
+ y_sufix : "B/s",
+ derivative : true,
+ div_graph : $(".vm_net_tx_speed_graph", context)
+ }
+ ];
+
+ for(var i=0; i
'+
+ ''+
+ '
'+
+ ''+
+ Locale.tr("This Virtual Machine will be saved in a new Template. Only the main disk will be preserved!")+
+ ' '+
+ Locale.tr("You can then create a new Virtual Machine using this Template")+
+ ' '+
+ '
'+
+ '
'+
+ ' '+
+ ''+
+ ' '+
+ ''+
+ '× '+
+ ' ');
+ });
+
+ context.on("click", ".provision_snapshot_create_button", function(){
+ var button = $(this);
+ button.attr("disabled", "disabled");
+ var context = $(".provision_info_vm[vm_id]");
+
+ var vm_id = context.attr("vm_id");
+ var template_name = $('.provision_snapshot_name', context).val();
+
+ OpenNebula.VM.save_as_template({
+ data : {
+ id: vm_id,
+ extra_param: {
+ name : template_name
+ }
+ },
+ success: function(request, response){
+ OpenNebula.Action.clear_cache("VMTEMPLATE");
+ Notifier.notifyMessage(Locale.tr("Image") + ' ' + request.request.data[0][1].name + ' ' + Locale.tr("saved successfully"))
+ update_provision_vm_info(vm_id, context);
+ button.removeAttr("disabled");
+ },
+ error: function(request, response){
+ Notifier.onError(request, response);
+ button.removeAttr("disabled");
+ }
+ })
+
+ return false;
+ });
+ }
+
+ context.on("click", ".provision_delete_confirm_button", function(){
+ $(".provision_confirm_action:first", context).html(
+ '
'+
+ '
'+
+ '
'+
+ ''+
+ Locale.tr("Be careful, this action will inmediately destroy your Virtual Machine")+
+ ' '+
+ Locale.tr("All the information will be lost!")+
+ ' '+
+ '
'+
+ '
'+
+ '
'+
+ '
× '+
+ '
');
+ });
+
+ context.on("click", ".provision_shutdownhard_confirm_button", function(){
+ $(".provision_confirm_action:first", context).html(
+ '
'+
+ '
'+
+ '
'+
+ ''+
+ Locale.tr("Be careful, this action will inmediately destroy your Virtual Machine")+
+ ' '+
+ Locale.tr("All the information will be lost!")+
+ ' '+
+ '
'+
+ '
'+
+ '
'+
+ '
× '+
+ '
');
+ });
+
+ context.on("click", ".provision_poweroff_confirm_button", function(){
+ $(".provision_confirm_action:first", context).html(
+ '
'+
+ '
'+
+ '
'+
+ ''+
+ Locale.tr("This action will power off this Virtual Machine. The Virtual Machine will remain in the poweroff state, and can be powered on later")+
+ ' '+
+ ' '+
+ Locale.tr("You can send the power off signal to the Virtual Machine (this is equivalent to execute the command from the console). If that doesn't effect your Virtual Machine, try to Power off the machine (this is equivalent to pressing the power off button in a physical computer).")+
+ ' '+
+ '
'+
+ '
'+
+ '
'+
+ '
'+
+ '
× '+
+ '
');
+ });
+
+ context.on("click", ".provision_reboot_confirm_button", function(){
+ $(".provision_confirm_action:first", context).html(
+ '
'+
+ '
'+
+ '
'+
+ ''+
+ Locale.tr("This action will reboot this Virtual Machine.")+
+ ' '+
+ ' '+
+ Locale.tr("You can send the reboot signal to the Virtual Machine (this is equivalent to execute the reboot command form the console). If that doesn't effect your Virtual Machine, try to Reboot the machine (this is equivalent to pressing the reset button a physical computer).")+
+ ' '+
+ '
'+
+ '
'+
+ '
'+
+ '
'+
+ '
× '+
+ '
');
+ });
+
+ context.on("click", ".provision_delete_button", function(){
+ var button = $(this);
+ button.attr("disabled", "disabled");
+ var vm_id = $(".provision_info_vm", context).attr("vm_id");
+
+ OpenNebula.VM.del({
+ data : {
+ id: vm_id
+ },
+ success: function(request, response){
+ $(".provision_back", context).click();
+ $(".provision_vms_list_refresh_button", context).click();
+ button.removeAttr("disabled");
+ },
+ error: function(request, response){
+ Notifier.onError(request, response);
+ button.removeAttr("disabled");
+ }
+ })
+
+ return false;
+ });
+
+ context.on("click", ".provision_shutdownhard_button", function(){
+ var button = $(this);
+ button.attr("disabled", "disabled");
+ var vm_id = $(".provision_info_vm", context).attr("vm_id");
+
+ OpenNebula.VM.cancel({
+ data : {
+ id: vm_id
+ },
+ success: function(request, response){
+ $(".provision_back", context).click();
+ $(".provision_vms_list_refresh_button", context).click();
+ button.removeAttr("disabled");
+ },
+ error: function(request, response){
+ Notifier.onError(request, response);
+ button.removeAttr("disabled");
+ }
+ })
+
+ return false;
+ });
+
+ context.on("click", ".provision_poweroff_button", function(){
+ var button = $(this);
+ button.attr("disabled", "disabled");
+ var vm_id = $(".provision_info_vm", context).attr("vm_id");
+ var poweroff_action = $('input[name=provision_poweroff_radio]:checked').val()
+
+ OpenNebula.VM[poweroff_action]({
+ data : {
+ id: vm_id
+ },
+ success: function(request, response){
+ update_provision_vm_info(vm_id, context);
+ button.removeAttr("disabled");
+ },
+ error: function(request, response){
+ Notifier.onError(request, response);
+ button.removeAttr("disabled");
+ }
+ })
+
+ return false;
+ });
+
+ context.on("click", ".provision_reboot_button", function(){
+ var button = $(this);
+ button.attr("disabled", "disabled");
+
+ var vm_id = $(".provision_info_vm", context).attr("vm_id");
+ var reboot_action = $('input[name=provision_reboot_radio]:checked').val()
+
+ OpenNebula.VM[reboot_action]({
+ data : {
+ id: vm_id
+ },
+ success: function(request, response){
+ update_provision_vm_info(vm_id, context);
+ button.removeAttr("disabled");
+ },
+ error: function(request, response){
+ Notifier.onError(request, response);
+ button.removeAttr("disabled");
+ }
+ })
+
+ return false;
+ });
+
+ context.on("click", ".provision_poweron_button", function(){
+ var button = $(this);
+ button.attr("disabled", "disabled");
+ var vm_id = $(".provision_info_vm", context).attr("vm_id");
+
+ OpenNebula.VM.resume({
+ data : {
+ id: vm_id
+ },
+ success: function(request, response){
+ update_provision_vm_info(vm_id, context);
+ button.removeAttr("disabled");
+ },
+ error: function(request, response){
+ Notifier.onError(request, response);
+ button.removeAttr("disabled");
+ }
+ })
+
+ return false;
+ });
+
+ context.on("click", ".provision_vnc_button", function(){
+ var button = $(this);
+ button.attr("disabled", "disabled");
+ var vm_id = $(".provision_info_vm", context).attr("vm_id");
+ var vm_data = $(".provision_info_vm", context).data("vm");
+
+ OpenNebula.VM.vnc({
+ data : {
+ id: vm_id
+ },
+ success: function(request, response){
+ if (OpenNebula.VM.isVNCSupported(vm_data)) {
+ var proxy_host = window.location.hostname;
+ var proxy_port = config['system_config']['vnc_proxy_port'];
+ var pw = response["password"];
+ var token = response["token"];
+ var vm_name = response["vm_name"];
+ var path = '?token='+token;
+
+ var url = "vnc?";
+ url += "host=" + proxy_host;
+ url += "&port=" + proxy_port;
+ url += "&token=" + token;
+ url += "&password=" + pw;
+ url += "&encrypt=" + config['user_config']['vnc_wss'];
+ url += "&title=" + vm_name;
+
+ window.open(url, '', '_blank');
+ button.removeAttr("disabled");
+ } else if (OpenNebula.VM.isSPICESupported(vm_data)) {
+ var host, port, password, scheme = "ws://", uri, token, vm_name;
+
+ if (config['user_config']['vnc_wss'] == "yes") {
+ scheme = "wss://";
+ }
+
+ host = window.location.hostname;
+ port = config['system_config']['vnc_proxy_port'];
+ password = response["password"];
+ token = response["token"];
+ vm_name = response["vm_name"];
+
+ uri = scheme + host + ":" + port + "?token=" + token;
+
+ var url = "spice?";
+ url += "host=" + host;
+ url += "&port=" + port;
+ url += "&token=" + token;
+ url += "&password=" + password;
+ url += "&encrypt=" + config['user_config']['vnc_wss'];
+ url += "&title=" + vm_name;
+
+ window.open(url, '', '_blank');
+ button.removeAttr("disabled");
+ } else {
+ Notifier.notifyError("The remote console is not enabled for this VM")
+ }
+ },
+ error: function(request, response){
+ Notifier.onError(request, response);
+ button.removeAttr("disabled");
+ }
+ })
+
+ return false;
+ });
+
+ context.on("click", ".provision_refresh_info", function(){
+ var vm_id = $(".provision_info_vm", context).attr("vm_id");
+ update_provision_vm_info(vm_id, context);
+ return false;
+ });
+
+ //
+ // Info VM
+ //
+
+ $(".provision_list_vms", context).on("click", ".provision_info_vm_button", function(){
+ $("a.provision_show_vm_accordion", context).trigger("click");
+ // TODO loading
+
+ var vm_id = $(this).parents(".provision-pricing-table").attr("opennebula_id")
+ update_provision_vm_info(vm_id, context);
+ return false;
+ })
+ }
+
+
+ // @params
+ // data: and VM object
+ // Example: data.ID
+ // @returns and object containing the following properties
+ // color: css class for this state.
+ // color + '-color' font color class
+ // color + '-bg' background class
+ // str: user friendly state string
+ function get_provision_vm_state(data) {
+ var state = OpenNebula.VM.stateStr(data.STATE);
+ var state_color;
+ var state_str;
+
+ switch (state) {
+ case "INIT":
+ case "PENDING":
+ case "HOLD":
+ state_color = 'deploying';
+ state_str = Locale.tr("DEPLOYING") + " (1/3)";
+ break;
+ case "FAILED":
+ state_color = 'error';
+ state_str = Locale.tr("ERROR");
+ break;
+ case "ACTIVE":
+ var lcm_state = OpenNebula.VM.shortLcmStateStr(data.LCM_STATE);
+
+ switch (lcm_state) {
+ case "LCM_INIT":
+ state_color = 'deploying';
+ state_str = Locale.tr("DEPLOYING") + " (1/3)";
+ break;
+ case "PROLOG":
+ state_color = 'deploying';
+ state_str = Locale.tr("DEPLOYING") + " (2/3)";
+ break;
+ case "BOOT":
+ state_color = 'deploying';
+ state_str = Locale.tr("DEPLOYING") + " (3/3)";
+ break;
+ case "RUNNING":
+ case "SNAPSHOT":
+ case "MIGRATE":
+ state_color = 'running';
+ state_str = Locale.tr("RUNNING");
+ break;
+ case "HOTPLUG":
+ state_color = 'deploying';
+ state_str = Locale.tr("SAVING IMAGE");
+ break;
+ case "FAILURE":
+ state_color = 'error';
+ state_str = Locale.tr("ERROR");
+ break;
+ case "SAVE":
+ case "EPILOG":
+ case "SHUTDOWN":
+ case "CLEANUP":
+ state_color = 'powering_off';
+ state_str = Locale.tr("POWERING OFF");
+ break;
+ case "UNKNOWN":
+ state_color = 'powering_off';
+ state_str = Locale.tr("UNKNOWN");
+ break;
+ default:
+ state_color = 'powering_off';
+ state_str = Locale.tr("UNKNOWN");
+ break;
+ }
+
+ break;
+ case "STOPPED":
+ case "SUSPENDED":
+ case "POWEROFF":
+ state_color = 'off';
+ state_str = Locale.tr("OFF");
+
+ break;
+ default:
+ state_color = 'powering_off';
+ state_str = Locale.tr("UNKNOWN");
+ break;
+ }
+
+ return {
+ color: state_color,
+ str: state_str
+ }
+ }
+
+ function get_provision_disk_image(data) {
+ var disks = []
+ if ($.isArray(data.TEMPLATE.DISK))
+ disks = data.TEMPLATE.DISK
+ else if (!$.isEmptyObject(data.TEMPLATE.DISK))
+ disks = [data.TEMPLATE.DISK]
+
+ if (disks.length > 0) {
+ return disks[0].IMAGE;
+ } else {
+ return '';
+ }
+ }
+
+ function get_provision_ips(data) {
+ return '
' + OpenNebula.VM.ipsStr(data);
+ }
+
+ // @params
+ // data: and IMAGE object
+ // Example: data.ID
+ // @returns and object containing the following properties
+ // color: css class for this state.
+ // color + '-color' font color class
+ // color + '-bg' background class
+ // str: user friendly state string
+ function get_provision_image_state(data) {
+ var state = OpenNebula.Image.stateStr(data.STATE);
+ var state_color;
+ var state_str;
+
+ switch (state) {
+ case "READY":
+ case "USED":
+ state_color = 'running';
+ state_str = Locale.tr("READY");
+ break;
+ case "DISABLED":
+ case "USED_PERS":
+ state_color = 'off';
+ state_str = Locale.tr("OFF");
+ break;
+ case "LOCKED":
+ case "CLONE":
+ case "INIT":
+ state_color = 'deploying';
+ state_str = Locale.tr("DEPLOYING") + " (1/3)";
+ break;
+ case "ERROR":
+ state_color = 'error';
+ state_str = Locale.tr("ERROR");
+ break;
+ case "DELETE":
+ state_color = 'error';
+ state_str = Locale.tr("DELETING");
+ break;
+ default:
+ state_color = 'powering_off';
+ state_str = Locale.tr("UNKNOWN");
+ break;
+ }
+
+ return {
+ color: state_color,
+ str: state_str
+ }
+ }
+});
diff --git a/src/sunstone/public/app/utils/graphs.js b/src/sunstone/public/app/utils/graphs.js
index a9eb8f3df8..06035e3728 100644
--- a/src/sunstone/public/app/utils/graphs.js
+++ b/src/sunstone/public/app/utils/graphs.js
@@ -65,7 +65,10 @@ define(function(require) {
return Humanize.prettyTimeAxis(val, info.show_date);
},
color: "#efefef",
- size: 8
+ font: {
+ color: "#999",
+ size: 10
+ }
},
yaxis : {
tickFormatter: function(val, axis) {
@@ -73,8 +76,10 @@ define(function(require) {
},
min: 0,
color: "#efefef",
-
- size: 8
+ font: {
+ color: "#999",
+ size: 10
+ }
},
series: {
lines: {