1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-04-01 06:50:25 +03:00

Feature #1112: Add datastores to Sunstone

This commit is contained in:
Hector Sanjuan 2012-03-10 17:47:15 +01:00
parent c61159fb30
commit d1012c8146
17 changed files with 810 additions and 60 deletions

View File

@ -1118,6 +1118,7 @@ SUNSTONE_MODELS_JSON_FILES="src/sunstone/models/OpenNebulaJSON/HostJSON.rb \
src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb \
src/sunstone/models/OpenNebulaJSON/AclJSON.rb \
src/sunstone/models/OpenNebulaJSON/ClusterJSON.rb \
src/sunstone/models/OpenNebulaJSON/DatastoreJSON.rb \
src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb"
SUNSTONE_TEMPLATE_FILES="src/sunstone/templates/login.html \
@ -1137,6 +1138,7 @@ SUNSTONE_PUBLIC_JS_PLUGINS_FILES="\
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/datastores-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 \

View File

@ -23,6 +23,10 @@
:ALL: true
:user:
:group:
- plugins/datastores-tab.js:
:ALL: true
:user:
:group:
- plugins/templates-tab.js:
:ALL: true
:user:

View File

@ -28,6 +28,7 @@ require 'OpenNebulaJSON/UserJSON'
require 'OpenNebulaJSON/VirtualMachineJSON'
require 'OpenNebulaJSON/VirtualNetworkJSON'
require 'OpenNebulaJSON/AclJSON'
require 'OpenNebulaJSON/DatastoreJSON'
module OpenNebula
class Error

View File

@ -17,23 +17,27 @@
require 'OpenNebulaJSON/JSONUtils'
module OpenNebulaJSON
class ClusterJSON < OpenNebula::Datastore
class DatastoreJSON < OpenNebula::Datastore
include JSONUtils
def create(template_json, cluster_id=ClusterPool::NONE_CLUSTER_ID)
datastore_hash = parse_json(template_json, 'datastore')
if OpenNebula.is_error?(datastore_hash)
return datastore_hash
def create(template_json)
ds_hash = parse_json(template_json, 'datastore')
if OpenNebula.is_error?(ds_hash)
return ds_hash
end
if datastore_hash['datastore_raw']
template = datastore_hash['image_raw']
cluster_id = parse_json(template_json, 'cluster_id')
if OpenNebula.is_error?(cluster_id)
return cluster_id
end
if ds_hash['datastore_raw']
template = ds_hash['datastore_raw']
else
template = template_to_str(datastore_hash)
template = template_to_str(ds_hash)
end
self.allocate(template,cluster_id)
self.allocate(template,cluster_id.to_i)
end
def perform_action(template_json)
@ -42,9 +46,27 @@ 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 "update" then self.update(action_hash['params'])
when "chown" then self.chown(action_hash['params'])
when "chmod" then self.chmod_octet(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['template_raw'])
end
def chown(params=Hash.new)
super(params['owner_id'].to_i,params['group_id'].to_i)
end
def chmod_octet(params=Hash.new)
super(params['octet'])
end
end
end

View File

@ -26,13 +26,18 @@ module OpenNebulaJSON
return image_hash
end
ds_id = parse_json(template_json, 'ds_id')
if OpenNebula.is_error?(ds_id)
return ds_id
end
if image_hash['image_raw']
template = image_hash['image_raw']
else
template = template_to_str(image_hash)
end
self.allocate(template)
self.allocate(template,ds_id)
end
def perform_action(template_json)

View File

@ -26,4 +26,5 @@ module OpenNebulaJSON
class UserPoolJSON < OpenNebula::UserPool; include JSONUtils; end
class AclPoolJSON < OpenNebula::AclPool; include JSONUtils; end
class ClusterPoolJSON < OpenNebula::ClusterPool; include JSONUtils; end
class DatastorePoolJSON < OpenNebula::DatastorePool; include JSONUtils; end
end

View File

@ -56,6 +56,7 @@ class SunstoneServer < CloudServer
when "vnet" then VirtualNetworkPoolJSON.new(@client, user_flag)
when "user" then UserPoolJSON.new(@client)
when "acl" then AclPoolJSON.new(@client)
when "datastore" then DatastorePoolJSON.new(@client)
else
error = Error.new("Error: #{kind} resource not supported")
return [404, error.to_json]
@ -109,6 +110,7 @@ class SunstoneServer < CloudServer
when "vnet" then VirtualNetworkJSON.new(VirtualNetwork.build_xml, @client)
when "user" then UserJSON.new(User.build_xml, @client)
when "acl" then AclJSON.new(Acl.build_xml, @client)
when "datastore" then DatastoreJSON.new(Acl.build_xml, @client)
else
error = Error.new("Error: #{kind} resource not supported")
return [404, error.to_json]
@ -276,15 +278,16 @@ 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 "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)
when "vm" then VirtualMachineJSON.new_with_id(id, @client)
when "vnet" then VirtualNetworkJSON.new_with_id(id, @client)
when "user" then UserJSON.new_with_id(id, @client)
when "acl" then AclJSON.new_with_id(id, @client)
when "vm" then VirtualMachineJSON.new_with_id(id, @client)
when "vnet" then VirtualNetworkJSON.new_with_id(id, @client)
when "user" then UserJSON.new_with_id(id, @client)
when "acl" then AclJSON.new_with_id(id, @client)
when "datastore" then DatastoreJSON.new_with_id(id, @client)
else
error = Error.new("Error: #{kind} resource not supported")
return error

