From 447bc1849d74065bd2751ce30f106277ac82117b Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Mon, 26 Mar 2012 12:06:00 +0200 Subject: [PATCH 01/12] Sunstone: minor bugfixes. Show host tab for regular users. --- src/sunstone/etc/sunstone-plugins.yaml | 3 +-- src/sunstone/public/js/plugins/clusters-tab.js | 2 +- .../public/js/plugins/datastores-tab.js | 8 +++++--- src/sunstone/public/js/plugins/hosts-tab.js | 18 ++++++++++++------ src/sunstone/public/js/plugins/vnets-tab.js | 2 +- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/sunstone/etc/sunstone-plugins.yaml b/src/sunstone/etc/sunstone-plugins.yaml index bc724898ba..7330791c4e 100644 --- a/src/sunstone/etc/sunstone-plugins.yaml +++ b/src/sunstone/etc/sunstone-plugins.yaml @@ -54,10 +54,9 @@ :user: :group: - plugins/hosts-tab.js: - :ALL: false + :ALL: true :user: :group: - oneadmin: true - plugins/datastores-tab.js: :ALL: true :user: diff --git a/src/sunstone/public/js/plugins/clusters-tab.js b/src/sunstone/public/js/plugins/clusters-tab.js index b0cccd6aaa..3de0de0bfe 100644 --- a/src/sunstone/public/js/plugins/clusters-tab.js +++ b/src/sunstone/public/js/plugins/clusters-tab.js @@ -453,7 +453,7 @@ function removeClusterMenus(){ // Sunstone.removeMainTab('cluster_vnets_tab_n',true); // Sunstone.removeMainTab('cluster_datastores_tab_n',true); // Sunstone.removeMainTab('cluster_hosts_tab_n',true); - Sunstone.removeMainTab('cluster_tab_n',true); + Sunstone.removeMainTab('cluster_tab_-',true); for (var i=0; i < data.length; i++){ var id = data[i][1]; diff --git a/src/sunstone/public/js/plugins/datastores-tab.js b/src/sunstone/public/js/plugins/datastores-tab.js index 854bbba145..d7470dd7d8 100644 --- a/src/sunstone/public/js/plugins/datastores-tab.js +++ b/src/sunstone/public/js/plugins/datastores-tab.js @@ -271,7 +271,8 @@ var datastore_buttons = { "Datastore.update_dialog" : { type: "action", text: tr("Update properties"), - alwaysActive: true + alwaysActive: true, + condition: mustBeAdmin, }, "Datastore.addtocluster" : { type: "confirm_with_select", @@ -296,7 +297,8 @@ var datastore_buttons = { }, "Datastore.delete" : { type: "confirm", - text: tr("Delete") + text: tr("Delete"), + condition: mustBeAdmin } } @@ -443,7 +445,7 @@ function updateDatastoreInfo(request,ds){ \ \ '+tr("Cluster")+'\ - '+(element.CLUSTER.length ? element.CLUSTER : "-")+'\ + '+(info.CLUSTER.length ? info.CLUSTER : "-")+'\ \ \ '+tr("DS Mad")+'\ diff --git a/src/sunstone/public/js/plugins/hosts-tab.js b/src/sunstone/public/js/plugins/hosts-tab.js index 0abc980a5b..147e793ef5 100644 --- a/src/sunstone/public/js/plugins/hosts-tab.js +++ b/src/sunstone/public/js/plugins/hosts-tab.js @@ -271,30 +271,36 @@ var host_buttons = { }, "Host.create_dialog" : { type: "create_dialog", - text: tr("+ New") + text: tr("+ New"), + condition: mustBeAdmin }, "Host.update_dialog" : { type: "action", text: tr("Update a template"), - alwaysActive: true + alwaysActive: true, + condition: mustBeAdmin }, "Host.addtocluster" : { type: "confirm_with_select", text: tr("Select cluster"), select: clusters_sel, tip: tr("Select the destination cluster:"), + condition: mustBeAdmin }, "Host.enable" : { type: "action", - text: tr("Enable") + text: tr("Enable"), + condition: mustBeAdmin }, "Host.disable" : { type: "action", - text: tr("Disable") + text: tr("Disable"), + condition: mustBeAdmin }, "Host.delete" : { type: "confirm", - text: tr("Delete host") + text: tr("Delete host"), + condition: mustBeAdmin } }; @@ -475,7 +481,7 @@ function updateHostInfo(request,host){ \ \ ' + tr("Cluster") + '\ - '+(host.CLUSTER.length ? host.CLUSTER : "-")+'\ + '+(host_info.CLUSTER.length ? host_info.CLUSTER : "-")+'\ \ \ ' + tr("State") + '\ diff --git a/src/sunstone/public/js/plugins/vnets-tab.js b/src/sunstone/public/js/plugins/vnets-tab.js index d65f672ebe..8f9a2d1b5d 100644 --- a/src/sunstone/public/js/plugins/vnets-tab.js +++ b/src/sunstone/public/js/plugins/vnets-tab.js @@ -566,7 +566,7 @@ function updateVNetworkInfo(request,vn){ \ \ '+tr("Cluster")+'\ - '+(network.CLUSTER.length ? network.CLUSTER : "-")+'\ + '+(vn_info.CLUSTER.length ? vn_info.CLUSTER : "-")+'\ \ \ '+tr("Owner")+'\ From fd4f8c87e07c92e81609614b0c0b7ba8b343c790 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Mon, 26 Mar 2012 12:49:25 +0200 Subject: [PATCH 02/12] Sunstone: Fixes related to clusters Adapt dashboards for cluster none. Do not show cluster info in infraestructure dashboard for non oneadmin users. --- .../public/js/plugins/clusters-tab.js | 75 +++++++++++++++++++ src/sunstone/public/js/plugins/infra-tab.js | 11 +-- 2 files changed, 81 insertions(+), 5 deletions(-) diff --git a/src/sunstone/public/js/plugins/clusters-tab.js b/src/sunstone/public/js/plugins/clusters-tab.js index 3de0de0bfe..676507df49 100644 --- a/src/sunstone/public/js/plugins/clusters-tab.js +++ b/src/sunstone/public/js/plugins/clusters-tab.js @@ -366,7 +366,82 @@ function clusterTabContent(cluster_json) { vnets_list = '
  • '+cluster.VNETS.ID+' - '+getVNetName(cluster.VNETS.ID)+'
  • '; */ + //special case for cluster none, simplified dashboard + if (cluster.ID == "-"){ + var html_code = '\ +\ +\ +\ +\ +
    \ +\ + \ + \ + \ + \ + \ + \ +
    \ +
    \ +

    ' + tr("Cluster information") + '

    \ +
    \ +\ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
    ' + tr("ID") + ''+cluster.ID+'
    ' + tr("Name") + ''+cluster.NAME+'
    \ +\ +
    \ +
    \ +
    \ +
    \ +

    ' + tr("Hosts") + '

    \ + \ +
    \ +
    \ +\ + \ + \ + \ + \ + \ + \ +
    \ +
    \ +

    ' + tr("Datastores") + '

    \ + \ +
    \ +
    \ +
    \ +

    ' + tr("Virtual Networks") + '

    \ + \ +
    \ +
    \ +
    \ +'; + return html_code; + }; + //end cluster none special html var html_code = '\ \ diff --git a/src/sunstone/public/js/plugins/infra-tab.js b/src/sunstone/public/js/plugins/infra-tab.js index 49e3782ed7..0b52418572 100644 --- a/src/sunstone/public/js/plugins/infra-tab.js +++ b/src/sunstone/public/js/plugins/infra-tab.js @@ -15,7 +15,7 @@ /* -------------------------------------------------------------------------- */ var infra_tab_content = -'
    \ +'
    \ \ \ \
    \ \ @@ -26,7 +26,7 @@ var infra_tab_content =
    \ \
    \ - \ + \ \ \ \ @@ -54,7 +54,7 @@ var infra_tab_content =

    ' + tr("Quickstart") + '

    \
    \


    \ - '+tr("Create new Cluster")+'
    \ + '+tr("Create new Cluster")+'
    \ '+tr("Create new Host")+'
    \ '+tr("Create new Datastore")+'
    \ '+tr("Create new Virtual Network")+'
    \ @@ -72,7 +72,7 @@ var infra_tab_content =

    \

    ' + tr("Infrastructure resources") + '

    \
    \ -

    '+tr("The Infrastructure menu allows management of Hosts, Datastores, Virtual Networks and the Clusters they are placed in. The Clusters node can be expanded, and resources can be managed for each cluster.")+'

    \ +

    '+tr("The Infrastructure menu allows management of Hosts, Datastores, Virtual Networks. Users in the oneadmin group can manage clusters as well.")+'

    \

    '+tr("You can find further information on the following links:")+'

    \
      \
    • Host subsystem
    • \ @@ -117,5 +117,6 @@ function updateInfraDashboard(what,json_info){ }; $(document).ready(function(){ - + if (!mustBeAdmin()) + $('table#infra_dashboard .cluster_related', main_tabs_context).hide(); }); \ No newline at end of file From 8d68721a590603e0591bb989e67a2b48e49b8f75 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Mon, 26 Mar 2012 13:10:47 +0200 Subject: [PATCH 03/12] Sunstone: Append submenus after parents menu. Allows more freedom in the loading order of plugins. Submenus will always be added after parent menu item, or after parents submenus items (so it keeps order). --- src/sunstone/etc/sunstone-plugins.yaml | 10 +++++----- src/sunstone/public/js/sunstone.js | 14 +++++++++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/sunstone/etc/sunstone-plugins.yaml b/src/sunstone/etc/sunstone-plugins.yaml index 7330791c4e..edde7af592 100644 --- a/src/sunstone/etc/sunstone-plugins.yaml +++ b/src/sunstone/etc/sunstone-plugins.yaml @@ -53,6 +53,11 @@ :ALL: true :user: :group: +- plugins/clusters-tab.js: + :ALL: false + :user: + :group: + oneadmin: true - plugins/hosts-tab.js: :ALL: true :user: @@ -65,8 +70,3 @@ :ALL: true :user: :group: -- plugins/clusters-tab.js: - :ALL: false - :user: - :group: - oneadmin: true diff --git a/src/sunstone/public/js/sunstone.js b/src/sunstone/public/js/sunstone.js index df9659a96c..20e82c3909 100644 --- a/src/sunstone/public/js/sunstone.js +++ b/src/sunstone/public/js/sunstone.js @@ -465,7 +465,19 @@ function insertTab(tab_name){ $('div#'+tab_name,main_tabs_context).html(tab_info.content); - $('div#menu ul#navigation').append('
    • '+tab_info.title+'
    • '); + var li_item = '
    • '+tab_info.title+'
    • '; + + //if this is a submenu... + if (parent.length) { + var children = $('div#menu ul#navigation li.'+parent); + //if there are other submenus, insert after last of them + if (children.length) + $(children[children.length-1]).after(li_item); + else //instert after parent menu + $('div#menu ul#navigation li#li_'+parent).after(li_item); + } else { //not a submenu, instert in the end + $('div#menu ul#navigation').append(li_item); + }; if (parent){ //this is a subtab $('div#menu li#li_'+tab_name).hide();//hide by default From 04e907bc784540d8b2587474e26443cdf11dca9f Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Tue, 27 Mar 2012 13:34:32 +0200 Subject: [PATCH 04/12] Feature #1181: Add ip column to vms view. --- src/sunstone/public/js/plugins/vms-tab.js | 28 ++++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index ff5815c3fe..c8210bea4b 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -63,6 +63,7 @@ var vms_tab_content =
    \ \ \ + \ \ \ \ @@ -619,7 +620,21 @@ function vmShow(req) { // Returns a human readable running time for a VM function str_start_time(vm){ return pretty_time(vm.STIME); -} +}; + +function ip_str(vm){ + var nic = vm.TEMPLATE.NIC; + var ip = '--'; + if ($.isArray(nic)) { + ip = ''; + $.each(nic, function(index,value){ + ip += value.IP+'
    '; + }); + } else if (nic && nic.IP) { + ip = nic.IP; + }; + return ip; +}; // Returns an array formed by the information contained in the vm_json // and ready to be introduced in a dataTable @@ -650,10 +665,11 @@ function vMachineElementArray(vm_json){ vm.CPU, humanize_size(vm.MEMORY), hostname, + ip_str(vm), str_start_time(vm), vncIcon(vm) ]; -} +}; //Creates a listener for the TDs of the VM table @@ -1284,9 +1300,9 @@ $(document).ready(function(){ "aoColumnDefs": [ { "bSortable": false, "aTargets": ["check"] }, { "sWidth": "60px", "aTargets": [0,6,7] }, - { "sWidth": "35px", "aTargets": [1,10] }, - { "sWidth": "150px", "aTargets": [5,9] }, - { "sWidth": "100px", "aTargets": [2,3] } + { "sWidth": "35px", "aTargets": [1,11] }, + { "sWidth": "150px", "aTargets": [5,10] }, + { "sWidth": "100px", "aTargets": [2,3,9] } ], "oLanguage": (datatable_lang != "") ? { @@ -1297,7 +1313,7 @@ $(document).ready(function(){ dataTable_vMachines.fnClearTable(); addElement([ spinner, - '','','','','','','','','',''],dataTable_vMachines); + '','','','','','','','','','',''],dataTable_vMachines); Sunstone.runAction("VM.list"); setupCreateVMDialog(); From aa0469acf677d5baf8d1b0f8af295897edcdc03d Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Tue, 27 Mar 2012 15:46:36 +0200 Subject: [PATCH 05/12] Feature #1179: Add vm history to vm tab --- src/sunstone/public/js/opennebula.js | 23 ++++-- src/sunstone/public/js/plugins/vms-tab.js | 90 ++++++++++++++++++++--- src/sunstone/public/js/sunstone-util.js | 14 ++++ 3 files changed, 113 insertions(+), 14 deletions(-) diff --git a/src/sunstone/public/js/opennebula.js b/src/sunstone/public/js/opennebula.js index eb4f149d30..8507ab0b08 100644 --- a/src/sunstone/public/js/opennebula.js +++ b/src/sunstone/public/js/opennebula.js @@ -46,21 +46,24 @@ var OpenNebula = { { switch(type) { - case "HOST","host": + case "HOST": + case "host": return ["INIT", "MONITORING", "MONITORED", "ERROR", "DISABLED"][value]; break; - case "HOST_SIMPLE","host_simple": + case "HOST_SIMPLE": + case "host_simple": return ["ON", "ON", "ON", "ERROR", "OFF"][value]; break; - case "VM","vm": + case "VM": + case "vm": return ["INIT", "PENDING", "HOLD", @@ -70,7 +73,8 @@ var OpenNebula = { "DONE", "FAILED"][value]; break; - case "VM_LCM","vm_lcm": + case "VM_LCM": + case "vm_lcm": return ["LCM_INIT", "PROLOG", "BOOT", @@ -89,7 +93,8 @@ var OpenNebula = { "CLEANUP", "UNKNOWN"][value]; break; - case "IMAGE","image": + case "IMAGE": + case "image": return ["INIT", "READY", "USED", @@ -97,6 +102,14 @@ var OpenNebula = { "LOCKED", "ERROR"][value]; break; + case "VM_MIGRATE_REASON": + case "vm_migrate_reason": + return ["NONE", + "ERROR", + "STOP_RESUME", + "USER", + "CANCEL"][value]; + break; default: return; } diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index c8210bea4b..455d2a39d5 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -593,6 +593,10 @@ var vm_info_panel = { "vm_log_tab" : { title: tr("VM log"), content: "" + }, + "vm_history_tab" : { + title: tr("History information"), + content: "", } } @@ -627,11 +631,11 @@ function ip_str(vm){ var ip = '--'; if ($.isArray(nic)) { ip = ''; - $.each(nic, function(index,value){ - ip += value.IP+'
    '; - }); + $.each(nic, function(index,value){ + ip += value.IP+'
    '; + }); } else if (nic && nic.IP) { - ip = nic.IP; + ip = nic.IP; }; return ip; }; @@ -719,7 +723,69 @@ function updateVMachinesView(request, vmachine_list){ updateView(vmachine_list_array,dataTable_vMachines); updateDashboard("vms",vmachine_list); updateVResDashboard("vms",vmachine_list); -} +}; + +function generateHistoryTable(vm){ + var html = '
    '+tr("CPU")+''+tr("Memory")+''+tr("Hostname")+''+tr("IPs")+''+tr("Start Time")+''+tr("VNC Access")+'
    \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + '; + + var history = []; + + if ($.isArray(vm.HISTORY_RECORDS.HISTORY)) + history = vm.HISTORY_RECORDS.HISTORY; + else if (vm.HISTORY_RECORDS.HISTORY.SEQ) + history = [vm.HISTORY_RECORDS.HISTORY]; + + var now = Math.round(new Date().getTime() / 1000); + + for (var i=0; i < history.length; i++){ + // :TIME time calculations copied from onevm_helper.rb + var stime = parseInt(history[i].STIME, 10); + + var etime = parseInt(history[i].ETIME, 10) + etime = etime == 0 ? now : etime; + + var dtime = etime - stime; + // end :TIME + + //:PTIME + var stime2 = parseInt(history[i].PSTIME, 10); + var etime2; + var ptime2 = parseInt(history[i].PETIME, 10); + if (stime2 == 0) + etime2 = 0; + else + etime2 = ptime2 == 0 ? now : ptime2; + var dtime2 = etime2 - stime2; + + //end :PTIME + + + html += ' \ + \ + \ + \ + \ + \ + \ + \ + ' + }; + html += '\ +
    '+tr("Sequence")+''+tr("Hostname")+''+tr("Reason")+''+tr("State change time")+''+tr("Total time")+''+tr("Prolog time")+'
    '+history[i].SEQ+''+history[i].HOSTNAME+''+OpenNebula.Helper.resource_state("VM_MIGRATE_REASON",parseInt(history[i].REASON, 10))+''+pretty_time(history[i].STIME)+''+pretty_time_runtime(dtime)+''+pretty_time_runtime(dtime2)+'
    '; + return html; + +}; // Refreshes the information panel for a VM @@ -821,7 +887,7 @@ function updateVMInfo(request,vm){
    ' - } + }; var template_tab = { title: tr("VM Template"), @@ -830,21 +896,27 @@ function updateVMInfo(request,vm){ '+tr("VM template")+''+ prettyPrintJSON(vm_info.TEMPLATE)+ '' - } + }; var log_tab = { title: tr("VM log"), content: '
    '+spinner+'
    ' - } + }; var monitoring_tab = { title: tr("Monitoring information"), content: generateMonitoringDivs(vm_graphs,"vm_monitor_") - } + }; + + var history_tab = { + title: tr("History information"), + content: generateHistoryTable(vm_info), + }; Sunstone.updateInfoPanelTab("vm_info_panel","vm_info_tab",info_tab); Sunstone.updateInfoPanelTab("vm_info_panel","vm_template_tab",template_tab); Sunstone.updateInfoPanelTab("vm_info_panel","vm_log_tab",log_tab); + Sunstone.updateInfoPanelTab("vm_info_panel","vm_history_tab",history_tab); Sunstone.updateInfoPanelTab("vm_info_panel","vm_monitoring_tab",monitoring_tab); //Pop up the info panel and asynchronously get vm_log and stats diff --git a/src/sunstone/public/js/sunstone-util.js b/src/sunstone/public/js/sunstone-util.js index 22064569de..7877635b51 100644 --- a/src/sunstone/public/js/sunstone-util.js +++ b/src/sunstone/public/js/sunstone-util.js @@ -60,6 +60,20 @@ function pretty_time_axis(time){ return hour + ":" + mins + ":" + secs;// + " " + month + "/" + day; } +function pretty_time_runtime(time){ + var d = new Date(); + d.setTime(time*1000); + + var secs = pad(d.getUTCSeconds(),2); + var hour = pad(d.getUTCHours(),2); + var mins = pad(d.getUTCMinutes(),2); + var day = d.getUTCDate()-1; + var month = pad(d.getUTCMonth()+1,2); //getMonths returns 0-11 + var year = d.getUTCFullYear(); + + return day + "d " + hour + ":" + mins;// + ":" + secs;// + " " + month + "/" + day; +} + //returns a human readable size in Kilo, Mega, Giga or Tera bytes function humanize_size(value) { if (typeof(value) === "undefined") { From ef97c118c8b57af6e05733bb7a0e1ef4cdf45e00 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Tue, 27 Mar 2012 16:19:41 +0200 Subject: [PATCH 06/12] Sunstone: hide manual disk and network addition when creating vm templates --- src/sunstone/public/js/plugins/hosts-tab.js | 4 ---- .../public/js/plugins/templates-tab.js | 21 ++++++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/sunstone/public/js/plugins/hosts-tab.js b/src/sunstone/public/js/plugins/hosts-tab.js index 147e793ef5..dd4423c77a 100644 --- a/src/sunstone/public/js/plugins/hosts-tab.js +++ b/src/sunstone/public/js/plugins/hosts-tab.js @@ -499,10 +499,6 @@ function updateHostInfo(request,host){ '+ tr("VN MAD") +'\ '+host_info.VN_MAD+'\ \ - \ - '+ tr("TM MAD") +'\ - '+host_info.TM_MAD+'\ - \ \ \ \ diff --git a/src/sunstone/public/js/plugins/templates-tab.js b/src/sunstone/public/js/plugins/templates-tab.js index f7496b0892..59d7165900 100644 --- a/src/sunstone/public/js/plugins/templates-tab.js +++ b/src/sunstone/public/js/plugins/templates-tab.js @@ -186,7 +186,7 @@ var create_template_tmpl = '
    \

    '+tr("Add disks/images")+'

    \
    \
    '+tr("Disks")+'\ -
    \ +