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

Merge branch 'feature-407rm'

This commit is contained in:
Ruben S. Montero 2011-06-13 23:05:23 +02:00
commit 75abcefb4d
24 changed files with 3572 additions and 3432 deletions

View File

@ -17,7 +17,7 @@
require 'OpenNebula'
include OpenNebula
require 'OpenNebulaJSON/ClusterJSON'
require 'OpenNebulaJSON/GroupJSON'
require 'OpenNebulaJSON/HostJSON'
require 'OpenNebulaJSON/ImageJSON'
require 'OpenNebulaJSON/TemplateJSON'

View File

@ -17,16 +17,16 @@
require 'OpenNebulaJSON/JSONUtils'
module OpenNebulaJSON
class ClusterJSON < OpenNebula::Cluster
class GroupJSON < OpenNebula::Group
include JSONUtils
def create(template_json)
cluster_hash = parse_json(template_json,'cluster')
if OpenNebula.is_error?(cluster_hash)
return cluster_hash
group_hash = parse_json(template_json,'group')
if OpenNebula.is_error?(group_hash)
return group_hash
end
self.allocate(cluster_hash['name'])
self.allocate(group_hash['name'])
end
def perform_action(template_json)
@ -36,8 +36,7 @@ module OpenNebulaJSON
end
rc = case action_hash['perform']
when "add_host" then self.add_host(action_hash['params'])
when "remove_host" then self.remove_host(action_hash['params'])
when "chown" then self.chown(action_hash['params'])
else
error_msg = "#{action_hash['perform']} action not " <<
" available for this resource"
@ -45,12 +44,8 @@ module OpenNebulaJSON
end
end
def add_host(params=Hash.new)
super(params['host_id'])
end
def remove_host(params=Hash.new)
super(params['host_id'])
def chown(params=Hash.new)
super(params['owner_id'].to_i)
end
end
end

View File

@ -50,6 +50,7 @@ module OpenNebulaJSON
when "rm_attr" then self.remove_attr(action_hash['params'])
when "unpublish" then self.unpublish
when "update" then self.update(action_hash['params'])
when "chown" then self.chown(action_hash['params'])
else
error_msg = "#{action_hash['perform']} action not " <<
" available for this resource"
@ -58,11 +59,15 @@ module OpenNebulaJSON
end
def update(params=Hash.new)
super(params['name'], params['value'])
super(params['template_raw'])
end
def remove_attr(params=Hash.new)
super(params['name'])
end
def chown(params=Hash.new)
super(params['owner_id'].to_i,params['group_id'].to_i)
end
end
end

View File

@ -15,6 +15,7 @@
#--------------------------------------------------------------------------- #
module OpenNebulaJSON
require 'json'
module JSONUtils

View File

@ -22,6 +22,6 @@ module OpenNebulaJSON
class VirtualNetworkPoolJSON < OpenNebula::VirtualNetworkPool; include JSONUtils; end
class ImagePoolJSON < OpenNebula::ImagePool; include JSONUtils; end
class TemplatePoolJSON < OpenNebula::TemplatePool; include JSONUtils; end
class ClusterPoolJSON < OpenNebula::ClusterPool; include JSONUtils; end
class GroupPoolJSON < OpenNebula::GroupPool; include JSONUtils; end
class UserPoolJSON < OpenNebula::UserPool; include JSONUtils; end
end

View File

@ -43,23 +43,22 @@ module OpenNebulaJSON
rc = case action_hash['perform']
when "publish" then self.publish
when "rm_attr" then self.remove_attr(action_hash['params'])
when "unpublish" then self.unpublish
when "update" then self.update(action_hash['params'])
when "chown" then self.chown(action_hash['params'])
else
error_msg = "#{action_hash['perform']} action not " <<
" available for this resource"
OpenNebula::Error.new(error_msg)
end
end
def update(params=Hash.new)
super(params['name'], params['value'])
super(params['template_raw'])
end
def remove_attr(params=Hash.new)
super(params['name'])
def chown(params=Hash.new)
super(params['owner_id'].to_i,params['group_id'].to_i)
end
end
end

View File

@ -38,6 +38,7 @@ module OpenNebulaJSON
rc = case action_hash['perform']
when "passwd" then self.passwd(action_hash['params'])
when "chgrp" then self.chgrp(action_hash['params'])
else
error_msg = "#{action_hash['perform']} action not " <<
" available for this resource"
@ -49,5 +50,9 @@ module OpenNebulaJSON
password = Digest::SHA1.hexdigest(params['password'])
super(password)
end
def chgrp(params=Hash.new)
super(params['group_id'])
end
end
end

View File

@ -63,6 +63,7 @@ module OpenNebulaJSON
when "saveas" then self.save_as(action_hash['params'])
when "shutdown" then self.shutdown
when "resubmit" then self.resubmit
when "chown" then self.chown(action_hash['params'])
else
error_msg = "#{action_hash['perform']} action not " <<
" available for this resource"
@ -89,5 +90,9 @@ module OpenNebulaJSON
def save_as(params=Hash.new)
super(params['disk_id'].to_i, params['image_name'])
end
def chown(params=Hash.new)
super(params['owner_id'].to_i,params['group_id'].to_i)
end
end
end

View File

@ -44,11 +44,16 @@ module OpenNebulaJSON
rc = case action_hash['perform']
when "publish" then self.publish
when "unpublish" then self.unpublish
when "chown" then self.chown(action_hash['params'])
else
error_msg = "#{action_hash['perform']} action not " <<
" available for this resource"
OpenNebula::Error.new(error_msg)
end
end
def chown(params=Hash.new)
super(params['owner_id'].to_i,params['group_id'].to_i)
end
end
end

View File

@ -55,7 +55,7 @@ class SunstoneServer
def get_pool(kind)
user_flag = -2
pool = case kind
when "cluster" then ClusterPoolJSON.new(@client)
when "group" then GroupPoolJSON.new(@client)
when "host" then HostPoolJSON.new(@client)
when "image" then ImagePoolJSON.new(@client, user_flag)
when "template" then TemplatePoolJSON.new(@client, user_flag)
@ -87,12 +87,25 @@ class SunstoneServer
end
end
############################################################################
#
############################################################################
def get_template(kind,id)
resource = retrieve_resource(kind,id)
if OpenNebula.is_error?(resource)
return [404, resource.to_json]
else
template_str = resource.template_str(true)
return [200, {:template => template_str}.to_json]
end
end
############################################################################
#
############################################################################
def create_resource(kind, template)
resource = case kind
when "cluster" then ClusterJSON.new(Cluster.build_xml, @client)
when "group" then GroupJSON.new(Group.build_xml, @client)
when "host" then HostJSON.new(Host.build_xml, @client)
when "image" then ImageJSON.new(Image.build_xml, @client)
when "template" then TemplateJSON.new(Template.build_xml, @client)
@ -299,7 +312,7 @@ class SunstoneServer
def retrieve_resource(kind, id)
resource = case kind
when "cluster" then ClusterJSON.new_with_id(id, @client)
when "group" then GroupJSON.new_with_id(id, @client)
when "host" then HostJSON.new_with_id(id, @client)
when "image" then ImageJSON.new_with_id(id, @client)
when "template" then TemplateJSON.new_with_id(id, @client)

View File