View File

@ -866,6 +866,9 @@ var OpenNebula = {
"list" : function(params){
OpenNebula.Action.list(params,OpenNebula.Cluster.resource);
},
"show" : function(params){
OpenNebula.Action.show(params,OpenNebula.Cluster.resource);
},
"addhost" : function(params){
var action_obj = { "host_id": params.data.extra_param };
OpenNebula.Action.simple_action(params,OpenNebula.Cluster.resource,
@ -897,4 +900,43 @@ var OpenNebula = {
"delvnet",action_obj);
},
},
"Datastore" : {
"resource" : "DATASTORE",
"create" : function(params){
OpenNebula.Action.create(params,OpenNebula.Datastore.resource);
},
"delete" : function(params){
OpenNebula.Action.delete(params,OpenNebula.Datastore.resource);
},
"list" : function(params){
OpenNebula.Action.list(params,OpenNebula.Datastore.resource);
},
"show" : function(params){
OpenNebula.Action.show(params,OpenNebula.Datastore.resource);
},
"chown" : function(params){
OpenNebula.Action.chown(params,OpenNebula.Datastore.resource);
},
"chgrp" : function(params){
OpenNebula.Action.chgrp(params,OpenNebula.Datastore.resource);
},
"chmod" : function(params){
var action_obj = params.data.extra_param;
OpenNebula.Action.simple_action(params,
OpenNebula.Datastore.resource,
"chmod",
action_obj);
},
"update" : function(params){
var action_obj = {"template_raw" : params.data.extra_param };
OpenNebula.Action.simple_action(params,
OpenNebula.Datastore.resource,
"update",
action_obj);
},
"fetch_template" : function(params){
OpenNebula.Action.show(params,OpenNebula.Datastore.resource,"template");
},
},
}

View File

@ -45,8 +45,10 @@ var create_acl_tmpl =
<label for="applies">'+tr("This rule applies to")+':</label>\
<select name="applies" id="applies"></select>\
<div class="clear"></div>\
<label style="height:9em">'+tr("Affected resources")+':</label>\
<label style="height:11em">'+tr("Affected resources")+':</label>\
<input type="checkbox" name="res_host" class="resource_cb" value="HOST">'+tr("Hosts")+'</input><br />\
<input type="checkbox" name="res_cluster" class="resource_cb" value="CLUSTER">'+tr("Clusters")+'</input><br />\
<input type="checkbox" name="res_datastore" class="resource_cb" value="DATASTORE">'+tr("Datastores")+'</input><br />\
<input type="checkbox" name="res_vm" class="resource_cb" value="VM">'+tr("Virtual Machines")+'</input><br />\
<input type="checkbox" name="res_net" class="resource_cb" value="NET">'+tr("Virtual Networks")+'</input><br />\
<input type="checkbox" name="res_image" class="resource_cb" value="IMAGE">'+tr("Images")+'</input><br />\
@ -247,6 +249,12 @@ function parseAclString(string) {
case "GROUP":
resources_str+=tr("Groups")+", ";
break;
case "CLUSTER":
resources_str+=tr("Clusters")+", ";
break;
case "DATASTORE":
resources_str+=tr("Datastores")+", ";
break;
};
};
//remove ", " from end

View File

