diff --git a/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb b/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb
index fcc71d8e2f..a0fe9146b3 100644
--- a/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb
+++ b/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb
@@ -48,6 +48,7 @@ module OpenNebulaJSON
when "unpublish" then self.unpublish
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'])
when "hold" then self.hold(action_hash['params'])
when "release" then self.release(action_hash['params'])
else
@@ -73,6 +74,10 @@ module OpenNebulaJSON
super(params['owner_id'].to_i,params['group_id'].to_i)
end
+ def chmod_octet(params=Hash.new)
+ super(params['octet'])
+ end
+
def hold(params=Hash.new)
super(params['ip'])
end
diff --git a/src/sunstone/public/js/opennebula.js b/src/sunstone/public/js/opennebula.js
index 3956b35752..390fb127cc 100644
--- a/src/sunstone/public/js/opennebula.js
+++ b/src/sunstone/public/js/opennebula.js
@@ -491,6 +491,13 @@ var OpenNebula = {
"chgrp" : function(params){
OpenNebula.Action.chgrp(params,OpenNebula.Network.resource);
},
+ "chmod" : function(params){
+ var action_obj = params.data.extra_param;
+ OpenNebula.Action.simple_action(params,
+ OpenNebula.Network.resource,
+ "chmod",
+ action_obj);
+ },
"publish": function(params){
OpenNebula.Action.simple_action(params,OpenNebula.Network.resource,"publish");
},
diff --git a/src/sunstone/public/js/plugins/vnets-tab.js b/src/sunstone/public/js/plugins/vnets-tab.js
index 5e3ba99707..ab84ee4282 100644
--- a/src/sunstone/public/js/plugins/vnets-tab.js
+++ b/src/sunstone/public/js/plugins/vnets-tab.js
@@ -30,7 +30,6 @@ var vnets_tab_content =
'+tr("Name")+' | \
'+tr("Type")+' | \
'+tr("Bridge")+' | \
- '+tr("Public")+' | \
'+tr("Total Leases")+' | \
\
\
@@ -149,8 +148,31 @@ var update_vnet_tmpl =
\
\
\
-
\
-
\
+
\
\
\
\
@@ -299,6 +321,14 @@ var vnet_actions = {
notify: true
},
+ "Network.chmod" : {
+ type: "multiple",
+ call: OpenNebula.Network.chmod,
+// callback
+ error: onError,
+ notify: true
+ },
+
"Network.fetch_template" : {
type: "single",
call: OpenNebula.Network.fetch_template,
@@ -308,11 +338,20 @@ var vnet_actions = {
error: onError
},
+ "Network.fetch_permissions" : {
+ type: "single",
+ call: OpenNebula.Network.show,
+ callback: function(request,vnet_json){
+ var dialog = $('#vnet_template_update_dialog form');
+ var vnet = vnet_json.VNET;
+ setPermissionsTable(vnet,dialog);
+ },
+ error: onError
+ },
+
"Network.update_dialog" : {
type: "custom",
- call: function() {
- popUpVNetTemplateUpdateDialog();
- }
+ call: popUpVNetTemplateUpdateDialog
},
"Network.update" : {
@@ -341,20 +380,10 @@ var vnet_buttons = {
"Network.update_dialog" : {
type: "action",
- text: tr("Update a template"),
+ text: tr("Update properties"),
alwaysActive: true
},
- "Network.publish" : {
- type: "action",
- text: tr("Publish")
- },
-
- "Network.unpublish" : {
- type: "action",
- text: tr("Unpublish")
- },
-
"Network.chown" : {
type: "confirm_with_select",
text: tr("Change owner"),
@@ -419,8 +448,6 @@ function vNetworkElementArray(vn_json){
network.NAME,
parseInt(network.TYPE) ? "FIXED" : "RANGED",
network.BRIDGE,
- parseInt(network.PUBLIC) ? ''
- : '',
network.TOTAL_LEASES ];
}
@@ -500,10 +527,6 @@ function updateVNetworkInfo(request,vn){
'+tr("Group")+' | \
'+vn_info.GNAME+' | \
\
- \
- '+tr("Public")+' | \
- '+(parseInt(vn_info.PUBLIC) ? "yes" : "no" )+' | \
-
\
\
'+tr("Physical device")+' | \
'+ (typeof(vn_info.PHYDEV) == "object" ? "--": vn_info.PHYDEV) +' | \
@@ -512,6 +535,19 @@ function updateVNetworkInfo(request,vn){
'+tr("VNET ID")+' | \
'+ (typeof(vn_info.VLAN_ID) == "object" ? "--": vn_info.VLAN_ID) +' | \
\
+ | |
\
+ \
+ '+tr("Owner permissions")+' | \
+ '+ownerPermStr(vn_info)+' | \
+
\
+ \
+ '+tr("Group permissions")+' | \
+ '+groupPermStr(vn_info)+' | \
+
\
+ \
+ '+tr("Other permissions")+' | \
+ '+otherPermStr(vn_info)+' | \
+
\
';
info_tab_content += '\
@@ -842,13 +878,15 @@ function setupVNetTemplateUpdateDialog(){
//Put HTML in place
dialog.html(update_vnet_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:700,
modal:true,
- height:480,
- resizable:false,
+ height:height,
+ resizable:true,
});
$('button',dialog).button();
@@ -857,24 +895,22 @@ function setupVNetTemplateUpdateDialog(){
var id = $(this).val();
if (id && id.length){
var dialog = $('#vnet_template_update_dialog');
+ $('.permissions_table input',dialog).removeAttr('checked')
$('#vnet_template_update_textarea',dialog).val(tr("Loading")+"...");
- var vnet_public = is_public_vnet(id);
-
- if (vnet_public){
- $('#vnet_template_update_public',dialog).attr('checked','checked')
- } else {
- $('#vnet_template_update_public',dialog).removeAttr('checked')
- }
-
+ Sunstone.runAction("Network.fetch_permissions",id);
Sunstone.runAction("Network.fetch_template",id);
} else {
$('#vnet_template_update_textarea',dialog).val("");
};
});
- $('#vnet_template_update_button',dialog).click(function(){
- var dialog = $('#vnet_template_update_dialog');
+ $('.permissions_table input',dialog).change(function(){
+ $(this).parents('table').attr('update','update');
+ });
+
+ $('form',dialog).submit(function(){
+ var dialog = $(this);
var new_template = $('#vnet_template_update_textarea',dialog).val();
var id = $('#vnet_template_update_select',dialog).val();
if (!id || !id.length) {
@@ -882,17 +918,16 @@ function setupVNetTemplateUpdateDialog(){
return false;
};
- var old_public = is_public_vnet(id);
-
- var new_public = $('#vnet_template_update_public:checked',dialog).length;
-
- if (old_public != new_public){
- if (new_public) Sunstone.runAction("Network.publish",id);
- else Sunstone.runAction("Network.unpublish",id);
+ var permissions = $('.permissions_table');
+ if (permissions.attr('update')){
+ var perms = {
+ octet : buildOctet(permissions)
+ };
+ Sunstone.runAction("Network.chmod",id,perms);
};
Sunstone.runAction("Network.update",id,new_template);
- dialog.dialog('close');
+ $(this).parents('#vnet_template_update_dialog').dialog('close');
return false;
});
};
@@ -910,7 +945,7 @@ function popUpVNetTemplateUpdateDialog(){
var dialog = $('#vnet_template_update_dialog');
$('#vnet_template_update_select',dialog).html(select);
$('#vnet_template_update_textarea',dialog).val("");
- $('#vnet_template_update_public',dialog).removeAttr('checked')
+ $('.permissions_table input',dialog).removeAttr('checked')
if (sel_elems.length >= 1){ //several items in the list are selected
//grep them
@@ -999,23 +1034,6 @@ function setVNetAutorefresh() {
},INTERVAL+someTime());
};
-function is_public_vnet(id) {
- var data = getElementData(id,"#vnetwork",dataTable_vNetworks)[7];
- return $(data).is(":checked");
-};
-
-function setupVNetActionCheckboxes(){
- $('input.action_cb#cb_public_vnet',dataTable_vNetworks).live("click",function(){
- var $this = $(this)
- var id=$this.attr('elem_id');
- if ($this.attr('checked'))
- Sunstone.runAction("Network.publish",id);
- else Sunstone.runAction("Network.unpublish",id);
-
- return true;
- });
-}
-
//The DOM is ready and the ready() from sunstone.js
//has been executed at this point.
$(document).ready(function(){
@@ -1027,7 +1045,7 @@ $(document).ready(function(){
"sPaginationType": "full_numbers",
"aoColumnDefs": [
{ "bSortable": false, "aTargets": ["check"] },
- { "sWidth": "60px", "aTargets": [0,5,6,7,8] },
+ { "sWidth": "60px", "aTargets": [0,5,6,7] },
{ "sWidth": "35px", "aTargets": [1] },
{ "sWidth": "100px", "aTargets": [2,3] }
],
@@ -1040,13 +1058,12 @@ $(document).ready(function(){
dataTable_vNetworks.fnClearTable();
addElement([
spinner,
- '','','','','','','',''],dataTable_vNetworks);
+ '','','','','','',''],dataTable_vNetworks);
Sunstone.runAction("Network.list");
setupCreateVNetDialog();
setupVNetTemplateUpdateDialog();
setupLeasesOps();
- setupVNetActionCheckboxes();
setVNetAutorefresh();
initCheckAllBoxes(dataTable_vNetworks);
diff --git a/src/sunstone/public/js/sunstone-util.js b/src/sunstone/public/js/sunstone-util.js
index 7938deb026..d1f2669bad 100644
--- a/src/sunstone/public/js/sunstone-util.js
+++ b/src/sunstone/public/js/sunstone-util.js
@@ -16,7 +16,7 @@
/* Some useful functions for Sunstone default plugins */
-var INTERVAL=60000; //milisecs
+var INTERVAL=300000; //milisecs
function someTime(){
return Math.floor(Math.random()*30000);
@@ -743,3 +743,126 @@ function groups_sel(){
function hosts_sel(){
return hosts_select;
}
+
+function ownerUse(resource){
+ return parseInt(resource.PERMISSIONS.OWNER_U);
+};
+function ownerManage(resource){
+ return parseInt(resource.PERMISSIONS.OWNER_M);
+};
+function ownerAdmin(resource){
+ return parseInt(resource.PERMISSIONS.OWNER_A);
+};
+
+function groupUse(resource){
+ return parseInt(resource.PERMISSIONS.GROUP_U);
+};
+function groupManage(resource){
+ return parseInt(resource.PERMISSIONS.GROUP_M);
+};
+function groupAdmin(resource){
+ return parseInt(resource.PERMISSIONS.GROUP_A);
+};
+
+function otherUse(resource){
+ return parseInt(resource.PERMISSIONS.OTHER_U);
+};
+function otherManage(resource){
+ return parseInt(resource.PERMISSIONS.OTHER_M);
+};
+function otherAdmin(resource){
+ return parseInt(resource.PERMISSIONS.OTHER_A);
+};
+
+
+function ownerPermStr(resource){
+ var result = "";
+ if (ownerUse(resource))
+ result += tr("Use")+", ";
+ if (ownerManage(resource))
+ result += tr("Manage")+", ";
+ if (ownerAdmin(resource))
+ result += tr("Administrate")+", ";
+
+ //Remove ", " from end
+ result = result.substring(0,result.length-2);
+ return result;
+};
+
+function groupPermStr(resource){
+ var result = "";
+ if (groupUse(resource))
+ result += tr("Use")+", ";
+ if (groupManage(resource))
+ result += tr("Manage")+", ";
+ if (groupAdmin(resource))
+ result += tr("Administrate")+", ";
+
+ //Remove ", " from end
+ result = result.substring(0,result.length-2);
+ return result;
+};
+
+function otherPermStr(resource){
+ var result = "";
+ if (otherUse(resource))
+ result += tr("Use")+", ";
+ if (otherManage(resource))
+ result += tr("Manage")+", ";
+ if (otherAdmin(resource))
+ result += tr("Administrate")+", ";
+
+ //Remove ", " from end
+ result = result.substring(0,result.length-2);
+ return result;
+};
+
+function setPermissionsTable(resource,context){
+ if (ownerUse(resource))
+ $('.owner_u',context).attr('checked','checked');
+ if (ownerManage(resource))
+ $('.owner_m',context).attr('checked','checked');
+ if (ownerAdmin(resource))
+ $('.owner_a',context).attr('checked','checked');
+ if (groupUse(resource))
+ $('.group_u',context).attr('checked','checked');
+ if (groupManage(resource))
+ $('.group_m',context).attr('checked','checked');
+ if (groupAdmin(resource))
+ $('.group_a',context).attr('checked','checked');
+ if (otherUse(resource))
+ $('.other_u',context).attr('checked','checked');
+ if (otherManage(resource))
+ $('.other_m',context).attr('checked','checked');
+ if (otherAdmin(resource))
+ $('.other_a',context).attr('checked','checked');
+};
+
+function buildOctet(permTable){
+ var owner=0;
+ var group=0;
+ var other=0;
+
+ if ($('.owner_u',permTable).is(':checked'))
+ owner+=4;
+ if ($('.owner_m',permTable).is(':checked'))
+ owner+=2;
+ if ($('.owner_a',permTable).is(':checked'))
+ owner+=1;
+
+ if ($('.group_u',permTable).is(':checked'))
+ group+=4;
+ if ($('.group_m',permTable).is(':checked'))
+ group+=2;
+ if ($('.group_a',permTable).is(':checked'))
+ group+=1;
+
+ if ($('.other_u',permTable).is(':checked'))
+ other+=4;
+ if ($('.other_m',permTable).is(':checked'))
+ other+=2;
+ if ($('.other_a',permTable).is(':checked'))
+ other+=1;
+
+ return ""+owner+group+other;
+};
\ No newline at end of file