@ -235,7 +235,7 @@ div.tip span.man_icon {
display:inline-block!important;
}
span.tipspan {
span.tipspan,div.full_info {
position: fixed;
display:block;
padding:4px;

View File

@ -177,6 +177,42 @@ var OpenNebula = {
p_pool[0][type] = pool;
return(p_pool);
}
},
"chown": function(params,resource,url_prefix,chgrp){
var callback = params.success;
var callback_error = params.error;
var id = params.data.id;
var id2 = params.data.extra_param;
var method = "chown";
//if trying to change group, set owner to -1, otherwise set group to -1
var object = chgrp ? {"owner_id": "-1", "group_id": id2} : {"owner_id": id2, "group_id": "-1"};
var action = OpenNebula.Helper.action(method,object);
var request = OpenNebula.Helper.request(resource,method, [id, id2]);
$.ajax({
url: url_prefix + "/" + id + "/action",
type: "POST",
data: JSON.stringify(action),
success: function()
{
if (callback)
{
callback(request);
}
},
error: function(response)
{
if (callback_error)
{
callback_error(request, OpenNebula.Error(response));
}
}
});
},
"chgrp": function(params,resource,url_prefix){
OpenNebula.Helper.chown(params,resource,url_prefix,true);
}
},
@ -725,6 +761,14 @@ var OpenNebula = {
}
}
});
},
"chown" : function(params){
OpenNebula.Helper.chown(params,OpenNebula.Network.resource,"vnet");
},
"chgrp" : function(params){
OpenNebula.Helper.chgrp(params,OpenNebula.Network.resource,"vnet");
}
},
@ -1431,24 +1475,31 @@ var OpenNebula = {
}
}
});
}
},
"Cluster": {
"resource": "CLUSTER",
"chown" : function(params){
OpenNebula.Helper.chown(params,OpenNebula.VM.resource,"vm");
},
"chgrp" : function(params){
OpenNebula.Helper.chgrp(params,OpenNebula.VM.resource,"vm");
}
},
"Group": {
"resource": "GROUP",
"create": function(params)
{
var callback = params.success;
var callback_error = params.error;
var data = params.data;
var resource = OpenNebula.Cluster.resource;
var resource = OpenNebula.Group.resource;
var request = OpenNebula.Helper.request(resource,"create", name);
$.ajax({
url: "/cluster",
url: "/group",
type: "POST",
dataType: "json",
data: JSON.stringify(data),
@ -1474,12 +1525,12 @@ var OpenNebula = {
var callback = params.success;
var callback_error = params.error;
var id = params.data.id;
var resource = OpenNebula.Cluster.resource;
var resource = OpenNebula.Group.resource;
var request = OpenNebula.Helper.request(resource,"delete", id);
$.ajax({
url: "/cluster/" + id,
url: "/group/" + id,
type: "DELETE",
success: function()
{
@ -1504,11 +1555,11 @@ var OpenNebula = {
var callback_error = params.error;
var timeout = params.timeout || false;
var resource = OpenNebula.Cluster.resource;
var resource = OpenNebula.Group.resource;
var request = OpenNebula.Helper.request(resource,"list");
$.ajax({
url: "/cluster",
url: "/group",
type: "GET",
dataType: "json",
data: {timeout: timeout},
@ -1516,8 +1567,8 @@ var OpenNebula = {
{
if (callback)
{
var cluster_pool = OpenNebula.Helper.pool(resource,response);
callback(request, cluster_pool);
var group_pool = OpenNebula.Helper.pool(resource,response);
callback(request, group_pool);
}
},
error: function(response)
@ -1530,75 +1581,9 @@ var OpenNebula = {
});
},
"addhost": function(params)
"chown": function(params)
{
var callback = params.success;
var callback_error = params.error;
var host_id = params.data.id;
var cluster_id = params.data.extra_param;
var resource = OpenNebula.Cluster.resource;
var method = "add_host";
var action = OpenNebula.Helper.action(method, {
"host_id" : host_id
});
var request = OpenNebula.Helper.request(resource,method, [host_id, cluster_id]);
$.ajax({
url: "/cluster/" + cluster_id + "/action",
type: "POST",
data: JSON.stringify(action),
success: function(response)
{
if (callback)
{
callback(request, response);
}
},
error: function(response)
{
if (callback_error)
{
callback_error(request, OpenNebula.Error(response));
}
}
});
},
"removehost": function(params)
{
var callback = params.success;
var callback_error = params.error;
var host_id = params.data.id;
var cluster_id = params.data.extra_param;
var method = "remove_host";
var action = OpenNebula.Helper.action(method, {
"host_id" : host_id
});
var resource = OpenNebula.Cluster.resource;
var request = OpenNebula.Helper.request(resource,method, [host_id, cluster_id]);
$.ajax({
url: "/cluster/" + cluster_id + "/action",
type: "POST",
data: JSON.stringify(action),
success: function(response)
{
if (callback)
{
callback(request, response);
}
},
error: function(response)
{
if (callback_error)
{
callback_error(request, OpenNebula.Error(response));
}
}
});
OpenNebula.Helper.chown(params,OpenNebula.Group.resource,"group");
}
},
@ -1731,6 +1716,37 @@ var OpenNebula = {
}
}
});
},
"chgrp" : function(params){
var callback = params.success;
var callback_error = params.error;
var id = params.data.id;
var gid = params.data.extra_param;
var method = "chgrp";
var action = OpenNebula.Helper.action(method, {"group_id": gid});
var request = OpenNebula.Helper.request(OpenNebula.User.resource,method, [id, gid]);
$.ajax({
url: "user/" + id + "/action",
type: "POST",
data: JSON.stringify(action),
success: function()
{
if (callback)
{
callback(request);
}
},
error: function(response)
{
if (callback_error)
{
callback_error(request, OpenNebula.Error(response));
}
}
});
}
},
@ -1767,7 +1783,71 @@ var OpenNebula = {
}
});
},
"fetch_template" : function(params)
{
var callback = params.success;
var callback_error = params.error;
var id = params.data.id;
var method = "fetch_template";
var resource = OpenNebula.Image.resource;
var request = OpenNebula.Helper.request(resource,method, id);
$.ajax({
url: "/image/" + id + "/template",
type: "GET",
dataType:"json",
success: function(response)
{
if (callback)
{
callback(request,response);
}
},
error: function(response)
{
if(callback_error)
{
callback_error(request, OpenNebula.Error(response));
}
}
});
},
"update": function(params)
{
var callback = params.success;
var callback_error = params.error;
var id = params.data.id;
var template_raw = params.data.extra_param;
var template_obj = {"template_raw": template_raw}
var method = "update";
var action = OpenNebula.Helper.action(method, template_obj);
var resource = OpenNebula.Image.resource;
var request = OpenNebula.Helper.request(resource,method, [id, template_obj]);
$.ajax({
url: "/image/" + id + "/action",
type: "POST",
data: JSON.stringify(action),
success: function(response)
{
if (callback)
{
callback(request, response);
}
},
error: function(response)
{
if (callback_error)
{
callback_error(request, OpenNebula.Error(response));
}
}
});
},
"delete": function(params)
{
var callback = params.success;
@ -1858,82 +1938,6 @@ var OpenNebula = {
}
});
},
"addattr": function(params)
{
var callback = params.success;
var callback_error = params.error;
var id = params.data.id;
var name = params.data.name;
var value = params.data.value;
var method = "update";
var action = OpenNebula.Helper.action(method, {
"name" : name,
"value" : value
});
var resource = OpenNebula.Image.resource;
var request = OpenNebula.Helper.request(resource,method, [id, name, value]);
$.ajax({
url: "/image/" + id + "/action",
type: "POST",
data: JSON.stringify(action),
success: function(response)
{
if (callback)
{
callback(request, response);
}
},
error: function(response)
{
if (callback_error)
{
callback_error(request, OpenNebula.Error(response));
}
}
});
},
"rmattr": function(params)
{
var callback = params.success;
var callback_error = params.error;
var id = params.data.id;
var name = params.data.name;
var value = params.data.value;
var method = "rm_attr";
var action = OpenNebula.Helper.action(method, {
"name" : name
});
var resource = OpenNebula.Image.resource;
var request = OpenNebula.Helper.request(resource,method, [id, name]);
$.ajax({
url: "/image/" + id + "/action",
type: "POST",
data: JSON.stringify(action),
success: function(response)
{
if (callback)
{
callback(request, response);
}
},
error: function(response)
{
if (callback_error)
{
callback_error(request, OpenNebula.Error(response));
}
}
});
},
"enable": function(params)
{
var callback = params.success;
@ -2127,6 +2131,14 @@ var OpenNebula = {
}
}
});
},
"chown" : function(params){
OpenNebula.Helper.chown(params,OpenNebula.Image.resource,"image");
},
"chgrp" : function(params){
OpenNebula.Helper.chgrp(params,OpenNebula.Image.resource,"image");
}
},
@ -2164,27 +2176,20 @@ var OpenNebula = {
});
},
"addattr" : function(params)
"fetch_template" : function(params)
{
var callback = params.success;
var callback_error = params.error;
var id = params.data.id;
var name = params.data.name;
var value = params.data.value;
var method = "update";
var action = OpenNebula.Helper.action(method, {
"name" : name,
"value" : value
});
var method = "fetch_template";
var resource = OpenNebula.Template.resource;
var request = OpenNebula.Helper.request(resource,method, [id, name, value]);
var request = OpenNebula.Helper.request(resource,method, id);
$.ajax({
url: "/template/" + id + "/action",
type: "POST",
data: JSON.stringify(action),
url: "/template/" + id + "/template",
type: "GET",
dataType:"json",
success: function(response)
{
if (callback)
@ -2206,17 +2211,14 @@ var OpenNebula = {
var callback = params.success;
var callback_error = params.error;
var id = params.data.id;
var name = params.data.name;
var value = params.data.value;
var template_raw = params.data.extra_param;
var template_obj = {"template_raw": template_raw}
var method = "update";
var action = OpenNebula.Helper.action(method, {
"name" : name,
"value" : value
});
var action = OpenNebula.Helper.action(method, template_obj);
var resource = OpenNebula.Template.resource;
var request = OpenNebula.Helper.request(resource,method, [id, name, value]);
var request = OpenNebula.Helper.request(resource,method, [id, template_obj]);
$.ajax({
url: "/template/" + id + "/action",
@ -2238,42 +2240,7 @@ var OpenNebula = {
}
});
},
"rmattr" : function(params)
{
var callback = params.success;
var callback_error = params.error;
var id = params.data.id;
var name = params.data.name;
var value = params.data.value;
var method = "rm_attr";
var action = OpenNebula.Helper.action(method, {
"name" : name
});
var resource = OpenNebula.Template.resource;
var request = OpenNebula.Helper.request(resource,method, [id, name]);
$.ajax({
url: "/template/" + id + "/action",
type: "POST",
data: JSON.stringify(action),
success: function(response)
{
if (callback)
{
callback(request, response);
}
},
error: function(response)
{
if (callback_error)
{
callback_error(request, OpenNebula.Error(response));
}
}
});
},
"publish" : function(params)
{
var callback = params.success;
@ -2423,6 +2390,14 @@ var OpenNebula = {
}
}
});
},
"chown" : function(params){
OpenNebula.Helper.chown(params,OpenNebula.Template.resource,"template");
},
"chgrp" : function(params){
OpenNebula.Helper.chgrp(params,OpenNebula.Template.resource,"template");
}
}
}

View File