@ -128,7 +128,7 @@ var cluster_actions = {
"Cluster.adddatastore" : {
type: "single",
call : OpenNebula.Cluster.addhost,
call : OpenNebula.Cluster.adddatastore,
callback : function (req) {
Sunstone.runAction("Datastore.show",req.request.data[0][1].ds_id);
//Sunstone.runAction("Cluster.show",req.request.data[0]);
@ -138,7 +138,7 @@ var cluster_actions = {
"Cluster.deldatastore" : {
type: "single",
call : OpenNebula.Cluster.addhost,
call : OpenNebula.Cluster.deldatastore,
callback : function (req) {
//Sunstone.runAction("Cluster.show",req.request.data[0]);
},

View File

@ -0,0 +1,657 @@
/* -------------------------------------------------------------------------- */
/* 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. */
/* -------------------------------------------------------------------------- */
/*Datastore tab plugin*/
var datastores_tab_content =
'<form id="form_datastores" action="javascript:alert(\'js errors?!\')">\
<div class="action_blocks">\
</div>\
<table id="datatable_datastores" class="display">\
<thead>\
<tr>\
<th class="check"><input type="checkbox" class="check_all" value="">' + tr("All") + '</input></th>\
<th>'+tr("ID")+'</th>\
<th>'+tr("Owner")+'</th>\
<th>'+tr("Group")+'</th>\
<th>'+tr("Name")+'</th>\
<th>'+tr("Cluster")+'</th>\
</tr>\
</thead>\
<tbody id="tbodydatastores">\
</tbody>\
</table>\
</form>';
var create_datastore_tmpl =
'<div class="create_form"><form id="create_datastore_form" action="">\
<fieldset>\
<label for="name">' + tr("Name") + ':</label>\
<input type="text" name="name" id="name" />\
<label for="cluster">' + tr("Cluster") + ':</label>\
<select id="cluster_id" name="cluster_id">\
</select>\
<label>' + tr("Datastore manager") + ':</label>\
<select id="ds_mad" name="ds_mad">\
<option value="fs">' + tr("Filesystem") + '</option>\
<option value="vmware">' + tr("VMware") + '</option>\
<option value="iscsi">' + tr("iSCSI") + '</option>\
</select>\
<label>' + tr("Transfer manager") + ':</label>\
<select id="tm_mad" name="tm_mad">\
<option value="shared">' + tr("Shared") + '</option>\
<option value="ssh">' + tr("SSH") + '</option>\
<option value="iscsi">' + tr("iSCSI") + '</option>\
<option value="dummy">' + tr("Dummy") + '</option>\
</select>\
</fieldset>\
<fieldset>\
<div class="form_buttons">\
<div><button class="button" type="submit" id="create_datastore_submit" value="OpenNebula.Datastore.create">' + tr("Create") + '</button>\
<button class="button" type="reset" value="reset">' + tr("Reset") + '</button></div>\
</div>\
</fieldset>\
</form></div>';
var update_datastore_tmpl =
'<form action="javascript:alert(\'js error!\');">\
<h3 style="margin-bottom:10px;">'+tr("Please, choose and modify the datastore you want to update")+':</h3>\
<fieldset style="border-top:none;">\
<label for="datastore_template_update_select">'+tr("Select a datastore")+':</label>\
<select id="datastore_template_update_select" name="datastore_template_update_select"></select>\
<div class="clear"></div>\
<div>\
<table class="permissions_table" style="padding:0 10px;">\
<thead><tr>\
<td style="width:130px">'+tr("Permissions")+':</td>\
<td style="width:40px;text-align:center;">'+tr("Use")+'</td>\
<td style="width:40px;text-align:center;">'+tr("Manage")+'</td>\
<td style="width:40px;text-align:center;">'+tr("Admin")+'</td></tr></thead>\
<tr>\
<td>'+tr("Owner")+'</td>\
<td style="text-align:center"><input type="checkbox" name="datastore_owner_u" class="owner_u" /></td>\
<td style="text-align:center"><input type="checkbox" name="datastore_owner_m" class="owner_m" /></td>\
<td style="text-align:center"><input type="checkbox" name="datastore_owner_a" class="owner_a" /></td>\
</tr>\
<tr>\
<td>'+tr("Group")+'</td>\
<td style="text-align:center"><input type="checkbox" name="datastore_group_u" class="group_u" /></td>\
<td style="text-align:center"><input type="checkbox" name="datastore_group_m" class="group_m" /></td>\
<td style="text-align:center"><input type="checkbox" name="datastore_group_a" class="group_a" /></td>\
</tr>\
<tr>\
<td>'+tr("Other")+'</td>\
<td style="text-align:center"><input type="checkbox" name="datastore_other_u" class="other_u" /></td>\
<td style="text-align:center"><input type="checkbox" name="datastore_other_m" class="other_m" /></td>\
<td style="text-align:center"><input type="checkbox" name="datastore_other_a" class="other_a" /></td>\
</tr>\
</table>\
</div>\
<label for="datastore_template_update_textarea">'+tr("Datastore")+':</label>\
<div class="clear"></div>\
<textarea id="datastore_template_update_textarea" style="width:100%; height:14em;"></textarea>\
</fieldset>\
<fieldset>\
<div class="form_buttons">\
<button class="button" id="datastore_template_update_button" value="Datastore.update_template">\
'+tr("Update")+'\
</button>\
</div>\
</fieldset>\
</form>';
var datastores_select="";
var dataTable_datastores;
var $create_datastore_dialog;
//Setup actions
var datastore_actions = {
"Datastore.create" : {
type: "create",
call : OpenNebula.Datastore.create,
callback : addDatastoreElement,
error : onError,
notify: true
},
"Datastore.create_dialog" : {
type: "custom",
call: popUpCreateDatastoreDialog
},
"Datastore.list" : {
type: "list",
call: OpenNebula.Datastore.list,
callback: updateDatastoresView,
error: onError
},
"Datastore.show" : {
type: "single",
call: OpenNebula.Datastore.show,
callback: updateDatastoreElement,
error: onError
},
"Datastore.showinfo" : {
type: "single",
call: OpenNebula.Datastore.show,
callback: updateDatastoreInfo,
error: onError
},
"Datastore.refresh" : {
type: "custom",
call: function(){
waitingNodes(dataTable_datastores);
Sunstone.runAction("Datastore.list");
},
error: onError
},
"Datastore.fetch_template" : {
type: "single",
call: OpenNebula.Datastore.fetch_template,
callback: function (request,response) {
$('#datastore_template_update_dialog #datastore_template_update_textarea').val(response.template);
},
error: onError
},
"Datastore.fetch_permissions" : {
type: "single",
call: OpenNebula.Datastore.show,
callback: function(request,element_json){
var dialog = $('#datastore_template_update_dialog form');
var ds = element_json.DATASTORE;
setPermissionsTable(ds,dialog);
},
error: onError
},
"Datastore.update_dialog" : {
type: "custom",
call: popUpDatastoreTemplateUpdateDialog,
},
"Datastore.update" : {
type: "single",
call: OpenNebula.Datastore.update,
callback: function() {
notifyMessage(tr("Datastore updated correctly"));
},
error: onError
},
"Datastore.autorefresh" : {
type: "custom",
call : function() {
OpenNebula.Datastore.list({timeout: true, success: updateDatastoresView,error: onError});
}
},
"Datastore.delete" : {
type: "multiple",
call : OpenNebula.Datastore.delete,
callback : deleteDatastoreElement,
elements: datastoreElements,
error : onError,
notify:true
},
"Datastore.chown" : {
type: "multiple",
call: OpenNebula.Datastore.chown,
callback: function (req) {
Sunstone.runAction("Datastore.show",req.request.data[0][0]);
},
elements: datastoreElements,
error: onError,
notify: true
},
"Datastore.chgrp" : {
type: "multiple",
call: OpenNebula.Datastore.chgrp,
callback: function (req) {
Sunstone.runAction("Datastore.show",req.request.data[0][0]);
},
elements: datastoreElements,
error: onError,
notify: true
},
"Datastore.chmod" : {
type: "single",
call: OpenNebula.Datastore.chmod,
// callback
error: onError,
notify: true
},
"Datastore.addtocluster" : {
type: "multiple",
call: function(params){
var cluster = params.data.extra_param;
var ds = params.data.id;
Sunstone.runAction("Cluster.adddatastore",cluster,ds);
},
elements: datastoreElements,
notify:true,
},
};
var datastore_buttons = {
"Datastore.refresh" : {
type: "image",
text: tr("Refresh list"),
img: "images/Refresh-icon.png"
},
"Datastore.create_dialog" : {
type: "create_dialog",
text: tr("+ New")
},
"Datastore.update_dialog" : {
type: "action",
text: tr("Update properties"),
alwaysActive: true
},
"Datastore.addtocluster" : {
type: "confirm_with_select",
text: tr("Select cluster"),
select: clusters_sel,
tip: tr("Select the destination cluster:"),
},
"Datastore.chown" : {
type: "confirm_with_select",
text: tr("Change owner"),
select: users_sel,
tip: tr("Select the new owner")+":",
condition: mustBeAdmin
},
"Datastore.chgrp" : {
type: "confirm_with_select",
text: tr("Change group"),
select: groups_sel,
tip: tr("Select the new group")+":",
condition: mustBeAdmin
},
"Datastore.delete" : {
type: "confirm",
text: tr("Delete")
}
}
var datastore_info_panel = {
"datastore_info_tab" : {
title: tr("Datastore information"),
content: ""
},
"datastore_template_tab" : {
title: tr("Datastore template"),
content: ""
},
}
var datastores_tab = {
title: tr("Datastores"),
content: datastores_tab_content,
buttons: datastore_buttons
}
Sunstone.addActions(datastore_actions);
Sunstone.addMainTab('datastores_tab',datastores_tab);
Sunstone.addInfoPanel('datastore_info_panel',datastore_info_panel);
function datastoreElements() {
return getSelectedNodes(dataTable_datastores);
}
function vmShow(req) {
Sunstone.runAction("Datastore.show",req.request.data[0]);
}
function datastoreElementArray(element_json){
var element = element_json.DATASTORE;
return [
'<input class="check_item" type="checkbox" id="datastore_'+element.ID+'" name="selected_items" value="'+element.ID+'"/>',
element.ID,
element.UNAME,
element.GNAME,
element.NAME,
element.CLUSTER
];
}
function datastoreInfoListener(){
$('#tbodydatastores tr',dataTable_datastores).live("click", function(e){
if ($(e.target).is('input') || $(e.target).is('a img')) {return true;}
var aData = dataTable_datastores.fnGetData(this);
var id = $(aData[0]).val();
if (!id) return true;
popDialogLoading();
Sunstone.runAction("Datastore.showinfo",id);
return false;
});
}
function updateDatastoreElement(request, element_json){
var id = element_json.DATASTORE.ID;
var element = datastoreElementArray(element_json);
updateSingleElement(element,dataTable_datastores,'#datastore_'+id)
}
function deleteDatastoreElement(request){
deleteElement(dataTable_datastores,'#datastore_'+request.request.data);
}
function addDatastoreElement(request,element_json){
var id = element_json.DATASTORE.ID;
var element = datastoreElementArray(element_json);
addElement(element,dataTable_datastores);
}
function updateDatastoresView(request, list){
var list_array = [];
$.each(list,function(){
list_array.push( datastoreElementArray(this));
});
updateView(list_array,dataTable_datastores);
updateDashboard("datastores",list);
}
function updateDatastoreInfo(request,ds){
var info = ds.DATASTORE;
var info_tab = {
title : tr("Datastore information"),
content:
'<table id="info_datastore_table" class="info_table">\
<thead>\
<tr><th colspan="2">'+tr("Datastore information")+' - '+info.NAME+'</th></tr>\
</thead>\
<tbody>\
<tr>\
<td class="key_td">'+tr("ID")+'</td>\
<td class="value_td">'+info.ID+'</td>\
</tr>\
<tr>\
<td class="key_td">'+tr("Name")+'</td>\
<td class="value_td">'+info.NAME+'</td>\
</tr>\
<tr>\
<td class="key_td">'+tr("Owner")+'</td>\
<td class="value_td">'+info.UNAME+'</td>\
</tr>\
<tr>\
<td class="key_td">'+tr("Group")+'</td>\
<td class="value_td">'+info.GNAME+'</td>\
</tr>\
<tr>\
<td class="key_td">'+tr("Cluster")+'</td>\
<td class="value_td">'+info.CLUSTER+'</td>\
</tr>\
<tr>\
<td class="key_td">'+tr("DS Mad")+'</td>\
<td class="value_td">'+info.DS_MAD+'</td>\
</tr>\
<tr>\
<td class="key_td">'+tr("TM Mad")+'</td>\
<td class="value_td">'+ info.TM_MAD +'</td>\
</tr>\
<tr>\
<td class="key_td">'+tr("Base path")+'</td>\
<td class="value_td">'+info.BASE_PATH+'</td>\
</tr>\
<tr><td class="key_td">'+tr("Permissions")+'</td><td></td></tr>\
<tr>\
<td class="key_td">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+tr("Owner")+'</td>\
<td class="value_td" style="font-family:monospace;">'+ownerPermStr(info)+'</td>\
</tr>\
<tr>\
<td class="key_td">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+tr("Group")+'</td>\
<td class="value_td" style="font-family:monospace;">'+groupPermStr(info)+'</td>\
</tr>\
<tr>\
<td class="key_td"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+tr("Other")+'</td>\
<td class="value_td" style="font-family:monospace;">'+otherPermStr(info)+'</td>\
</tr>\
</tbody>\
</table>'
}
var template_tab = {
title: tr("Datastore Template"),
content:
'<table id="datastore_template_table" class="info_table" style="width:80%">\
<thead><tr><th colspan="2">'+tr("Datastore template")+'</th></tr></thead>'+
prettyPrintJSON(info.TEMPLATE)+
'</table>'
}
Sunstone.updateInfoPanelTab("datastore_info_panel","datastore_info_tab",info_tab);
Sunstone.updateInfoPanelTab("datastore_info_panel","datastore_template_tab",template_tab);
Sunstone.popUpInfoPanel("datastore_info_panel");
}
// Sets up the create-template dialog and all the processing associated to it,
// which is a lot.
function setupCreateDatastoreDialog(){
dialogs_context.append('<div title=\"'+tr("Create Datastore")+'\" id="create_datastore_dialog"></div>');
//Insert HTML in place
$create_datastore_dialog = $('#create_datastore_dialog')
var dialog = $create_datastore_dialog;
dialog.html(create_datastore_tmpl);
//Prepare jquery dialog
dialog.dialog({
autoOpen: false,
modal: true,
width: 400
});
$('button',dialog).button();
setupTips(dialog);
$('#create_datastore_form',dialog).submit(function(){
var name = $('#name',this).val();
var cluster_id = $('#cluster_id',this).val();
var ds_mad = $('#ds_mad',this).val();
var tm_mad = $('#tm_mad',this).val();
if (!name){
notifyError("Please provide a name");
return false;
};
var ds_obj = {
"datastore" : {
"name" : name,
"ds_mad" : ds_mad,
"tm_mad" : tm_mad
},
"cluster_id" : cluster_id
};
Sunstone.runAction("Datastore.create",ds_obj);
$create_datastore_dialog.dialog('close');
return false;
});
}
function popUpCreateDatastoreDialog(){
$('select#cluster_id',$create_datastore_dialog).html(clusters_sel());
$create_datastore_dialog.dialog('open');
}
function setupDatastoreTemplateUpdateDialog(){
//Append to DOM
dialogs_context.append('<div id="datastore_template_update_dialog" title="'+tr("Update Datastore properties")+'"></div>');
var dialog = $('#datastore_template_update_dialog',dialogs_context);
//Put HTML in place
dialog.html(update_datastore_tmpl);
var height = Math.floor($(window).height()*0.8); //set height to a percentage of the window
//Convert into jQuery
dialog.dialog({
autoOpen:false,
width:500,
modal:true,
height:height,
resizable:true,
});
$('button',dialog).button();
$('#datastore_template_update_select',dialog).change(function(){
var id = $(this).val();
$('.permissions_table input',dialog).removeAttr('checked');
$('.permissions_table',dialog).removeAttr('update');
if (id && id.length){
var dialog = $('#datastore_template_update_dialog');
$('#template_template_update_textarea',dialog).val(tr("Loading")+"...");
Sunstone.runAction("Datastore.fetch_template",id);
Sunstone.runAction("Datastore.fetch_permissions",id);
} else {
$('#datastore_template_update_textarea',dialog).val("");
};
});
$('.permissions_table input',dialog).change(function(){
$(this).parents('table').attr('update','update');
});
$('form',dialog).submit(function(){
var dialog = $(this);
var new_template = $('#datastore_template_update_textarea',dialog).val();
var id = $('#datastore_template_update_select',dialog).val();
if (!id || !id.length) {
$(this).parents('#datastore_template_update_dialog').dialog('close');
return false;
};
var permissions = $('.permissions_table',dialog);
if (permissions.attr('update')){
var perms = {
octet : buildOctet(permissions)
};
Sunstone.runAction("Datastore.chmod",id,perms);
};
Sunstone.runAction("Datastore.update",id,new_template);
$(this).parents('#datastore_template_update_dialog').dialog('close');
return false;
});
};
function popUpDatastoreTemplateUpdateDialog(){
var select = makeSelectOptions(dataTable_datastores,
1,//id_col
4,//name_col
[],
[]
);
var sel_elems = getSelectedNodes(dataTable_datastores);
var dialog = $('#datastore_template_update_dialog');
$('#datastore_template_update_select',dialog).html(select);
$('#datastore_template_update_textarea',dialog).val("");
$('.permissions_table input',dialog).removeAttr('checked');
$('.permissions_table',dialog).removeAttr('update');
if (sel_elems.length >= 1){ //several items in the list are selected
//grep them
var new_select= sel_elems.length > 1? '<option value="">Please select</option>' : "";
$('option','<select>'+select+'</select>').each(function(){
var val = $(this).val();
if ($.inArray(val,sel_elems) >= 0){
new_select+='<option value="'+val+'">'+$(this).text()+'</option>';
};
});
$('#datastore_template_update_select',dialog).html(new_select);
if (sel_elems.length == 1) {
$('#datastore_template_update_select option',dialog).attr('selected','selected');
$('#datastore_template_update_select',dialog).trigger("change");
};
};
dialog.dialog('open');
return false;
};
//Prepares autorefresh
function setDatastoreAutorefresh(){
setInterval(function(){
var checked = $('input.check_item:checked',dataTable_datastores);
var filter = $("#datatable_datastores_filter input",
dataTable_datastores.parents('#datatable_datastores_wrapper')).attr('value');
if (!checked.length && !filter.length){
Sunstone.runAction("Datastore.autorefresh");
};
},INTERVAL+someTime());
}
$(document).ready(function(){
dataTable_datastores = $("#datatable_datastores",main_tabs_context).dataTable({
"bJQueryUI": true,
"bSortClasses": false,
"sPaginationType": "full_numbers",
"bAutoWidth":false,
"aoColumnDefs": [
{ "bSortable": false, "aTargets": ["check"] },
{ "sWidth": "60px", "aTargets": [0] },
{ "sWidth": "35px", "aTargets": [1] },
{ "sWidth": "100px", "aTargets": [2,3,5] }
],
"oLanguage": (datatable_lang != "") ?
{
sUrl: "locale/"+lang+"/"+datatable_lang
} : ""
});
dataTable_datastores.fnClearTable();
addElement([
spinner,
'','','','',''],dataTable_datastores);
Sunstone.runAction("Datastore.list");
setupCreateDatastoreDialog();
setupDatastoreTemplateUpdateDialog();
setDatastoreAutorefresh();
initCheckAllBoxes(dataTable_datastores);
tableCheckboxesListener(dataTable_datastores);
datastoreInfoListener();
})

View File

@ -321,11 +321,6 @@ var hosts_tab = {
buttons: host_buttons
}
//Hack since this plugin is loaded earlier
function clusters_sel() {
return clusters_select;
}
Sunstone.addActions(host_actions);
Sunstone.addMainTab('hosts_tab',hosts_tab);
Sunstone.addInfoPanel("host_info_panel",host_info_panel);
@ -607,7 +602,7 @@ function setupCreateHostDialog(){
//Open creation dialogs
function popUpCreateHostDialog(){
$('#host_cluster_id',$create_host_dialog).html(clusters_select);
$('#host_cluster_id',$create_host_dialog).html(clusters_sel());
$create_host_dialog.dialog('open');
return false;
}
@ -632,10 +627,6 @@ function hostMonitorError(req,error_json){
$('#host_monitoring_tab '+id).html('<div style="padding-left:20px;">'+message+'</div>');
}
function hosts_sel() {
return hosts_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

View File

@ -28,6 +28,7 @@ var images_tab_content =
<th>'+tr("Owner")+'</th>\
<th>'+tr("Group")+'</th>\
<th>'+tr("Name")+'</th>\
<th>'+tr("Datastore")+'</th>\
<th>'+tr("Size")+'</th>\
<th>'+tr("Type")+'</th>\
<th>'+tr("Registration time")+'</th>\
@ -316,7 +317,7 @@ var image_actions = {
type: "single",
call: OpenNebula.Image.update,
callback: function() {
notifyMessage(tr("Template updated correctly"));
notifyMessage(tr("Image updated correctly"));
},
error: onError
},
@ -378,7 +379,7 @@ var image_actions = {
type: "multiple",
call: OpenNebula.Image.chown,
callback: function (req) {
Sunstone.runAction("Image.show",req.request.data[0]);
Sunstone.runAction("Image.show",req.request.data[0][0]);
},
elements: imageElements,
error: onError,
@ -389,7 +390,7 @@ var image_actions = {
type: "multiple",
call: OpenNebula.Image.chgrp,
callback: function (req) {
Sunstone.runAction("Image.show",req.request.data[0]);
Sunstone.runAction("Image.show",req.request.data[0][0]);
},
elements: imageElements,
error: onError,
@ -522,6 +523,7 @@ function imageElementArray(image_json){
image.UNAME,
image.GNAME,
image.NAME,
image.DATASTORE,
image.SIZE,
'<select class="action_cb" id="select_chtype_image" elem_id="'+image.ID+'" style="width:100px">'+type.html()+'</select>',
pretty_time(image.REGTIME),
@ -599,6 +601,10 @@ function updateImageInfo(request,img){
<td class="key_td">'+tr("Name")+'</td>\
<td class="value_td">'+img_info.NAME+'</td>\
</tr>\
<tr>\
<td class="key_td">'+tr("Datastore")+'</td>\
<td class="value_td">'+img_info.DATASTORE+'</td>\
</tr>\
<tr>\
<td class="key_td">'+tr("Owner")+'</td>\
<td class="value_td">'+img_info.UNAME+'</td>\
@ -643,7 +649,7 @@ function updateImageInfo(request,img){
<td class="key_td">'+tr("Running #VMS")+'</td>\
<td class="value_td">'+img_info.RUNNING_VMS+'</td>\
</tr>\
<tr><td class="key_td">Permissions</td><td></td></tr>\
<tr><td class="key_td">'+tr("Permissions")+'</td><td></td></tr>\
<tr>\
<td class="key_td">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+tr("Owner")+'</td>\
<td class="value_td" style="font-family:monospace;">'+ownerPermStr(img_info)+'</td>\
@ -843,6 +849,9 @@ function setupCreateImageDialog(){
}
});
if (exit) { return false; }
var ds_id = $('#img_ds_id',this).val();
var img_json = {};
var name = $('#img_name',this).val();
@ -897,8 +906,9 @@ function setupCreateImageDialog(){
img_json[attr_name] = attr_value;
});
img_obj = { "image" : img_json };
ds_id = 1;
img_obj = { "image" : img_json,
"ds_id" : ds_id};
if (upload){
uploader._onInputChange(file_input);
@ -1094,10 +1104,10 @@ $(document).ready(function(){
"sPaginationType": "full_numbers",
"aoColumnDefs": [
{ "bSortable": false, "aTargets": ["check"] },
{ "sWidth": "60px", "aTargets": [0,2,3,8,9] },
{ "sWidth": "35px", "aTargets": [1,5,10] },
{ "sWidth": "100px", "aTargets": [6] },
{ "sWidth": "150px", "aTargets": [7] }
{ "sWidth": "60px", "aTargets": [0,2,3,9,10] },
{ "sWidth": "35px", "aTargets": [1,6,11] },
{ "sWidth": "100px", "aTargets": [5,7] },
{ "sWidth": "150px", "aTargets": [8] }
],
"oLanguage": (datatable_lang != "") ?
{
@ -1108,7 +1118,7 @@ $(document).ready(function(){
dataTable_images.fnClearTable();
addElement([
spinner,
'','','','','','','','','',''],dataTable_images);
'','','','','','','','','','',''],dataTable_images);
Sunstone.runAction("Image.list");
setupCreateImageDialog();

View File

@ -599,21 +599,21 @@ var update_template_tmpl =
<td style="width:40px;text-align:center;">'+tr("Admin")+'</td></tr></thead>\
<tr>\
<td>'+tr("Owner")+'</td>\
<td style="text-align:center"><input type="checkbox" name="vnet_owner_u" class="owner_u" /></td>\
<td style="text-align:center"><input type="checkbox" name="vnet_owner_m" class="owner_m" /></td>\
<td style="text-align:center"><input type="checkbox" name="vnet_owner_a" class="owner_a" /></td>\
<td style="text-align:center"><input type="checkbox" name="template_owner_u" class="owner_u" /></td>\
<td style="text-align:center"><input type="checkbox" name="template_owner_m" class="owner_m" /></td>\
<td style="text-align:center"><input type="checkbox" name="template_owner_a" class="owner_a" /></td>\
</tr>\
<tr>\
<td>'+tr("Group")+'</td>\
<td style="text-align:center"><input type="checkbox" name="vnet_group_u" class="group_u" /></td>\
<td style="text-align:center"><input type="checkbox" name="vnet_group_m" class="group_m" /></td>\
<td style="text-align:center"><input type="checkbox" name="vnet_group_a" class="group_a" /></td>\
<td style="text-align:center"><input type="checkbox" name="template_group_u" class="group_u" /></td>\
<td style="text-align:center"><input type="checkbox" name="template_group_m" class="group_m" /></td>\
<td style="text-align:center"><input type="checkbox" name="template_group_a" class="group_a" /></td>\
</tr>\
<tr>\
<td>'+tr("Other")+'</td>\
<td style="text-align:center"><input type="checkbox" name="vnet_other_u" class="other_u" /></td>\
<td style="text-align:center"><input type="checkbox" name="vnet_other_m" class="other_m" /></td>\
<td style="text-align:center"><input type="checkbox" name="vnet_other_a" class="other_a" /></td>\
<td style="text-align:center"><input type="checkbox" name="template_other_u" class="other_u" /></td>\
<td style="text-align:center"><input type="checkbox" name="template_other_m" class="other_m" /></td>\
<td style="text-align:center"><input type="checkbox" name="template_other_a" class="other_a" /></td>\
</tr>\
</table>\
</div>\
@ -624,7 +624,7 @@ var update_template_tmpl =
<fieldset>\
<div class="form_buttons">\
<button class="button" id="template_template_update_button" value="Template.update_template">\
Update\
'+tr("Update")+'\
</button>\
</div>\
</fieldset>\
@ -956,7 +956,7 @@ function updateTemplateInfo(request,template){
<td class="key_td">'+tr("Register time")+'</td>\
<td class="value_td">'+pretty_time(template_info.REGTIME)+'</td>\
</tr>\
<tr><td class="key_td">Permissions</td><td></td></tr>\
<tr><td class="key_td">'+tr("Permissions")+'</td><td></td></tr>\
<tr>\
<td class="key_td">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+tr("Owner")+'</td>\
<td class="value_td" style="font-family:monospace;">'+ownerPermStr(template_info)+'</td>\
@ -2088,7 +2088,6 @@ function setupTemplateTemplateUpdateDialog(){
Sunstone.runAction("Template.update",id,new_template);
$(this).parents('#template_template_update_dialog').dialog('close');
dialog.dialog('close');
return false;
});
};

View File

@ -1302,7 +1302,6 @@ $(document).ready(function(){
setupSaveasDialog();
setVMAutorefresh();
setupVNC();
setupTips
initCheckAllBoxes(dataTable_vMachines);
tableCheckboxesListener(dataTable_vMachines);

View File

@ -587,7 +587,7 @@ function updateVNetworkInfo(request,vn){
<td class="key_td">'+tr("VLAN ID")+'</td>\
<td class="value_td">'+ (typeof(vn_info.VLAN_ID) == "object" ? "--": vn_info.VLAN_ID) +'</td>\
</tr>\
<tr><td class="key_td">Permissions</td><td></td></tr>\
<tr><td class="key_td">'+tr("Permissions")+'</td><td></td></tr>\
<tr>\
<td class="key_td">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+tr("Owner")+'</td>\
<td class="value_td" style="font-family:monospace;">'+ownerPermStr(vn_info)+'</td>\

View File

@ -751,6 +751,12 @@ function hosts_sel(){
return hosts_select;
}
function clusters_sel() {
return clusters_select;
}
function ownerUse(resource){
return parseInt(resource.PERMISSIONS.OWNER_U);
};