diff --git a/install.sh b/install.sh
index 52a312ab3d..3141640429 100755
--- a/install.sh
+++ b/install.sh
@@ -1116,6 +1116,7 @@ SUNSTONE_MODELS_JSON_FILES="src/sunstone/models/OpenNebulaJSON/HostJSON.rb \
src/sunstone/models/OpenNebulaJSON/VirtualMachineJSON.rb \
src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb \
src/sunstone/models/OpenNebulaJSON/AclJSON.rb \
+ src/sunstone/models/OpenNebulaJSON/ClusterJSON.rb \
src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb"
SUNSTONE_TEMPLATE_FILES="src/sunstone/templates/login.html \
@@ -1134,6 +1135,7 @@ SUNSTONE_PUBLIC_JS_PLUGINS_FILES="\
src/sunstone/public/js/plugins/dashboard-tab.js \
src/sunstone/public/js/plugins/dashboard-users-tab.js \
src/sunstone/public/js/plugins/hosts-tab.js \
+ src/sunstone/public/js/plugins/clusters-tab.js \
src/sunstone/public/js/plugins/groups-tab.js \
src/sunstone/public/js/plugins/images-tab.js \
src/sunstone/public/js/plugins/templates-tab.js \
diff --git a/src/sunstone/etc/sunstone-plugins.yaml b/src/sunstone/etc/sunstone-plugins.yaml
index ce33cfff64..d08072929d 100644
--- a/src/sunstone/etc/sunstone-plugins.yaml
+++ b/src/sunstone/etc/sunstone-plugins.yaml
@@ -14,6 +14,11 @@
:user:
:group:
oneadmin: true
+- plugins/clusters-tab.js:
+ :ALL: false
+ :user:
+ :group:
+ oneadmin: true
- plugins/vms-tab.js:
:ALL: true
:user:
diff --git a/src/sunstone/models/OpenNebulaJSON.rb b/src/sunstone/models/OpenNebulaJSON.rb
index ad5c493785..60b0ab116c 100644
--- a/src/sunstone/models/OpenNebulaJSON.rb
+++ b/src/sunstone/models/OpenNebulaJSON.rb
@@ -19,6 +19,7 @@ include OpenNebula
require 'OpenNebulaJSON/GroupJSON'
require 'OpenNebulaJSON/HostJSON'
+require 'OpenNebulaJSON/ClusterJSON'
require 'OpenNebulaJSON/ImageJSON'
require 'OpenNebulaJSON/TemplateJSON'
require 'OpenNebulaJSON/JSONUtils'
diff --git a/src/sunstone/models/OpenNebulaJSON/ClusterJSON.rb b/src/sunstone/models/OpenNebulaJSON/ClusterJSON.rb
index 806855c428..b834218a38 100644
--- a/src/sunstone/models/OpenNebulaJSON/ClusterJSON.rb
+++ b/src/sunstone/models/OpenNebulaJSON/ClusterJSON.rb
@@ -22,12 +22,10 @@ module OpenNebulaJSON
def create(template_json)
cluster_hash = parse_json(template_json, 'cluster')
-
if OpenNebula.is_error?(cluster_hash)
return cluster_hash
end
-
self.allocate(cluster_hash['name'])
end
@@ -37,9 +35,43 @@ module OpenNebulaJSON
return action_hash
end
- error_msg = "#{action_hash['perform']} action not " <<
- " available for this resource"
- OpenNebula::Error.new(error_msg)
+ rc = case action_hash['perform']
+ when "addhost" then self.addhost(action_hash['params'])
+ when "delhost" then self.delhost(action_hash['params'])
+ when "adddatastore" then self.adddatastore(action_hash['params'])
+ when "deldatastore" then self.deldatastore(action_hash['params'])
+ when "addvnet" then self.addvnet(action_hash['params'])
+ when "delvnet" then self.delvnet(action_hash['params'])
+
+ else
+ error_msg = "#{action_hash['perform']} action not " <<
+ " available for this resource"
+ OpenNebula::Error.new(error_msg)
+ end
+ end
+
+ def addhost(params=Hash.new)
+ super(params['host_id'].to_i)
+ end
+
+ def delhost(params=Hash.new)
+ super(params['host_id'].to_i)
+ end
+
+ def adddatastore(params=Hash.new)
+ super(params['ds_id'].to_i)
+ end
+
+ def deldatastore(params=Hash.new)
+ super(params['ds_id'].to_i)
+ end
+
+ def addvnet(params=Hash.new)
+ super(params['vnet_id'].to_i)
+ end
+
+ def delvnet(params=Hash.new)
+ super(params['vnet_id'].to_i)
end
end
end
diff --git a/src/sunstone/models/OpenNebulaJSON/HostJSON.rb b/src/sunstone/models/OpenNebulaJSON/HostJSON.rb
index b0dbac71b8..3ca11ecb0b 100644
--- a/src/sunstone/models/OpenNebulaJSON/HostJSON.rb
+++ b/src/sunstone/models/OpenNebulaJSON/HostJSON.rb
@@ -30,7 +30,7 @@ module OpenNebulaJSON
host_hash['im_mad'],
host_hash['vm_mad'],
host_hash['vnm_mad'],
- host_hash['tm_mad'])
+ host_hash['cluster_id'].to_i)
end
def delete
diff --git a/src/sunstone/models/OpenNebulaJSON/PoolJSON.rb b/src/sunstone/models/OpenNebulaJSON/PoolJSON.rb
index fbca6fe2a4..fe8e67dcfd 100644
--- a/src/sunstone/models/OpenNebulaJSON/PoolJSON.rb
+++ b/src/sunstone/models/OpenNebulaJSON/PoolJSON.rb
@@ -25,4 +25,5 @@ module OpenNebulaJSON
class GroupPoolJSON < OpenNebula::GroupPool; include JSONUtils; end
class UserPoolJSON < OpenNebula::UserPool; include JSONUtils; end
class AclPoolJSON < OpenNebula::AclPool; include JSONUtils; end
+ class ClusterPoolJSON < OpenNebula::ClusterPool; include JSONUtils; end
end
diff --git a/src/sunstone/models/SunstoneServer.rb b/src/sunstone/models/SunstoneServer.rb
index 6696d7f436..7a64255bb6 100644
--- a/src/sunstone/models/SunstoneServer.rb
+++ b/src/sunstone/models/SunstoneServer.rb
@@ -48,6 +48,7 @@ class SunstoneServer < CloudServer
pool = case kind
when "group" then GroupPoolJSON.new(@client)
+ when "cluster" then ClusterPoolJSON.new(@client)
when "host" then HostPoolJSON.new(@client)
when "image" then ImagePoolJSON.new(@client, user_flag)
when "vmtemplate" then TemplatePoolJSON.new(@client, user_flag)
@@ -100,6 +101,7 @@ class SunstoneServer < CloudServer
def create_resource(kind, template)
resource = case kind
when "group" then GroupJSON.new(Group.build_xml, @client)
+ when "cluster" then ClusterJSON.new(Group.build_xml, @client)
when "host" then HostJSON.new(Host.build_xml, @client)
when "image" then ImageJSON.new(Image.build_xml, @client)
when "vmtemplate" then TemplateJSON.new(Template.build_xml, @client)
@@ -275,6 +277,7 @@ class SunstoneServer < CloudServer
def retrieve_resource(kind, id)
resource = case kind
when "group" then GroupJSON.new_with_id(id, @client)
+ when "cluster" then ClusterJSON.new_with_id(id, @client)
when "host" then HostJSON.new_with_id(id, @client)
when "image" then ImageJSON.new_with_id(id, @client)
when "vmtemplate" then TemplateJSON.new_with_id(id, @client)
diff --git a/src/sunstone/public/js/opennebula.js b/src/sunstone/public/js/opennebula.js
index 9552c3563e..560170b6ea 100644
--- a/src/sunstone/public/js/opennebula.js
+++ b/src/sunstone/public/js/opennebula.js
@@ -852,5 +852,49 @@ var OpenNebula = {
"list" : function(params){
OpenNebula.Action.list(params,OpenNebula.Acl.resource);
}
- }
+ },
+
+ "Cluster" : {
+ "resource" : "CLUSTER",
+
+ "create" : function(params){
+ OpenNebula.Action.create(params,OpenNebula.Cluster.resource);
+ },
+ "delete" : function(params){
+ OpenNebula.Action.delete(params,OpenNebula.Cluster.resource);
+ },
+ "list" : function(params){
+ OpenNebula.Action.list(params,OpenNebula.Cluster.resource);
+ },
+ "addhost" : function(params){
+ var action_obj = { "host_id": params.data.extra_param };
+ OpenNebula.Action.simple_action(params,OpenNebula.Cluster.resource,
+ "addhost",action_obj);
+ },
+ "delhost" : function(params){
+ var action_obj = { "host_id": params.data.extra_param };
+ OpenNebula.Action.simple_action(params,OpenNebula.Cluster.resource,
+ "delhost",action_obj);
+ },
+ "adddatastore" : function(params){
+ var action_obj = { "ds_id": params.data.extra_param };
+ OpenNebula.Action.simple_action(params,OpenNebula.Cluster.resource,
+ "adddatastore",action_obj);
+ },
+ "deldatastore" : function(params){
+ var action_obj = { "ds_id": params.data.extra_param };
+ OpenNebula.Action.simple_action(params,OpenNebula.Cluster.resource,
+ "deldatastore",action_obj);
+ },
+ "addvnet" : function(params){
+ var action_obj = { "vnet_id": params.data.extra_param };
+ OpenNebula.Action.simple_action(params,OpenNebula.Cluster.resource,
+ "addvnet",action_obj);
+ },
+ "delvnet" : function(params){
+ var action_obj = { "vnet_id": params.data.extra_param };
+ OpenNebula.Action.simple_action(params,OpenNebula.Cluster.resource,
+ "delvnet",action_obj);
+ },
+ },
}
diff --git a/src/sunstone/public/js/plugins/clusters-tab.js b/src/sunstone/public/js/plugins/clusters-tab.js
new file mode 100644
index 0000000000..3d4a2079ca
--- /dev/null
+++ b/src/sunstone/public/js/plugins/clusters-tab.js
@@ -0,0 +1,511 @@
+/* -------------------------------------------------------------------------- */
+/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */
+/* */
+/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
+/* not use this file except in compliance with the License. You may obtain */
+/* a copy of the License at */
+/* */
+/* http://www.apache.org/licenses/LICENSE-2.0 */
+/* */
+/* Unless required by applicable law or agreed to in writing, software */
+/* distributed under the License is distributed on an "AS IS" BASIS, */
+/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
+/* See the License for the specific language governing permissions and */
+/* limitations under the License. */
+/* -------------------------------------------------------------------------- */
+
+/*Cluster tab plugin*/
+
+
+var clusters_tab_content =
+'
';
+
+var create_cluster_tmpl =
+'';
+
+var clusters_select="";
+var dataTable_clusters;
+var $create_cluster_dialog;
+
+//Setup actions
+var cluster_actions = {
+
+ "Cluster.create" : {
+ type: "create",
+ call : OpenNebula.Cluster.create,
+ callback : addClusterElement,
+ error : onError,
+ notify: true
+ },
+
+ "Cluster.create_dialog" : {
+ type: "custom",
+ call: popUpCreateClusterDialog
+ },
+
+ "Cluster.list" : {
+ type: "list",
+ call: OpenNebula.Cluster.list,
+ callback: updateClustersView,
+ error: onError
+ },
+
+ "Cluster.show" : {
+ type: "single",
+ call: OpenNebula.Cluster.show,
+ callback: updateClusterElement,
+ error: onError
+ },
+
+/*
+
+ "Cluster.showinfo" : {
+ type: "single",
+ call: OpenNebula.Cluster.show,
+ callback: updateClusterInfo,
+ error: onError
+ },
+*/
+
+ "Cluster.refresh" : {
+ type: "custom",
+ call: function(){
+ waitingNodes(dataTable_clusters);
+ Sunstone.runAction("Cluster.list");
+ },
+ error: onError
+ },
+
+ "Cluster.autorefresh" : {
+ type: "custom",
+ call : function() {
+ OpenNebula.Cluster.list({timeout: true, success: updateClustersView,error: onError});
+ }
+ },
+
+ "Cluster.addhost" : {
+ type: "single",
+ call : OpenNebula.Cluster.addhost,
+ callback : function (req) {
+ Sunstone.runAction("Host.show",req.request.data[0][1].host_id);
+ },
+ error : onError,
+ },
+
+ "Cluster.delhost" : {
+ type: "single",
+ call : OpenNebula.Cluster.delhost,
+ callback : function (req) {
+ //Sunstone.runAction("Cluster.show",req.request.data[0]);
+ },
+ error : onError,
+ notify: true
+ },
+
+ "Cluster.adddatastore" : {
+ type: "single",
+ call : OpenNebula.Cluster.addhost,
+ callback : function (req) {
+ Sunstone.runAction("Datastore.show",req.request.data[0][1].ds_id);
+ //Sunstone.runAction("Cluster.show",req.request.data[0]);
+ },
+ error : onError,
+ },
+
+ "Cluster.deldatastore" : {
+ type: "single",
+ call : OpenNebula.Cluster.addhost,
+ callback : function (req) {
+ //Sunstone.runAction("Cluster.show",req.request.data[0]);
+ },
+ error : onError,
+ },
+
+ "Cluster.addvnet" : {
+ type: "single",
+ call : OpenNebula.Cluster.addvnet,
+ callback : function (req) {
+ Sunstone.runAction("Network.show",req.request.data[0][1].vnet_id);
+ },
+ error : onError,
+ },
+
+ "Cluster.delvnet" : {
+ type: "single",
+ call : OpenNebula.Cluster.delvnet,
+ callback : function (req) {
+ //Sunstone.runAction("Cluster.show",req.request.data[0]);
+ },
+ error : onError,
+ notify: true
+ },
+
+ "Cluster.delete" : {
+ type: "multiple",
+ call : OpenNebula.Cluster.delete,
+ callback : deleteClusterElement,
+ elements: clusterElements,
+ error : onError,
+ notify:true
+ },
+};
+
+var cluster_buttons = {
+ "Cluster.refresh" : {
+ type: "image",
+ text: tr("Refresh list"),
+ img: "images/Refresh-icon.png"
+ },
+ "Cluster.create_dialog" : {
+ type: "create_dialog",
+ text: tr("+ New")
+ },
+ "Cluster.delete" : {
+ type: "confirm",
+ text: tr("Delete")
+ }
+};
+
+/*
+var host_info_panel = {
+ "host_info_tab" : {
+ title: tr("Host information"),
+ content:""
+ },
+
+ "host_template_tab" : {
+ title: tr("Host template"),
+ content: ""
+ },
+ "host_monitoring_tab": {
+ title: tr("Monitoring information"),
+ content: ""
+ }
+};
+*/
+
+
+var clusters_tab = {
+ title: tr("Clusters"),
+ content: clusters_tab_content,
+ buttons: cluster_buttons
+}
+
+Sunstone.addActions(cluster_actions);
+Sunstone.addMainTab('clusters_tab',clusters_tab);
+//Sunstone.addInfoPanel("host_info_panel",host_info_panel);
+
+
+function clusterElements(){
+ return getSelectedNodes(dataTable_clusters);
+}
+
+function clusterElementArray(element_json){
+
+ var element = element_json.CLUSTER;
+
+ return [
+ '',
+ element.ID,
+ element.NAME,
+ ];
+}
+
+/*
+//Listen to clicks on the tds of the tables and shows the info dialogs.
+function hostInfoListener(){
+ $('#tbodyhosts tr',dataTable_hosts).live("click",function(e){
+ //do nothing if we are clicking a checkbox!
+ if ($(e.target).is('input')) {return true;}
+
+ var aData = dataTable_hosts.fnGetData(this);
+ var id = $(aData[0]).val();
+ if (!id) return true;
+
+ popDialogLoading();
+ Sunstone.runAction("Host.showinfo",id);
+ return false;
+ });
+}
+*/
+
+//updates the host select by refreshing the options in it
+function updateClusterSelect(){
+ clusters_select = '';
+ clusters_select += makeSelectOptions(dataTable_clusters,
+ 1,//id_col
+ 2,//name_col
+ [],//status_cols
+ [],//bad_st
+ true
+ );
+}
+
+//callback for an action affecting a host element
+function updateClusterElement(request, element_json){
+ var id = element_json.CLUSTER.ID;
+ var element = clusterElementArray(element_json);
+ updateSingleElement(element,dataTable_clusters,'#cluster_'+id);
+ updateClusterSelect();
+}
+
+//callback for actions deleting a host element
+function deleteClusterElement(req){
+ deleteElement(dataTable_clusters,'#cluster_'+req.request.data);
+ updateClusterSelect();
+}
+
+//call back for actions creating a host element
+function addClusterElement(request,element_json){
+ var id = element_json.CLUSTER.ID;
+ var element = clusterElementArray(element_json);
+ addElement(element,dataTable_clusters);
+ updateClusterSelect();
+}
+
+//callback to update the list of hosts.
+function updateClustersView (request,list){
+ var list_array = [];
+
+ $.each(list,function(){
+ //Grab table data from the host_list
+ list_array.push(clusterElementArray(this));
+ });
+
+ updateView(list_array,dataTable_clusters);
+ updateClusterSelect();
+ //dependency with the dashboard plugin
+ updateDashboard("clusters",list);
+}
+
+/*
+//Updates the host info panel tab's content and pops it up
+function updateHostInfo(request,host){
+ var host_info = host.HOST;
+
+ //Information tab
+ var info_tab = {
+ title : tr("Host information"),
+ content :
+ '\
+ \
+ | ' + tr("Host information") + ' - '+host_info.NAME+' |
\
+ \
+ \
+ \
+ | ' + tr("id") + ' | \
+ '+host_info.ID+' | \
+
\
+ \
+ | ' + tr("Name") + ' | \
+ '+host_info.NAME+' | \
+
\
+ \
+ | ' + tr("Cluster") + ' | \
+ '+host_info.CLUSTER+' | \
+
\
+ \
+ | ' + tr("State") + ' | \
+ '+tr(OpenNebula.Helper.resource_state("host",host_info.STATE))+' | \
+
\
+ \
+ | ' + tr("IM MAD") + ' | \
+ '+host_info.IM_MAD+' | \
+
\
+ \
+ | ' + tr("VM MAD") + ' | \
+ '+host_info.VM_MAD+' | \
+
\
+ \
+ | '+ tr("VN MAD") +' | \
+ '+host_info.VN_MAD+' | \
+
\
+ \
+ | '+ tr("TM MAD") +' | \
+ '+host_info.TM_MAD+' | \
+
\
+ \
+
\
+ \
+ \
+ | ' + tr("Host shares") + ' |
\
+ \
+ \
+ \
+ | ' + tr("Max Mem") + ' | \
+ '+humanize_size(host_info.HOST_SHARE.MAX_MEM)+' | \
+
\
+ \
+ | ' + tr("Used Mem (real)") + ' | \
+ '+humanize_size(host_info.HOST_SHARE.USED_MEM)+' | \
+
\
+ \
+ | ' + tr("Used Mem (allocated)") + ' | \
+ '+humanize_size(host_info.HOST_SHARE.MAX_USAGE)+' | \
+
\
+ \
+ | ' + tr("Used CPU (real)") + ' | \
+ '+host_info.HOST_SHARE.USED_CPU+' | \
+
\
+ \
+ | ' + tr("Used CPU (allocated)") + ' | \
+ '+host_info.HOST_SHARE.CPU_USAGE+' | \
+
\
+ \
+ | ' + tr("Running VMs") + ' | \
+ '+host_info.HOST_SHARE.RUNNING_VMS+' | \
+
\
+ \
+
'
+ }
+
+ //Template tab
+ var template_tab = {
+ title : tr("Host template"),
+ content :
+ '\
+ | ' + tr("Host template") + ' |
'+
+ prettyPrintJSON(host_info.TEMPLATE)+
+ '
'
+ }
+
+ var monitor_tab = {
+ title: tr("Monitoring information"),
+ content : generateMonitoringDivs(host_graphs,"host_monitor_")
+ }
+
+ //Sunstone.updateInfoPanelTab(info_panel_name,tab_name, new tab object);
+ Sunstone.updateInfoPanelTab("host_info_panel","host_info_tab",info_tab);
+ Sunstone.updateInfoPanelTab("host_info_panel","host_template_tab",template_tab);
+ Sunstone.updateInfoPanelTab("host_info_panel","host_monitoring_tab",monitor_tab);
+
+ Sunstone.popUpInfoPanel("host_info_panel");
+ //pop up panel while we retrieve the graphs
+ for (var i=0; i');
+ $create_cluster_dialog = $('div#create_cluster_dialog');
+ var dialog = $create_cluster_dialog;
+
+ dialog.html(create_cluster_tmpl);
+ dialog.dialog({
+ autoOpen: false,
+ modal: true,
+ width: 500
+ });
+
+ $('button',dialog).button();
+
+ //Handle the form submission
+ $('#create_cluster_form',dialog).submit(function(){
+ if (!($('#name',this).val().length)){
+ notifyError(tr("Cluster name missing!"));
+ return false;
+ }
+
+ var cluster_json = {
+ "cluster": {
+ "name": $('#name',this).val(),
+ }
+ };
+
+ //Create the OpenNebula.Host.
+ //If it's successfull we refresh the list.
+ Sunstone.runAction("Cluster.create",cluster_json);
+ $create_cluster_dialog.dialog('close');
+ return false;
+ });
+}
+
+//Open creation dialogs
+function popUpCreateClusterDialog(){
+ $create_cluster_dialog.dialog('open');
+ return false;
+}
+
+//Prepares the autorefresh for hosts
+function setClusterAutorefresh() {
+ setInterval(function(){
+ var checked = $('input.check_item:checked',dataTable_clusters);
+ var filter = $("#datatable_clusters_filter input",dataTable_clusters.parents('#datatable_clusters_wrapper')).attr('value');
+ if (!checked.length && !filter.length){
+ Sunstone.runAction("Cluster.autorefresh");
+ }
+ },INTERVAL+someTime());
+}
+
+
+function clusters_sel() {
+ return clusters_select;
+}
+
+//This is executed after the sunstone.js ready() is run.
+//Here we can basicly init the host datatable, preload it
+//and add specific listeners
+$(document).ready(function(){
+
+ //prepare host datatable
+ dataTable_clusters = $("#datatable_clusters",main_tabs_context).dataTable({
+ "bJQueryUI": true,
+ "bSortClasses": false,
+ "bAutoWidth":false,
+ "sPaginationType": "full_numbers",
+ "aoColumnDefs": [
+ { "bSortable": false, "aTargets": ["check"] },
+ { "sWidth": "60px", "aTargets": [0] },
+ { "sWidth": "35px", "aTargets": [1] },
+ ],
+ "oLanguage": (datatable_lang != "") ?
+ {
+ sUrl: "locale/"+lang+"/"+datatable_lang
+ } : ""
+ });
+
+ //preload it
+ dataTable_clusters.fnClearTable();
+ addElement([
+ spinner,
+ '','',''],dataTable_clusters);
+ Sunstone.runAction("Cluster.list");
+
+ setupCreateClusterDialog();
+
+ setClusterAutorefresh();
+
+ initCheckAllBoxes(dataTable_clusters);
+ tableCheckboxesListener(dataTable_clusters);
+// clusterInfoListener();
+});
diff --git a/src/sunstone/public/js/plugins/hosts-tab.js b/src/sunstone/public/js/plugins/hosts-tab.js
index d076b59573..2d87e1585f 100644
--- a/src/sunstone/public/js/plugins/hosts-tab.js
+++ b/src/sunstone/public/js/plugins/hosts-tab.js
@@ -43,6 +43,7 @@ var hosts_tab_content =
' + tr("All") + ' | \
' + tr("id") + ' | \
' + tr("Name") + ' | \
+ ' + tr("Cluster") + ' | \
' + tr("Running VMs") + ' | \
' + tr("CPU Use") + ' | \
' + tr("Memory use") + ' | \
@@ -93,19 +94,15 @@ var create_host_tmpl =
\
\
\
- \
-
\
-