@ -15,7 +15,7 @@
/* -------------------------------------------------------------------------- */
var HISTORY_LENGTH=40;
var GRAPH_AUTOREFRESH_INTERVAL=10000; //10 secs
var GRAPH_AUTOREFRESH_INTERVAL=100000; //100 secs
var graph1 = {
title : "graph1",
@ -64,8 +64,8 @@ var dashboard_tab_content =
<td class="value_td"><span id="total_hosts"></span><span id="active_hosts" class="green"></span></td>\
</tr>\
<tr>\
<td class="key_td">Clusters</td>\
<td class="value_td"><span id="total_clusters"></span></td>\
<td class="key_td">Groups</td>\
<td class="value_td"><span id="total_groups"></span></td>\
</tr>\
<tr>\
<td class="key_td">VM Templates (total/public)</td>\
@ -101,7 +101,7 @@ var dashboard_tab_content =
<table style="width:100%;"><tr style="vertical-align:middle;"><td style="width:70%">\
<label style="font-weight:bold;width:40px;height:7em;">New:</label>\
<input type="radio" name="quickstart" value="Host.create_dialog">Host</input><br />\
<input type="radio" name="quickstart" value="Cluster.create_dialog">Cluster</input><br />\
<input type="radio" name="quickstart" value="Group.create_dialog">Group</input><br />\
<input type="radio" name="quickstart" value="Template.create_dialog">VM Template</input><br />\
<input type="radio" name="quickstart" value="VM.create_dialog">VM Instance</input><br />\
<input type="radio" name="quickstart" value="Image.create_dialog">Image</input><br />\
@ -184,10 +184,13 @@ function plot_global_graph(data,info){
};
var options = {
legend : { show : true,
legend : {
show : true,
noColumns: labels_arr.length,
container: $('#'+id+'_legend')},
xaxis : { mode: "time",
container: $('#'+id+'_legend')
},
xaxis : {
mode: "time",
timeformat: "%h:%M"
},
yaxis : { labelWidth: 40 }
@ -196,10 +199,10 @@ function plot_global_graph(data,info){
switch (id){
case "graph3":
case "graph5":
options["yaxis"]["tickFormatter"] = function(val,axis) { return humanize_size(val); }
options["yaxis"]["tickFormatter"] = function(val,axis) {
return humanize_size(val);
}
}
$.plot($('#'+id+'_graph'),series,options);
}
@ -273,9 +276,9 @@ function updateDashboard(what,json_info){
$('#total_hosts',db).html(total_hosts+'&nbsp;/&nbsp;');
$('#active_hosts',db).html(active_hosts);
break;
case "clusters":
var total_clusters=json_info.length;
$('#total_clusters',db).html(total_clusters);
case "groups":
var total_groups=json_info.length;
$('#total_groups',db).html(total_groups);
break;
case "vms":
var total_vms=json_info.length;

View File

@ -0,0 +1,276 @@
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2011, 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. */
/* -------------------------------------------------------------------------- */
var group_select="";
var group_list_json = {};
var dataTable_groups;
var groups_tab_content =
'<form id="group_form" action="" action="javascript:alert(\'js error!\');">\
<div class="action_blocks">\
</div>\
<table id="datatable_groups" class="display">\
<thead>\
<tr>\
<th class="check"><input type="checkbox" class="check_all" value="">All</input></th>\
<th>ID</th>\
<th>Owner</th>\
<th>Name</th>\
</tr>\
</thead>\
<tbody id="tbodygroups">\
</tbody>\
</table>\
</form>';
var create_group_tmpl =
'<form id="create_group_form" action="">\
<fieldset style="border:none;">\
<div>\
<label for="name">Group name:</label>\
<input type="text" name="name" id="name" /><br />\
</div>\
</fieldset>\
<fieldset>\
<div class="form_buttons">\
<button class="button" id="create_group_submit" value="Group.create">Create</button>\
<button class="button" type="reset" value="reset">Reset</button>\
</div>\
</fieldset>\
</form>';
var group_actions = {
"Group.create" : {
type: "create",
call : OpenNebula.Group.create,
callback : addGroupElement,
error : onError,
notify: true
},
"Group.create_dialog" : {
type: "custom",
call: popUpCreateGroupDialog
},
"Group.list" : {
type: "list",
call: OpenNebula.Group.list,
callback: updateGroupsView,
error: onError,
},
// "Group.showinfo" : {
// type: "custom",
// call: updateGroupInfo
// },
"Group.autorefresh" : {
type: "custom",
call: function () {
OpenNebula.Group.list({timeout: true, success: updateGroupsView,error: onError});
}
},
"Group.refresh" : {
type: "custom",
call: function() {
waitingNodes(dataTable_groups);
Sunstone.runAction("Group.list");
},
callback: function(){},
error: onError,
notify: false
},
"Group.delete" : {
type: "multiple",
call : OpenNebula.Group.delete,
callback : deleteGroupElement,
error : onError,
elements: function() { return getSelectedNodes(dataTable_groups); },
notify:true
},
"Group.chown" : {
type: "multiple",
call : OpenNebula.Group.chown,
callback : updateGroupElement,
elements: function() { return getSelectedNodes(dataTable_groups); },
error : onError,
notify:true
},
}
var group_buttons = {
"Group.refresh" : {
type: "image",
text: "Refresh list",
img: "/images/Refresh-icon.png",
condition: True
},
"Group.create_dialog" : {
type: "create_dialog",
text: "+ New Group",
condition : True
},
"Group.chown" : {
type: "confirm_with_select",
text: "Change group owner",
select: function(){return users_select},
tip: "Select the new group owner:",
condition : True
},
"Group.delete" : {
type: "action",
text: "Delete",
condition : True
}
};
var groups_tab = {
title: 'Groups',
content: groups_tab_content,
buttons: group_buttons,
condition: True
}
Sunstone.addActions(group_actions);
Sunstone.addMainTab('groups_tab',groups_tab);
function groupElementArray(group_json){
var group = group_json.GROUP;
return [
'<input type="checkbox" id="group_'+group.ID+'" name="selected_items" value="'+group.ID+'"/>',
group.ID,
getUserName(group.UID),
group.NAME ];
}
function groupInfoListener(){
$('#tbodygroups tr').live("click",function(e){
//do nothing if we are clicking a checkbox!
if ($(e.target).is('input')) {return true;}
var aData = dataTable_groups.fnGetData(this);
var id = $(aData[0]).val();
Sunstone.runAction("Group.showinfo",id);
return false;
});
}
function updateGroupSelect(){
groups_select = makeSelectOptions(dataTable_groups,1,3,-1,"",-1);
}
function updateGroupElement(request, group_json){
var id = group_json.GROUP.ID;
var element = groupElementArray(group_json);
updateSingleElement(element,dataTable_groups,'#group_'+id);
//No need to update select as all items are in it always
}
function deleteGroupElement(request){
deleteElement(dataTable_groups,'#group_'+req.request.data);
updateGroupSelect();
}
function addGroupElement(request,group_json){
var id = group_json.GROUP.ID;
var element = groupElementArray(group_json);
addElement(element,dataTable_groups);
updateGroupSelect();
}
//updates the list
function updateGroupsView(request, group_list){
group_list_json = group_list;
var group_list_array = [];
$.each(group_list,function(){
group_list_array.push(groupElementArray(this));
});
updateView(group_list_array,dataTable_groups);
updateGroupSelect(group_list);
updateDashboard("groups",group_list);
}
//Prepares the dialog to create
function setupCreateGroupDialog(){
$('div#dialogs').append('<div title="Create group" id="create_group_dialog"></div>');
$('#create_group_dialog').html(create_group_tmpl);
$('#create_group_dialog').dialog({
autoOpen: false,
modal: true,
width: 400
});
$('#create_group_dialog button').button();
$('#create_group_form').submit(function(){
var name=$('#name',this).val();
var group_json = { "group" : { "name" : name }};
Sunstone.runAction("Group.create",group_json);
$('#create_group_dialog').dialog('close');
return false;
});
}
function popUpCreateGroupDialog(){
$('#create_group_dialog').dialog('open');
return false;
}
//Prepares the autorefresh
function setGroupAutorefresh(){
setInterval(function(){
var checked = $('input:checked',dataTable_groups.fnGetNodes());
var filter = $("#datatable_groups_filter input").attr("value");
if (!checked.length && !filter.length){
Sunstone.runAction("Group.autorefresh");
}
},INTERVAL+someTime());
}
$(document).ready(function(){
dataTable_groups = $("#datatable_groups").dataTable({
"bJQueryUI": true,
"bSortClasses": false,
"sPaginationType": "full_numbers",
"bAutoWidth":false,
"aoColumnDefs": [
{ "bSortable": false, "aTargets": ["check"] },
{ "sWidth": "60px", "aTargets": [0] },
{ "sWidth": "35px", "aTargets": [1] }
]
});
dataTable_groups.fnClearTable();
addElement([
spinner,
'','',''],dataTable_groups);
Sunstone.runAction("Group.list");
setupCreateGroupDialog();
setGroupAutorefresh();
initCheckAllBoxes(dataTable_groups);
tableCheckboxesListener(dataTable_groups);
})

View File

@ -33,7 +33,6 @@ var host_graphs = [
]
var hosts_tab_content =
'<form id="form_hosts" action="javascript:alert(\'js errors?!\')">\
<div class="action_blocks">\
@ -44,7 +43,6 @@ var hosts_tab_content =
<th class="check"><input type="checkbox" class="check_all" value="">All</input></th>\
<th>ID</th>\
<th>Name</th>\
<th>Cluster</th>\
<th>Running VMs</th>\
<th>CPU Use</th>\
<th>Memory use</th>\
@ -99,26 +97,8 @@ var create_host_tmpl =
</fieldset>\
</form></div>';
var create_cluster_tmpl =
'<form id="create_cluster_form" action="">\
<fieldset style="border:none;">\
<div>\
<label for="name">Cluster name:</label>\
<input type="text" name="name" id="name" /><br />\
</div>\
</fieldset>\
<fieldset>\
<div class="form_buttons">\
<button class="button" id="create_cluster_submit" value="cluster/create">Create</button>\
<button class="button" type="reset" value="reset">Reset</button>\
</div>\
</fieldset>\
</form>';
var hosts_select="";
var clusters_select="";
var host_list_json = {};
var cluster_list_json = {};
var dataTable_hosts;
//Setup actions
@ -137,14 +117,13 @@ var host_actions = {
call: popUpCreateHostDialog
},
//Custom below
//~ "Host.list" : {
//~ type: "list",
//~ call: OpenNebula.Host.list,
//~ callback: updateHostsView,
//~ error: onError,
//~ notify:False
//~ },
"Host.list" : {
type: "list",
call: OpenNebula.Host.list,
callback: updateHostsView,
error: onError,
notify: false
},
"Host.show" : {
type: "single",
@ -209,14 +188,6 @@ var host_actions = {
notify:true
},
"Host.list" : {
type: "custom",
call : function() {
OpenNebula.Host.list({success: updateHostsView, error: onError});
OpenNebula.Cluster.list({success: updateClustersView, error: onError});
}
},
"Host.monitor" : {
type: "monitor",
call : OpenNebula.Host.monitor,
@ -236,66 +207,6 @@ var host_actions = {
plot_global_graph(response,info);
},
error: onError
},
"Cluster.create" : {
type: "create",
call : OpenNebula.Cluster.create,
callback : function(){
Sunstone.runAction("Cluster.list");
},
error : onError,
notify: true
},
"Cluster.create_dialog" : {
type: "custom",
call: popUpCreateClusterDialog
},
"Cluster.list" : {
type: "list",
call: OpenNebula.Cluster.list,
callback: updateClustersView,
error: onError,
},
"Cluster.autorefresh" : {
type: "custom",
call: function () {
OpenNebula.Cluster.list({timeout: true, success: updateClustersView,error: onError});
}
},
"Cluster.delete" : {
type: "single",
call : OpenNebula.Cluster.delete,
callback : function(){
//OpenNebula.Cluster.list({success: updateClustersView, error: onError});
Sunstone.runAction("Cluster.list");
},
error : onError,
notify:true
},
"Cluster.addhost" : {
type: "multiple",
call : OpenNebula.Cluster.addhost,
callback : function(req){
Sunstone.runAction("Host.show",req.request.data);
},
elements: function() { return getSelectedNodes(dataTable_hosts); },
error : onError,
notify:true
},
"Cluster.removehost" : {
type: "multiple",
call : OpenNebula.Cluster.removehost,
callback : deleteHostElement,
elements: function() { return getSelectedNodes(dataTable_hosts); },
error : onError,
notify:true
}
};
@ -321,35 +232,6 @@ var host_buttons = {
text: "Disable",
condition : True
},
"Cluster.create_dialog" : {
type: "create_dialog",
text: "+ New Cluster",
condition : True
},
"Cluster.delete" : {
type: "confirm_with_select",
text: "Delete cluster",
select: function(){return clusters_select},
tip: "Select the cluster you want to remove",
condition : True
},
"action_list" : { //Special button
type: "select",
actions: { "Cluster.addhost": {
type: "confirm_with_select",
text: "Add host to cluster",
select: function(){return clusters_select;},
tip: "Select the cluster in which you would like to place the hosts",
condition: True
},
"Cluster.removehost" : {
type: "action",
text: "Remove host from cluster",
condition: True
}},
condition : True
},
"Host.delete" : {
type: "action",
text: "Delete host",
@ -375,7 +257,7 @@ var host_info_panel = {
var hosts_tab = {
title: 'Hosts &amp; Clusters',
title: 'Hosts',
content: hosts_tab_content,
buttons: host_buttons,
condition: True
@ -386,7 +268,6 @@ Sunstone.addMainTab('hosts_tab',hosts_tab);
Sunstone.addInfoPanel("host_info_panel",host_info_panel);
//Creates an array to be added to the dataTable from the JSON of a host.
function hostElementArray(host_json){
@ -431,15 +312,14 @@ function hostElementArray(host_json){
</div>';
return [ '<input type="checkbox" id="host_'+host.ID+'" name="selected_items" value="'+host.ID+'"/>',
return [
'<input type="checkbox" id="host_'+host.ID+'" name="selected_items" value="'+host.ID+'"/>',
host.ID,
host.NAME,
host.CLUSTER,
host.HOST_SHARE.RUNNING_VMS, //rvm
pb_cpu,
pb_mem,
OpenNebula.Helper.resource_state("host_simple",host.STATE) ];
}
//Listen to clicks on the tds of the tables and shows the info dialogs.
@ -458,19 +338,7 @@ function hostInfoListener(){
//updates the host select by refreshing the options in it
function updateHostSelect(){
hosts_select = makeSelectOptions(dataTable_hosts,1,2,7,"DISABLED",-1);
}
//updates the cluster select by refreshing the options in it
function updateClusterSelect(cluster_list){
//manual, as there is not dataTable for it
clusters_select="<option value=\"\">Select a cluster</option>";
$.each(cluster_list, function(){
clusters_select += "<option value=\""+this.CLUSTER.ID+"\">"+this.CLUSTER.NAME+"</option>";
});
}
//callback for an action affecting a host element
@ -498,7 +366,7 @@ function addHostElement(request,host_json){
//callback to update the list of hosts.
function updateHostsView (request,host_list){
host_list_json = host_list;
var host_list_array = []
var host_list_array = [];
$.each(host_list,function(){
//Grab table data from the host_list
@ -511,13 +379,6 @@ function updateHostsView (request,host_list){
updateDashboard("hosts",host_list_json);
}
//updates the list of clusters
function updateClustersView(request, cluster_list){
cluster_list_json = cluster_list;
updateClusterSelect(cluster_list);
updateDashboard("clusters",cluster_list);
}
//Updates the host info panel tab's content and pops it up
function updateHostInfo(request,host){
var host_info = host.HOST;
@ -530,6 +391,7 @@ function updateHostInfo(request,host){
<thead>\
<tr><th colspan="2">Host information - '+host_info.NAME+'</th></tr>\
</thead>\
<tbody>\
<tr>\
<td class="key_td">ID</td>\
<td class="value_td">'+host_info.ID+'</td>\
@ -538,10 +400,6 @@ function updateHostInfo(request,host){
<td class="key_td">State</td>\
<td class="value_td">'+OpenNebula.Helper.resource_state("host",host_info.STATE)+'</td>\
</tr>\
<tr>\
<td class="key_td">Cluster</td>\
<td class="value_td">'+host_info.CLUSTER+'</td>\
</tr>\
<tr>\
<td class="key_td">IM MAD</td>\
<td class="value_td">'+host_info.IM_MAD+'</td>\
@ -554,11 +412,13 @@ function updateHostInfo(request,host){
<td class="key_td">TM MAD</td>\
<td class="value_td">'+host_info.TM_MAD+'</td>\
</tr>\
</tbody>\
</table>\
<table id="host_shares_table" class="info_table">\
<thead>\
<tr><th colspan="2">Host shares</th></tr>\
</thead>\
<tbody>\
<tr>\
<td class="key_td">Max Mem</td>\
<td class="value_td">'+humanize_size(host_info.HOST_SHARE.MAX_MEM)+'</td>\
@ -583,6 +443,7 @@ function updateHostInfo(request,host){
<td class="key_td">Running VMs</td>\
<td class="value_td">'+host_info.HOST_SHARE.RUNNING_VMS+'</td>\
</tr>\
</tbody>\
</table>'
}
@ -633,56 +494,29 @@ function setupCreateHostDialog(){
notifyError("Host name missing!");
return false;
}
var host_json = { "host": { "name": $('#name',this).val(),
var host_json = {
"host": {
"name": $('#name',this).val(),
"tm_mad": $('#tm_mad :selected',this).val(),
"vm_mad": $('#vmm_mad :selected',this).val(),
"im_mad": $('#im_mad :selected',this).val()}}
"im_mad": $('#im_mad :selected',this).val()
}
}
//Create the OpenNebula.Host.
//If it's successfull we refresh the list.
Sunstone.runAction("Host.create",host_json);
//OpenNebula.Host.create({data: host_json, success: addHostElement, error: onError});
$('#create_host_dialog').dialog('close');
return false;
});
}
//Prepares the dialog to create a cluster
function setupCreateClusterDialog(){
$('div#dialogs').append('<div title="Create cluster" id="create_cluster_dialog"></div>');
$('#create_cluster_dialog').html(create_cluster_tmpl);
$('#create_cluster_dialog').dialog({
autoOpen: false,
modal: true,
width: 400
});
$('#create_cluster_dialog button').button();
$('#create_cluster_form').submit(function(){
var name=$('#name',this).val();
var cluster_json = { "cluster" : { "name" : name }};
Sunstone.runAction("Cluster.create",cluster_json);
$('#create_cluster_dialog').dialog('close');
return false;
});
}
//Open creation dialogs
function popUpCreateHostDialog(){
$('#create_host_dialog').dialog('open');
return false;
}
function popUpCreateClusterDialog(){
$('#create_cluster_dialog').dialog('open');
return false;
}
//Prepares the autorefresh for hosts
function setHostAutorefresh() {
setInterval(function(){
@ -694,13 +528,6 @@ function setHostAutorefresh() {
},INTERVAL+someTime());
}
//Prepares the autorefresh for clusters
function setClusterAutorefresh(){
setInterval(function(){
Sunstone.runAction("Cluster.autorefresh");
},INTERVAL+someTime());
}
//This is executed after the sunstone.js ready() is run.
//Here we can basicly init the host datatable, preload it
//and add specific listeners
@ -714,9 +541,9 @@ $(document).ready(function(){
"sPaginationType": "full_numbers",
"aoColumnDefs": [
{ "bSortable": false, "aTargets": ["check"] },
{ "sWidth": "60px", "aTargets": [0,4] },
{ "sWidth": "60px", "aTargets": [0,3] },
{ "sWidth": "35px", "aTargets": [1] },
{ "sWidth": "200px", "aTargets": [5,6] }
{ "sWidth": "200px", "aTargets": [4,5] }
]
});
@ -724,18 +551,14 @@ $(document).ready(function(){
dataTable_hosts.fnClearTable();
addElement([
spinner,
'','','','','','',''],dataTable_hosts);
'','','','','',''],dataTable_hosts);
Sunstone.runAction("Host.list");
Sunstone.runAction("Cluster.list");
setupCreateHostDialog();
setupCreateClusterDialog();
setHostAutorefresh();
setClusterAutorefresh();
initCheckAllBoxes(dataTable_hosts);
tableCheckboxesListener(dataTable_hosts);
hostInfoListener();
});

View File

@ -25,7 +25,8 @@ var images_tab_content =
<tr>\
<th class="check"><input type="checkbox" class="check_all" value="">All</input></th>\
<th>ID</th>\
<th>User</th>\
<th>Owner</th>\
<th>Group</th>\
<th>Name</th>\
<th>Type</th>\
<th>Registration time</th>\
@ -209,65 +210,29 @@ var image_actions = {
}
},
"Image.addattr" : {
type: "multiple",
call: function(obj){
var id_attr = obj.data.id;
var name = $('#img_attr_name').val();
var value = $('#img_attr_value').val();
OpenNebula.Image.addattr(
{data: {
id: id_attr,
name: name,
value: value
"Image.fetch_template" : {
type: "single",
call: OpenNebula.Image.fetch_template,
callback: function (request,response) {
$('#template_update_dialog #template_update_textarea').val(response.template);
},
success: obj.success,
error: obj.error
});
},
callback : function (req) {
Sunstone.runAction("Image.show",req.request.data[0]);
},
elements: function() { return getSelectedNodes(dataTable_images); },
error: onError,
notify: true
notify: false
},
"Image.addattr_dialog" : {
"Image.update_dialog" : {
type: "custom",
call: popUpImageAddattrDialog
call: popUpImageTemplateUpdateDialog
},
"Image.updateattr_dialog" : {
type: "custom",
call: popUpImageAddattrDialog
"Image.update" : {
type: "single",
call: OpenNebula.Image.update,
callback: function() {
notifyMessage("Template updated correctly");
},
"Image.rmattr" : {
type: "multiple",
call: function(obj){
var id_attr = obj.data.id;
var name = $('#img_attr_name').val();
OpenNebula.Image.rmattr(
{data: {
id: id_attr,
name: name
},
success: obj.success,
error: obj.error
});
},
callback: function (req) {
Sunstone.runAction("Image.show",req.request.data[0]);
},
elements: function() { return getSelectedNodes(dataTable_images); },
error: onError,
notify: true
},
"Image.rmattr_dialog" : {
type: "custom",
call: popUpImageRmattrDialog,
notify: false
},
"Image.enable" : {
@ -343,6 +308,28 @@ var image_actions = {
elements: function() { return getSelectedNodes(dataTable_images); },
error: onError,
notify: true
},
"Image.chown" : {
type: "multiple",
call: OpenNebula.Image.chown,
callback: function (req) {
Sunstone.runAction("Image.show",req.request.data[0]);
},
elements: function() { return getSelectedNodes(dataTable_images); },
error: onError,
notify: true
},
"Image.chgrp" : {
type: "multiple",
call: OpenNebula.Image.chgrp,
callback: function (req) {
Sunstone.runAction("Image.show",req.request.data[0]);
},
elements: function() { return getSelectedNodes(dataTable_images); },
error: onError,
notify: true
}
}
@ -359,19 +346,24 @@ var image_buttons = {
text: "+ New",
condition: True
},
"Image.addattr_dialog" : {
"Image.update_dialog" : {
type: "action",
text: "Add attribute",
text: "Update a template",
condition: True,
alwaysActive: true
},
"Image.chown" : {
type: "confirm_with_select",
text: "Change owner",
select: function() {return users_select;},
tip: "Select the new owner:",
condition: True
},
"Image.updateattr_dialog" : {
type: "action",
text: "Update attribute",
condition: True
},
"Image.rmattr_dialog" : {
type: "action",
text: "Remove attribute",
"Image.chgrp" : {
type: "confirm_with_select",
text: "Change group",
select: function() {return groups_select;},
tip: "Select the new group:",
condition: True
},
"action_list" : {
@ -448,7 +440,8 @@ function imageElementArray(image_json){
return [
'<input type="checkbox" id="image_'+image.ID+'" name="selected_items" value="'+image.ID+'"/>',
image.ID,
image.USERNAME ? image.USERNAME : getUserName(image.UID),
getUserName(image.UID),
getGroupName(image.GID),
image.NAME,
OpenNebula.Helper.image_type(image.TYPE),
pretty_time(image.REGTIME),
@ -475,7 +468,7 @@ function imageInfoListener(){
//Updates the select input field with an option for each image
function updateImageSelect(){
images_select =
makeSelectOptions(dataTable_images,1,3,8,"DISABLED",2);
makeSelectOptions(dataTable_images,1,4,9,"DISABLED",2);
//update static selectors:
//in the VM section
@ -517,84 +510,14 @@ function updateImagesView(request, images_list){
}
// Prepare the dialog to add/remove/update image attributes
function setupImageAttributesDialogs(){
//Append to DOM
$('div#dialogs').append('<div id="image_attributes_dialog" title="Image attributes"></div>');
//Put HTML in place
$('#image_attributes_dialog').html(
'<form action="javascript:alert(\'js error!\');">\
<fieldset>\
<div id="img_attr_action_desc">\
</div>\
<div>\
<label for="img_attr_name">Name:</label>\
<input type="text" id="img_attr_name" name="img_attr_name" value="" />\
</div>\
<div>\
<label for="img_attr_value">Value:</label>\
<input type="text" id="img_attr_value" name="img_attr_value" value="" />\
</div>\
<div class="form_buttons">\
<button class="action_button" id="img_attr_proceed" value="">OK</button>\
<button id="img_attr_cancel" value="">Cancel</button>\
</div>\
</fieldset>\
</form>');
$('#image_attributes_dialog').dialog({
autoOpen:false,
width:400,
modal:true,
height:220,
resizable:false,
});
$('#image_attributes_dialog button').button();
//Upcase variable names
$('#img_attr_name').keyup(function(){
$(this).val($(this).val().toUpperCase());
});
$('#image_attributes_dialog #img_attr_proceed').click(function(){
$('#image_attributes_dialog').dialog('close');
});
$('#image_attributes_dialog #img_attr_cancel').click(function(){
$('#image_attributes_dialog').dialog('close');
return false;
});
}
// Popup a dialog to add/update an attribute
function popUpImageAddattrDialog(){
//Show value field and label
$('#img_attr_value').show();
$('#img_attr_value').prev().show();
var desc = "Please write the name and value of the attribute. It will be added or updated in all selected images:";
$('#img_attr_proceed').val("Image.addattr");
$('#img_attr_action_desc').html(desc);
$('#image_attributes_dialog').dialog('open');
function popUpImageTemplateUpdateDialog(){
$('#template_update_dialog #template_update_button').val("Image");
$('#template_update_dialog #template_update_select').html(images_select);
$('#template_update_dialog #template_update_textarea').val("");
$('#template_update_dialog').dialog('open');
return false;
}
// Popup a dialog to remove an attribute
function popUpImageRmattrDialog(){
//Hide value field and label
$('#img_attr_value').hide();
$('#img_attr_value').prev().hide();
var desc = "Please type the attribute you want to remove:";
$('#img_attr_proceed').val("Image.rmattr");
$('#img_attr_action_desc').html(desc);
$('#image_attributes_dialog').dialog('open');
return false;
}
// Callback to update the information panel tabs and pop it up
function updateImageInfo(request,img){
@ -830,23 +753,21 @@ $(document).ready(function(){
{ "bSortable": false, "aTargets": ["check"] },
{ "sWidth": "60px", "aTargets": [0,3] },
{ "sWidth": "35px", "aTargets": [1] },
{ "sWidth": "100px", "aTargets": [2,3] }
{ "sWidth": "100px", "aTargets": [2,3,4] }
]
});
dataTable_images.fnClearTable();
addElement([
spinner,
'','','','','','','','',''],dataTable_images);
'','','','','','','','','',''],dataTable_images);
Sunstone.runAction("Image.list");
setupCreateImageDialog();
setupImageAttributesDialogs();
setupTips($('#create_image_dialog'));
setImageAutorefresh();
initCheckAllBoxes(dataTable_images);
tableCheckboxesListener(dataTable_images);
imageInfoListener();
})

View File

@ -25,7 +25,8 @@ var templates_tab_content =
<tr>\
<th class="check"><input type="checkbox" class="check_all" value="">All</input></th>\
<th>ID</th>\
<th>User</th>\
<th>Owner</th>\
<th>Group</th>\
<th>Name</th>\
<th>Registration time</th>\
<th>Public</th>\
@ -587,65 +588,29 @@ var template_actions = {
}
},
"Template.addattr" : {
type: "multiple",
call: function(obj){
var id_attr = obj.data.id;
var name = $('#template_attr_name').val();
var value = $('#template_attr_value').val();
OpenNebula.Template.addattr(
{data: {
id: id_attr,
name: name,
value: value
"Template.update_dialog" : {
type: "custom",
call: popUpTemplateTemplateUpdateDialog
},
success: obj.success,
error: obj.error
});
"Template.update" : {
type: "single",
call: OpenNebula.Template.update,
callback: function() {
notifyMessage("Template updated correctly");
},
callback : function (req) {
Sunstone.runAction("Template.show",req.request.data[0]);
},
elements: function() { return getSelectedNodes(dataTable_templates); },
error: onError,
notify: true
notify: false
},
"Template.addattr_dialog" : {
type: "custom",
call: popUpTemplateAddattrDialog
"Template.fetch_template" : {
type: "single",
call: OpenNebula.Template.fetch_template,
callback: function (request,response) {
$('#template_update_dialog #template_update_textarea').val(response.template);
},
"Template.updateattr_dialog" : {
type: "custom",
call: popUpTemplateAddattrDialog
},
"Template.rmattr" : {
type: "multiple",
call: function(obj){
var id_attr = obj.data.id;
var name = $('#template_attr_name').val();
OpenNebula.Template.rmattr(
{data: {
id: id_attr,
name: name
},
success: obj.success,
error: obj.error
});
},
callback: function (req) {
Sunstone.runAction("Template.show",req.request.data[0]);
},
elements: function() { return getSelectedNodes(dataTable_templates); },
error: onError,
notify: true
},
"Template.rmattr_dialog" : {
type: "custom",
call: popUpTemplateRmattrDialog,
notify: false
},
"Template.publish" : {
@ -692,6 +657,26 @@ var template_actions = {
});
},
notify: false
},
"Template.chown" : {
type: "multiple",
call: OpenNebula.Template.chown,
callback: function (req) {
Sunstone.runAction("Template.show",req.request.data[0]);
},
elements: function() { return getSelectedNodes(dataTable_templates); },
error:onError,
notify: true
},
"Template.chgrp" : {
type: "multiple",
call: OpenNebula.Template.chgrp,
callback: function (req) {
Sunstone.runAction("Template.show",req.request.data[0]);
},
elements: function() { return getSelectedNodes(dataTable_templates); },
error:onError,
notify: true
}
}
@ -708,24 +693,29 @@ var template_buttons = {
text: "+ New",
condition: True
},
"Template.update_dialog" : {
type: "action",
text: "Update a template",
condition: True,
alwaysActive: true
},
"Template.instantiate" : {
type: "action",
text: "Instantiate",
condition: True
},
"Template.addattr_dialog" : {
type: "action",
text: "Add attribute",
"Template.chown" : {
type: "confirm_with_select",
text: "Change owner",
select: function() {return users_select;},
tip: "Select the new owner:",
condition: True
},
"Template.updateattr_dialog" : {
type: "action",
text: "Update attribute",
condition: True
},
"Template.rmattr_dialog" : {
type: "action",
text: "Remove attribute",
"Template.chgrp" : {
type: "confirm_with_select",
text: "Change group",
select: function() {return groups_select;},
tip: "Select the new group:",
condition: True
},
"action_list" : {
@ -776,7 +766,8 @@ function templateElementArray(template_json){
return [
'<input type="checkbox" id="template_'+template.ID+'" name="selected_items" value="'+template.ID+'"/>',
template.ID,
template.USERNAME ? template.USERNAME : getUserName(template.UID),
getUserName(template.UID),
getGroupName(template.GID),
template.NAME,
pretty_time(template.REGTIME),
parseInt(template.PUBLIC) ? "yes" : "no"
@ -799,7 +790,7 @@ function templateInfoListener(){
//Updates the select input field with an option for each template
function updateTemplateSelect(){
templates_select =
makeSelectOptions(dataTable_templates,1,3,5,"no",2);
makeSelectOptions(dataTable_templates,1,4,7,"no",2);
//update static selectors:
$('#create_vm_dialog #template_id').html(templates_select);
@ -841,82 +832,12 @@ function updateTemplatesView(request, templates_list){
}
// Prepare the dialog to add/remove/update template attributes
function setupTemplateAttributesDialogs(){
//Append to DOM
$('div#dialogs').append('<div id="template_attributes_dialog" title="Template attributes"></div>');
//Put HTML in place
$('#template_attributes_dialog').html(
'<form action="javascript:alert(\'js error!\');">\
<fieldset>\
<div id="template_attr_action_desc">\
</div>\
<div>\
<label for="template_attr_name">Name:</label>\
<input type="text" id="template_attr_name" name="template_attr_name" value="" />\
</div>\
<div>\
<label for="template_attr_value">Value:</label>\
<input type="text" id="template_attr_value" name="template_attr_value" value="" />\
</div>\
<div class="form_buttons">\
<button class="action_button" id="template_attr_proceed" value="">OK</button>\
<button id="template_attr_cancel" value="">Cancel</button>\
</div>\
</fieldset>\
</form>');
$('#template_attributes_dialog').dialog({
autoOpen:false,
width:400,
modal:true,
height:220,
resizable:false,
});
$('#template_attributes_dialog button').button();
//Upcase variable names
$('#template_attr_name').keyup(function(){
$(this).val($(this).val().toUpperCase());
});
$('#template_attributes_dialog #template_attr_proceed').click(function(){
$('#template_attributes_dialog').dialog('close');
});
$('#template_attributes_dialog #template_attr_cancel').click(function(){
$('#template_attributes_dialog').dialog('close');
return false;
});
}
// Popup a dialog to add/update an attribute
function popUpTemplateAddattrDialog(){
//Show value field and label
$('#template_attr_value').show();
$('#template_attr_value').prev().show();
var desc = "Please write the name and value of the attribute. It will be added or updated in all selected templates:";
$('#template_attr_proceed').val("Template.addattr");
$('#template_attr_action_desc').html(desc);
$('#template_attributes_dialog').dialog('open');
return false;
}
// Popup a dialog to remove an attribute
function popUpTemplateRmattrDialog(){
//Hide value field and label
$('#template_attr_value').hide();
$('#template_attr_value').prev().hide();
var desc = "Please type the attribute you want to remove:";
$('#template_attr_proceed').val("Template.rmattr");
$('#template_attr_action_desc').html(desc);
$('#template_attributes_dialog').dialog('open');
function popUpTemplateTemplateUpdateDialog(){
$('#template_update_dialog #template_update_button').val("Template");
$('#template_update_dialog #template_update_select').html(templates_select);
$('#template_update_dialog #template_update_textarea').val("");
$('#template_update_dialog').dialog('open');
return false;
}
@ -925,7 +846,8 @@ function updateTemplateInfo(request,template){
var template_info = template.VMTEMPLATE;
var info_tab = {
title: "Information",
content: '<table id="info_template_table" class="info_table">\
content:
'<table id="info_template_table" class="info_table">\
<thead>\
<tr><th colspan="2">Template "'+template_info.NAME+'" information</th></tr>\
</thead>\
@ -1118,8 +1040,6 @@ function setupCreateTemplateDialog(){
$(section_inputs).hide(); //not present for xen
$(section_graphics).show();
};
var enable_vmware = function() {
@ -1216,7 +1136,8 @@ function setupCreateTemplateDialog(){
}
});
var value_string = JSON.stringify(value);
var option= '<option value=\''+value_string+'\'>'+
var option=
'<option value=\''+value_string+'\'>'+
stringJSON(value)+
'</option>';
$('select'+box_tag,context).append(option);
@ -1326,7 +1247,6 @@ function setupCreateTemplateDialog(){
return false;
});
//Chrome workaround
$('#boot_method').change(function(){
$(this).trigger("click");
@ -1934,8 +1854,6 @@ function setupCreateTemplateDialog(){
return true;
});
}
function popUpCreateTemplateDialog(){
@ -1963,20 +1881,19 @@ $(document).ready(function(){
"sPaginationType": "full_numbers",
"aoColumnDefs": [
{ "bSortable": false, "aTargets": ["check"] },
{ "sWidth": "60px", "aTargets": [0,3] },
{ "sWidth": "60px", "aTargets": [0] },
{ "sWidth": "35px", "aTargets": [1] },
{ "sWidth": "100px", "aTargets": [2,3] }
{ "sWidth": "100px", "aTargets": [2,3,4] }
]
});
dataTable_templates.fnClearTable();
addElement([
spinner,
'','','','',''],dataTable_templates);
'','','','','',''],dataTable_templates);
Sunstone.runAction("Template.list");
setupCreateTemplateDialog();
setupTemplateAttributesDialogs();
setTemplateAutorefresh();
initCheckAllBoxes(dataTable_templates);

View File

@ -15,6 +15,9 @@
/* -------------------------------------------------------------------------- */
/*Users tab plugin*/
var user_list_json = {};
var dataTable_users;
var users_select="";
var users_tab_content =
'<form id="user_form" action="" action="javascript:alert(\'js error!\');">\
@ -26,6 +29,7 @@ var users_tab_content =
<th class="check"><input type="checkbox" class="check_all" value="">All</input></th>\
<th>ID</th>\
<th>Name</th>\
<th>Groups</th>\
</tr>\
</thead>\
<tbody id="tbodyusers">\
@ -51,9 +55,6 @@ var create_user_tmpl =
</fieldset>\
</form>';
var user_list_json = {};
var dataTable_users;
var user_actions = {
"User.create" : {
type: "create",
@ -86,7 +87,11 @@ var user_actions = {
"User.autorefresh" : {
type: "custom",
call: function(){
OpenNebula.User.list({timeout: true, success: updateUsersView, error: onError});
OpenNebula.User.list({
timeout: true,
success: updateUsersView,
error: onError
});
},
condition: function(){ uid == 0 },
notify: false
@ -141,14 +146,46 @@ function userElementArray(user_json){
name = user.NAME;
}
var i = 1;
var groups_str=getGroupName(user.GID)+", ";
var groups_full_str=getGroupName(user.GID)+", ";
var group_field;
if (user.GROUPS.ID){
$.each(user.GROUPS.ID,function() {
if (i<=5) {
groups_str+=getGroupName(this)+", ";
};
groups_full_str+=getGroupName(this)+", ";
i++;
});
if (i>0){
groups_str = groups_str.slice(0, -2);
groups_full_str = groups_str.slice(0, -2);
};
if (i>5){
groups_str+="...";
group_field = '<div class="shortened_info">'+groups_str+'</div><div class="full_info" style="display:none">'+groups_full_str+'</div>';
} else {
group_field=groups_str;
};
}
return [
'<input type="checkbox" id="user_'+user.ID+'" name="selected_items" value="'+user.ID+'"/>',
user.ID,
name
name,
group_field
]
}
function updateUserSelect(){
users_select = makeSelectOptions(dataTable_users,1,2,-1,"",-1);
}
// Callback to refresh a single element from the dataTable
function updateUserElement(request, user_json){
var id = user_json.USER.ID;
@ -159,12 +196,14 @@ function updateUserElement(request, user_json){
// Callback to delete a single element from the dataTable
function deleteUserElement(req){
deleteElement(dataTable_users,'#user_'+req.request.data);
updateUserSelect();
}
// Callback to add a single user element
function addUserElement(request,user_json){
var element = userElementArray(user_json);
addElement(element,dataTable_users);
updateUserSelect();
}
// Callback to update the list of users
@ -177,6 +216,7 @@ function updateUsersView(request,users_list){
});
updateView(user_list_array,dataTable_users);
updateDashboard("users",user_list_json);
updateUserSelect();
}
// Prepare the user creation dialog
@ -227,7 +267,6 @@ function setUserAutorefresh(){
}
$(document).ready(function(){
//if we are not oneadmin, our tab will not even be in the DOM.
if (uid==0) {
dataTable_users = $("#datatable_users").dataTable({
@ -244,7 +283,7 @@ $(document).ready(function(){
dataTable_users.fnClearTable();
addElement([
spinner,
'',''],dataTable_users);
'','',''],dataTable_users);
Sunstone.runAction("User.list");
@ -253,5 +292,6 @@ $(document).ready(function(){
initCheckAllBoxes(dataTable_users);
tableCheckboxesListener(dataTable_users);
shortenedInfoFields('#datatable_users');
}
})

View File

@ -56,7 +56,8 @@ var vms_tab_content =
<tr>\
<th class="check"><input type="checkbox" class="check_all" value="">All</input></th>\
<th>ID</th>\
<th>User</th>\
<th>Owner</th>\
<th>Group</th>\
<th>Name</th>\
<th>Status</th>\
<th>CPU</th>\
@ -373,6 +374,26 @@ var vm_actions = {
},
error: onError
},
"VM.chown" : {
type: "multiple",
call: OpenNebula.VM.chown,
callback: function (req) {
Sunstone.runAction("VM.show",req.request.data[0]);
},
elements: function() { return getSelectedNodes(dataTable_vMachines); },
error: onError,
notify: true
},
"VM.chgrp" : {
type: "multiple",
call: OpenNebula.VM.chgrp,
callback: function (req) {
Sunstone.runAction("VM.show",req.request.data[0]);
},
elements: function() { return getSelectedNodes(dataTable_vMachines); },
error: onError,
notify: true
}
}
@ -393,6 +414,22 @@ var vm_buttons = {
},
"VM.chown" : {
type: "confirm_with_select",
text: "Change owner",
select: function() {return users_select;},
tip: "Select the new owner:",
condition: True
},
"VM.chgrp" : {
type: "confirm_with_select",
text: "Change group",
select: function() {return groups_select;},
tip: "Select the new group:",
condition: True
},
"VM.shutdown" : {
type: "confirm",
text: "Shutdown",
@ -540,11 +577,11 @@ function vMachineElementArray(vm_json){
state = OpenNebula.Helper.resource_state("vm_lcm",vm.LCM_STATE);
}
return [
'<input type="checkbox" id="vm_'+vm.ID+'" name="selected_items" value="'+vm.ID+'"/>',
vm.ID,
vm.USERNAME ? vm.USERNAME : getUserName(vm.UID),
getUserName(vm.UID),
getGroupName(vm.GID),
vm.NAME,
state,
vm.CPU,
@ -552,7 +589,7 @@ function vMachineElementArray(vm_json){
vm.HISTORY ? vm.HISTORY.HOSTNAME : "--",
str_start_time(vm),
vncIcon(vm)
]
];
}
@ -608,10 +645,12 @@ function updateVMInfo(request,vm){
var vm_info = vm.VM;
var info_tab = {
title : "VM information",
content: '<table id="info_vm_table" class="info_table">\
content:
'<table id="info_vm_table" class="info_table">\
<thead>\
<tr><th colspan="2">Virtual Machine information - '+vm_info.NAME+'</th></tr>\
</thead>\
<tbody>\
<tr>\
<td class="key_td">ID</td>\
<td class="value_td">'+vm_info.ID+'</td>\
@ -635,12 +674,13 @@ function updateVMInfo(request,vm){
<tr>\
<td class="key_td">Deploy ID</td>\
<td class="value_td">'+(typeof(vm_info.DEPLOY_ID) == "object" ? "-" : vm_info.DEPLOY_ID)+'</td>\
</tr>\
</tr></tbody>\
</table>\
<table id="vm_monitoring_table" class="info_table">\
<thead>\
<tr><th colspan="2">Monitoring information</th></tr>\
</thead>\
<tbody>\
<tr>\
<td class="key_td">Net_TX</td>\
<td class="value_td">'+vm_info.NET_TX+'</td>\
@ -661,12 +701,14 @@ function updateVMInfo(request,vm){
<td class="key_td">VNC Session</td>\
<td class="value_td">'+vncIcon(vm_info)+'</td>\
</tr>\
</tbody>\
</table>'
}
var template_tab = {
title: "VM Template",
content: '<table id="vm_template_table" class="info_table">\
content:
'<table id="vm_template_table" class="info_table">\
<thead><tr><th colspan="2">VM template</th></tr></thead>'+
prettyPrintJSON(vm_info.TEMPLATE)+
'</table>'
@ -878,7 +920,7 @@ function setVMAutorefresh(){
if (!checked.length && !filter.length){
Sunstone.runAction("VM.autorefresh");
}
},INTERVAL+someTime()); //so that not all refreshing is done at the same time
},INTERVAL+someTime());
}
@ -952,7 +994,6 @@ function setupVNC(){
$( "#vnc_dialog" ).bind( "dialogclose", function(event, ui) {
var id = $("#vnc_dialog").attr("vm_id");
Sunstone.runAction("VM.stopvnc",id);
});
$('.vnc').live("click",function(){
@ -987,8 +1028,6 @@ function vncCallback(request,response){
$('#vnc_dialog').dialog('open');
},4000);
}
function vncIcon(vm){
@ -1018,14 +1057,14 @@ $(document).ready(function(){
{ "bSortable": false, "aTargets": ["check"] },
{ "sWidth": "60px", "aTargets": [0] },
{ "sWidth": "35px", "aTargets": [1,9] },
{ "sWidth": "100px", "aTargets": [2] }
{ "sWidth": "100px", "aTargets": [2,3,4] }
]
});
dataTable_vMachines.fnClearTable();
addElement([
spinner,
'','','','','','','','',''],dataTable_vMachines);
'','','','','','','','','',''],dataTable_vMachines);
Sunstone.runAction("VM.list");
setupCreateVMDialog();

View File

@ -25,7 +25,8 @@ var vnets_tab_content =
<tr>\
<th class="check"><input type="checkbox" class="check_all" value="">All</input></th>\
<th>ID</th>\
<th>User</th>\
<th>Owner</th>\
<th>Group</th>\
<th>Name</th>\
<th>Type</th>\
<th>Bridge</th>\
@ -206,8 +207,29 @@ var vnet_actions = {
elements: function() { return getSelectedNodes(dataTable_vNetworks); },
error: onError,
notify: true
}
},
"Network.chown" : {
type: "multiple",
call: OpenNebula.Network.chown,
callback: function (req) {
Sunstone.runAction("Network.show",req.request.data[0]);
},
elements: function() { return getSelectedNodes(dataTable_vNetworks); },
error:onError,
notify: true
},
"Network.chgrp" : {
type: "multiple",
call: OpenNebula.Network.chgrp,
callback: function (req) {
Sunstone.runAction("Network.show",req.request.data[0]);
},
elements: function() { return getSelectedNodes(dataTable_vNetworks); },
error:onError,
notify: true
}
}
@ -237,6 +259,22 @@ var vnet_buttons = {
condition: True
},
"Network.chown" : {
type: "confirm_with_select",
text: "Change owner",
select: function() {return users_select;},
tip: "Select the new owner:",
condition: True
},
"Network.chgrp" : {
type: "confirm_with_select",
text: "Change group",
select: function() {return groups_select;},
tip: "Select the new group:",
condition: True
},
"Network.delete" : {
type: "action",
text: "Delete",
@ -277,14 +315,11 @@ function vNetworkElementArray(vn_json){
total_leases = network.LEASES.LEASE.length ? network.LEASES.LEASE.length : "1";
}
//Does the JSON bring a username field? Otherwise try
//to get it from the users dataTable
var username = network.USERNAME? network.USERNAME : getUserName(network.UID)
return ['<input type="checkbox" id="vnetwork_'+network.ID+'" name="selected_items" value="'+network.ID+'"/>',
return [
'<input type="checkbox" id="vnetwork_'+network.ID+'" name="selected_items" value="'+network.ID+'"/>',
network.ID,
username,
getUserName(network.UID),
getGroupName(network.GID),
network.NAME,
parseInt(network.TYPE) ? "FIXED" : "RANGED",
network.BRIDGE,
@ -309,7 +344,7 @@ function vNetworkInfoListener(){
//updates the vnet select different options
function updateNetworkSelect(){
vnetworks_select=
makeSelectOptions(dataTable_vNetworks,1,3,6,"no",2);
makeSelectOptions(dataTable_vNetworks,1,4,7,"no",2);
//update static selectors:
//in the VM creation dialog
@ -364,7 +399,7 @@ function updateVNetworkInfo(request,vn){
<tr>\
<td class="key_td">ID</td>\
<td class="value_td">'+vn_info.ID+'</td>\
</tr>\
<tr>\
<tr>\
<td class="key_td">UID</td>\
<td class="value_td">'+vn_info.UID+'</td>\
@ -377,11 +412,12 @@ function updateVNetworkInfo(request,vn){
//if it is a fixed VNET we can add leases information
if (vn_info.TEMPLATE.TYPE == "FIXED"){
info_tab_content += '<table id="vn_leases_info_table" class="info_table">\
info_tab_content +=
'<table id="vn_leases_info_table" class="info_table">\
<thead>\
<tr><th colspan="2">Leases information</th></tr>\
</thead>'+
prettyPrintJSON(vn_info.LEASES.LEASE)+
prettyPrintJSON(vn_info.TEMPLATE.LEASES)+
'</table>';
}
@ -393,7 +429,8 @@ function updateVNetworkInfo(request,vn){
var template_tab = {
title: "Virtual Network template",
content: '<table id="vn_template_table" class="info_table">\
content:
'<table id="vn_template_table" class="info_table">\
<thead><tr><th colspan="2">Virtual Network template</th></tr></thead>'+
prettyPrintJSON(vn_info.TEMPLATE)+
'</table>'
@ -406,14 +443,11 @@ function updateVNetworkInfo(request,vn){
}
//Prepares the vnet creation dialog
function setupCreateVNetDialog() {
$('div#dialogs').append('<div title="Create Virtual Network" id="create_vn_dialog"></div>');
$('#create_vn_dialog').html(create_vn_tmpl);
//Prepare the jquery-ui dialog. Set style options here.
$('#create_vn_dialog').dialog({
autoOpen: false,
@ -450,7 +484,6 @@ function setupCreateVNetDialog() {
return false;
};
var lease = ""; //contains the HTML to be included in the select box
if (lease_mac == "") {
lease='<option value="' + lease_ip + '">' + lease_ip + '</option>';
@ -564,25 +597,22 @@ $(document).ready(function(){
"sPaginationType": "full_numbers",
"aoColumnDefs": [
{ "bSortable": false, "aTargets": ["check"] },
{ "sWidth": "60px", "aTargets": [0,4,5,6,7] },
{ "sWidth": "60px", "aTargets": [0,5,6,7,8] },
{ "sWidth": "35px", "aTargets": [1] },
{ "sWidth": "100px", "aTargets": [2] }
{ "sWidth": "100px", "aTargets": [2,3] }
]
});
dataTable_vNetworks.fnClearTable();
addElement([
spinner,
'','','','','','',''],dataTable_vNetworks);
'','','','','','','',''],dataTable_vNetworks);
Sunstone.runAction("Network.list");
setupCreateVNetDialog();
setVNetAutorefresh();
initCheckAllBoxes(dataTable_vNetworks);
tableCheckboxesListener(dataTable_vNetworks);
vNetworkInfoListener();
});

View File

@ -374,26 +374,28 @@ function waitingNodes(dataTable){
}
};
//given a user ID, returns an string with the user name.
//To do this it finds the user name in the user dataTable. If it is
//not defined then it returns "uid UID".
//TODO not very nice to hardcode a dataTable here...
function getUserName(uid){
var user = uid;
if (typeof(dataTable_users) == "undefined") {
return user;
return getName(uid,dataTable_users);
}
var nodes = dataTable_users.fnGetData();
function getGroupName(gid){
return getName(gid,dataTable_groups);
}
function getName(id,dataTable){
var name = id;
if (typeof(dataTable) == "undefined") {
return name;
}
var nodes = dataTable.fnGetData();
$.each(nodes,function(){
if (uid == this[1]) {
user = this[2];
if (id == this[1]) {
name = this[2];
return false;
}
});
return user;
return name;
}
@ -460,12 +462,15 @@ function makeSelectOptions(dataTable,
$.each(nodes,function(){
var id = this[id_col];
var name = this[name_col];
var status = this[status_col];
var status;
if (status_col >= 0) {
status = this[status_col];
}
var user = user_col > 0 ? this[user_col] : false;
var isMine = user ? (username == user) || (uid == user) : true;
if ((status != status_bad) || isMine ){
if (status_col < 0 || (status != status_bad) || isMine ){
select +='<option value="'+id+'">'+name+'</option>';
}
});
@ -494,7 +499,9 @@ function generateMonitoringDivs(graphs, id_prefix){
<thead><tr><th colspan="1">'+this.title+'</th></tr></thead>\
<tr><td id="legend_'+id_suffix+'"></td></tr>\
<tr><td style="border:0">\
<div id="'+id+'" style="width:'+width+'px; height:150px;">'+spinner+'</div>\
<div id="'+id+'" style="width:'+width+'px; height:150px;">'+
spinner+
'</div>\
</td></tr></table>';
});
@ -503,7 +510,8 @@ function generateMonitoringDivs(graphs, id_prefix){
function plot_graph(data,context,id_prefix,info){
var labels = info.monitor_resources;
var humanize = info.humanize_figures ? humanize_size : function(val){return val};
var humanize = info.humanize_figures ?
humanize_size : function(val){ return val };
var labels_arr = labels.split(',');
var id_suffix = labels.replace(/,/g,'_');
var series = [];
@ -536,6 +544,75 @@ function plot_graph(data,context,id_prefix,info){
$.plot($('#'+id, context),series,options);
}
//Enables showing full information on this type of fields on
//mouse hover
function shortenedInfoFields(context){
$('.shortened_info',context).live("mouseenter",function(e){
var full_info = $(this).next();
var top,left;
top = (e.pageY-15)+"px";
left = (e.pageX+15)+"px";
full_info.css({"top":top,"left":left});
full_info.fadeIn();
});
$('.shortened_info',context).live("mouseleave",function(e){
$(this).next().fadeOut();
});
}
function setupTemplateUpdateDialog(){
//Append to DOM
$('div#dialogs').append('<div id="template_update_dialog" title="Update template"></div>');
//Put HTML in place
$('#template_update_dialog').html(
'<form action="javascript:alert(\'js error!\');">\
<h3 style="margin-bottom:10px;">Update the template here:</h3>\
<fieldset style="border-top:none;">\
<label for="template_update_select">Select a template:</label>\
<select id="template_update_select" name="template_update_select"></select>\
<div class="clear"></div>\
<textarea id="template_update_textarea" style="width:100%; height:14em;">Select a template</textarea>\
</fieldset>\
<fieldset>\
<div class="form_buttons">\
<button class="button" id="template_update_button" value="">\
Update\
</button>\
<button class="button" type="reset" value="reset">Reset</button>\
</div>\
</fieldset>\
</form>');
$('#template_update_dialog').dialog({
autoOpen:false,
width:700,
modal:true,
height:410,
resizable:false,
});
$('#template_update_dialog button').button();
$('#template_update_dialog #template_update_select').live("change",function(){
var id = $(this).val();
var resource = $('#template_update_dialog #template_update_button').val();
$('#template_update_dialog #template_update_textarea').val("Loading...");
Sunstone.runAction(resource+".fetch_template",id);
});
$('#template_update_dialog #template_update_button').click(function(){
var new_template = $('#template_update_dialog #template_update_textarea').val();
var id = $('#template_update_dialog #template_update_select').val();
var resource = $(this).val();
Sunstone.runAction(resource+".update",id,new_template);
$('#template_update_dialog').dialog('close');
return false;
});
}
//functions that used as true and false conditions for testing mainly
function True(){
return true;

View File

@ -187,8 +187,8 @@ var Sunstone = {
// * "create" calls to opennebula.js
// * "single" element calls to opennebula.js
// * "list" (get the pool of elements) calls to opennebula.js
// * "monitor_global" (returns monitoring information from a pool of elements
// * "monitor_single" (returns monitoring information from 1 element to create graphs)
// * "monitor_global" (returns monitoring info from a pool of elements
// * "monitor_single" (returns monitoring info from 1 element)
// * "multiple" - actions to be run on a given list of elements
// (with maybe an extra parameter).
// * The default actions. Simple call the the pre-defined "call"
@ -200,25 +200,52 @@ var Sunstone = {
call({data:data_arg, success: callback, error:err});
break;
case "single":
if (extra_param){
call({
data:{
id:data_arg,
extra_param:extra_param
},
success: callback,error:err
});
} else {
call({data:{id:data_arg}, success: callback,error:err});
};
break;
case "list":
call({success: callback, error:err});
break;
case "monitor_global":
call({timeout: true, success: callback, error:err, data: {monitor: data_arg}});
call({
timeout: true,
success: callback,
error:err,
data: {monitor: data_arg}});
break;
case "monitor":
case "monitor_single":
call({timeout: true, success: callback, error:err, data: {id:data_arg, monitor: extra_param}});
call({
timeout: true,
success: callback,
error:err,
data: {id:data_arg, monitor: extra_param}});
break;
case "multiple":
//run on the list of nodes that come on the data
$.each(data_arg,function(){
if (extra_param){
call({data:{id:this,extra_param:extra_param}, success: callback, error: err});
call({
data:{
id:this,
extra_param:extra_param
},
success: callback,
error: err});
} else {
call({data:{id:this}, success: callback, error:err});
call({
data:{id:this},
success: callback,
error:err});
}
});
break;
@ -237,25 +264,6 @@ var Sunstone = {
},
//Runs a predefined action on the selected nodes of a datatable.
//Optionally they are run with an extra_parameter.
//If no datatable is provided, it simply runs the action.
//~ "runActionOnDatatableNodes": function(action,dataTable,extra_param){
//~ if (dataTable != null){
//~
//~ //Which rows of the datatable are checked?
//~ var nodes = $('input:checked',dataTable.fnGetNodes());
//~ var data = [];
//~ $.each(nodes,function(){
//~ data.push($(this).val());
//~ });
//~ Sunstone.runAction(action,data,extra_param);
//~
//~ } else {
//~ Sunstone.runAction(action,extra_param);
//~ };
//~ },
//~
//returns a button object from the desired tab
"getButton" : function(tab_id,button_name){
var button = null;
@ -273,8 +281,6 @@ var Sunstone = {
//Plugins have done their pre-ready jobs when we execute this. That means
//all startup configuration is in place regarding tabs, info panels etc.
$(document).ready(function(){
@ -291,6 +297,9 @@ $(document).ready(function(){
//Prepare the standard confirmation dialogs
setupConfirmDialogs();
//This dialog is shared to update templates
setupTemplateUpdateDialog();
//Listen for .action_buttons
//An action buttons runs a predefined action. If it has type
//"multiple" it runs that action on the elements of a datatable.
@ -299,7 +308,10 @@ $(document).ready(function(){
var table = null;
var value = $(this).attr("value");
var action = SunstoneCfg["actions"][value];
if (!action) { notifyError("Action "+value+" not defined."); return false;};
if (!action) {
notifyError("Action "+value+" not defined.");
return false;
};
switch (action.type){
case "multiple": //find the datatable
var nodes = action.elements();
@ -366,7 +378,8 @@ function setLogin(){
$("#user").html(username);
$("#logout").click(function(){
OpenNebula.Auth.logout({success:function(){
OpenNebula.Auth.logout({
success:function(){
window.location.href = "/login";
}
});
@ -502,16 +515,12 @@ function initListButtons(){
"display":"none"
});
//replace the select and insert the buttons
$(this).before(buttonset);
$(this).parents('.action_blocks').append(list);
$(this).remove();
//$(this).replaceWith(list);
});
//below the listeners for events on these buttons and list
//enable run the last action button
@ -529,7 +538,6 @@ function initListButtons(){
//return false;
});
//Show the list of actions in place
$('.list_button').click(function(){
$('.action_list',$(this).parents('.action_blocks')).css({
@ -591,7 +599,6 @@ function setupConfirmDialogs(){
</div>\
</form>');
//prepare the jquery dialog
$('div#confirm_with_select_dialog').dialog({
resizable:false,
@ -628,9 +635,7 @@ function setupConfirmDialogs(){
break;
}
return false;
});
}
//Popup a confirmation dialog.
@ -663,5 +668,3 @@ function popUpConfirmWithSelectDialog(target_elem){
$('button#confirm_with_select_proceed').val(value);
$('div#confirm_with_select_dialog').dialog("open");
}

View File

@ -184,6 +184,11 @@ end
##############################################################################
# GET Resource information
##############################################################################
get '/:resource/:id/template' do
@SunstoneServer.get_template(params[:resource], params[:id])
end
get '/:resource/:id' do
@SunstoneServer.get_resource(params[:resource], params[:id])
end

View File

@ -26,8 +26,11 @@
<script type="text/javascript" src="/js/layout.js"></script>
<script type="text/javascript" src="/js/sunstone.js"></script>
<script type="text/javascript" src="/js/sunstone-util.js"></script>
<!--Base plugins-->
<script type="text/javascript" src="/js/plugins/dashboard-tab.js"></script>
<script type="text/javascript" src="/js/plugins/hosts-tab.js"></script>
<script type="text/javascript" src="/js/plugins/groups-tab.js"></script>
<script type="text/javascript" src="/js/plugins/templates-tab.js"></script>
<script type="text/javascript" src="/js/plugins/vms-tab.js"></script>
<script type="text/javascript" src="/js/plugins/vnets-tab.js"></script>