From eccae0e73126d5571cd138a782d5ba0e58aa0e22 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Wed, 7 Dec 2011 01:18:13 +0100 Subject: [PATCH] Task #864, Feature #602: Improve leases support in Sunstone and new vnet operations in Sunstone This commit includes: * Support for ip_start, ip_end parameters when creating ranged vnetworks. * Removal of the add lease/remove lease dialogs. * Renewal of the representation of leases pool in the "extended information" windows. The list of leases is represented so that it is clearly visible those leases which are free, on hold (reserved), or used by a VM. Right on the list, leases can be added, updated or deleted. --- .../OpenNebulaJSON/VirtualNetworkJSON.rb | 12 +- src/sunstone/public/images/green_bullet.png | Bin 0 -> 484 bytes src/sunstone/public/images/red_bullet.png | Bin 0 -> 484 bytes src/sunstone/public/images/yellow_bullet.png | Bin 0 -> 449 bytes src/sunstone/public/js/opennebula.js | 14 + src/sunstone/public/js/plugins/vnets-tab.js | 250 ++++++++++++++++-- 6 files changed, 246 insertions(+), 30 deletions(-) create mode 100644 src/sunstone/public/images/green_bullet.png create mode 100644 src/sunstone/public/images/red_bullet.png create mode 100644 src/sunstone/public/images/yellow_bullet.png diff --git a/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb b/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb index b18230f2ac..fcc71d8e2f 100644 --- a/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/VirtualNetworkJSON.rb @@ -43,11 +43,13 @@ module OpenNebulaJSON rc = case action_hash['perform'] when "addleases" then self.addleases(action_hash['params']) - when "rmleases" then self.rmleases(action_hash['params']) + when "rmleases" then self.rmleases(action_hash['params']) when "publish" then self.publish when "unpublish" then self.unpublish when "update" then self.update(action_hash['params']) when "chown" then self.chown(action_hash['params']) + when "hold" then self.hold(action_hash['params']) + when "release" then self.release(action_hash['params']) else error_msg = "#{action_hash['perform']} action not " << " available for this resource" @@ -70,5 +72,13 @@ module OpenNebulaJSON def chown(params=Hash.new) super(params['owner_id'].to_i,params['group_id'].to_i) end + + def hold(params=Hash.new) + super(params['ip']) + end + + def release(params=Hash.new) + super(params['ip']) + end end end diff --git a/src/sunstone/public/images/green_bullet.png b/src/sunstone/public/images/green_bullet.png new file mode 100644 index 0000000000000000000000000000000000000000..d64f9dbf9d6c519d56a1128452779baf5b323db0 GIT binary patch literal 484 zcmeAS@N?(olHy`uVBq!ia0vp^JRr=$1SD^YpWXnZ7>k44ofy`glX(f`a29w(7Bet# z3xhBt!>l_iO9UAn2wYz}S4_HU zN%TR!vul06)J$wG6jRfhX2#0EUTw#%a$nN!<4a55vqckI`P+BDu(+N3-7AVAfiG{) z)%#zV7&IQ0EM8>6z4&p?ZjoOZj0_B$$~T{Ed3V2hNwl(^Sk=@O72EIrmrzyPp7eKT zSpVxkoZiYyd{3Xs=i;VuD`Z|32!d- zooCt}smwEVs(iD-lSyUEi#nroZajb7;QzX|jninAhK>T)nyw02_L{2D-AmFVdQ&MBb@0FFAlQ2+n{ literal 0 HcmV?d00001 diff --git a/src/sunstone/public/images/red_bullet.png b/src/sunstone/public/images/red_bullet.png new file mode 100644 index 0000000000000000000000000000000000000000..b8317a77cff95bffdd8857b21363a6c55233488b GIT binary patch literal 484 zcmVPx#32;bRa{vGf6951U69E94oEQKA00(qQO+^RW3ul(NKH zK#WntA(IJF#L0=qIkJq!g5{DdJ4hHqlJN4vbV`zFs*1&ehX>|!@|^u1P^YId8c9(o z5fucQG-bJDKIicf?>S(tG>z*z9Yy`YKvR}v8F`NP0_xME=l#cO)uw5ardq63)_z_< z01#-Qac*DN&1$9jj}9!nLIWG;?0Vf(#$b$u;RhUITiC%4iXfk44ofy`glX(f`a29w(7Bet# z3xhBt!>lS|xv6<2KrRD=b5UwyNotBh zd1gt5g1e`0K#E=}JJ4_~PZ!4!iOZ=M&-xv5U~qkCocgOf$=Ae9r9~n+M)J`m_79vj zVew7A*N-?j3-Ic-WG!EMdFC#Li%0TnC+*&GNUAq5M{EV>Q<=R?1<6fv7gg(~hp8BL zDXDs&5bC;_FY@gr&r2Ro_DN@(bP|7FS>wLKL|=M=EXSfojWmWn^+4fGOCtMA%ydno z=es_BxiVi{u;ink%qh#GJX7CwuU&O)h4?4KpEn%WUs(P2)V!?`-pevhg?~yvX@4zA zdXIsS9;k@uG*n?&o(yV3)<=6qpa>%k)K52K6u6{1-oD!M\ \
\ - \ - \ + \ +
\ + \ +
\ + \ +
\ + \ + \ \ \ \ @@ -95,9 +101,9 @@ var create_vn_tmpl =
\
\ \ - \ +
\ \ - \ +
\ \ \
\ @@ -248,7 +254,7 @@ var vnet_actions = { call: OpenNebula.Network.addleases, callback: vnShow, error: onError, - notify: true + notify: false, }, "Network.rmleases" : { @@ -256,9 +262,25 @@ var vnet_actions = { call: OpenNebula.Network.rmleases, callback: vnShow, error: onError, - notify: true + notify: false, }, + "Network.hold" : { + type: "single", + call: OpenNebula.Network.hold, + callback: vnShow, + error: onError, + notify: false, + }, + + "Network.release" : { + type: "single", + call: OpenNebula.Network.release, + callback: vnShow, + error: onError, + notify: false, + }, +/* "Network.modifyleases" : { type: "custom", call: function(action,obj){ @@ -278,7 +300,7 @@ var vnet_actions = { type: "custom", call: popUpRemoveLeaseDialog }, - +*/ "Network.chown" : { type: "multiple", call: OpenNebula.Network.chown, @@ -368,7 +390,7 @@ var vnet_buttons = { tip: "Select the new group:", condition: mustBeAdmin, }, - +/* "action_list" : { type: "select", actions: { @@ -382,7 +404,7 @@ var vnet_buttons = { } } }, - +*/ "Network.delete" : { type: "action", text: "Delete" @@ -455,6 +477,9 @@ function updateVNetworkElement(request, vn_json){ id = vn_json.VNET.ID; element = vNetworkElementArray(vn_json); updateSingleElement(element,dataTable_vNetworks,'#vnetwork_'+id); + + //we update this too, even if it's not shown. + $('#leases_form').replaceWith(printLeases(vn_json.VNET)); } //Callback to delete a vnet element from the table @@ -466,6 +491,8 @@ function deleteVNetworkElement(req){ function addVNetworkElement(request,vn_json){ var element = vNetworkElementArray(vn_json); addElement(element,dataTable_vNetworks); + //we update this too, even if it's not shown. + $('#leases_form').replaceWith(printLeases(vn_json.VNET)); } //updates the list of virtual networks @@ -494,6 +521,10 @@ function updateVNetworkInfo(request,vn){ ID\ '+vn_info.ID+'\ \ + \ + Name\ + '+vn_info.NAME+'\ + \ \ Owner\ '+vn_info.UNAME+'\ @@ -508,17 +539,15 @@ function updateVNetworkInfo(request,vn){ \ \ Physical device\ - '+(vn_info.PHYDEV ? vn_info.PHYDEV : "--" )+'\ + '+ (typeof(vn_info.PHYDEV) == "object" ? "--": vn_info.PHYDEV) +'\ \ - \ - \ - \ - \ - '+ - printLeases(vn_info.LEASES)+ - '
Leases information
';; - + \ + VNET ID\ + '+ (typeof(vn_info.VLAN_ID) == "object" ? "--": vn_info.VLAN_ID) +'\ + \ + '; + info_tab_content += printLeases(vn_info); var info_tab = { title: "Virtual Network information", @@ -541,19 +570,101 @@ function updateVNetworkInfo(request,vn){ } -function printLeases(leases){ - if (!leases.LEASE) //empty - { - return ""; +function printLeases(vn_info){ + var html ='
\ + \ + \ + '; + + if (vn_info.TYPE == "0"){ + html += '\ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + \ + '; + } else { + html += ''; }; - if (leases.LEASE.constructor == Array) //>1 lease + var leases = vn_info.LEASES.LEASE; + + if (!leases) //empty { - return prettyPrintJSON(leases.LEASE); + html+='\ + '; + return html; } - else {//1 lease - return prettyPrintJSON([leases.LEASE]); + else if (leases.constructor != Array) //>1 lease + { + leases = [leases]; }; + + var lease; + var state=null; + + for (var i=0; i'; + }; + + html += '
Leases information
IP Start'+vn_info.RANGE.IP_START+'
IP End'+vn_info.RANGE.IP_END+'
Network mask'+( vn_info.TEMPLATE.NETWORK_MASK ? vn_info.TEMPLATE.NETWORK_MASK : "--" )+'
\ + \ + \ +
\ + \ + \ +
\ + No leases to show\ + \ +
'; + html+=''; + + html += '\ + '+lease.MAC+'   '; + + switch (state){ + case 0: + html += 'hold | delete'; + break; + case 1: + html += 'Used by VM '+lease.VID; + break; + case 2: + html += 'release'; + break; + }; + html += '
'; + + return html; } //Prepares the vnet creation dialog @@ -622,6 +733,17 @@ function setupCreateVNetDialog() { return false; }); + $('#custom_pool', dialog).change(function(){ + if ($(this).is(':checked')){ + $('#ip_start', $create_vn_dialog).removeAttr('disabled'); + $('#ip_end', $create_vn_dialog).removeAttr('disabled'); + } + else { + $('#ip_start', $create_vn_dialog).attr('disabled','disabled'); + $('#ip_end', $create_vn_dialog).attr('disabled','disabled'); + }; + }); + $('#add_custom_var_vnet_button', dialog).click( function(){ @@ -681,7 +803,11 @@ function setupCreateVNetDialog() { else { //type ranged var network_addr = $('#net_address',this).val(); - var network_size = $('#net_size',this).val(); + var network_mask = $('#net_mask',this).val(); + var custom = $('#custom_pool',this).is(':checked'); + var ip_start = $('#ip_start',this).val(); + var ip_end = $('#ip_end',this).val(); + if (!network_addr.length){ notifyError("Please provide a network address"); return false; @@ -692,10 +818,17 @@ function setupCreateVNetDialog() { "vnet" : { "type" : "RANGED", "bridge" : bridge, - "network_size" : network_size, + "network_mask" : network_mask, "network_address" : network_addr, "name" : name } }; + + if (custom){ + if (ip_start.length) + network_json["vnet"]["ip_start"] = ip_start; + if (ip_end.length) + network_json["vnet"]["ip_start"] = ip_end; + }; }; //Time to add custom attributes @@ -826,6 +959,62 @@ function popUpVNetTemplateUpdateDialog(){ } +function setupLeasesOps(){ + $('button#panel_add_lease_button').live("click",function(){ + var lease = $(this).prev().val(); + //var mac = $(this).previous().val(); + var id = $(this).parents('form').attr('vnid'); + if (lease.length){ + var obj = {ip: lease}; + Sunstone.runAction('Network.addleases',id,obj); + } + return false; + }); + + $('button#panel_hold_lease_button').live("click",function(){ + var lease = $(this).prev().val(); + //var mac = $(this).previous().val(); + var id = $(this).parents('form').attr('vnid'); + if (lease.length){ + var obj = {ip: lease}; + Sunstone.runAction('Network.hold',id,obj); + } + return false; + }); + + $('form#leases_form a.delete_lease').live("click",function(){ + var lease = $(this).parents('tr').attr('ip'); + var id = $(this).parents('form').attr('vnid'); + var obj = { ip: lease}; + Sunstone.runAction('Network.rmleases',id,obj); + //Set spinner + $(this).parents('tr').html(''+spinner+''); + return false; + }); + + $('a.hold_lease').live("click",function(){ + var lease = $(this).parents('tr').attr('ip'); + var id = $(this).parents('form').attr('vnid'); + var obj = { ip: lease}; + Sunstone.runAction('Network.hold',id,obj); + //Set spinner + $(this).parents('tr').html(''+spinner+''); + return false; + }); + + $('a.release_lease').live("click",function(){ + var lease = $(this).parents('tr').attr('ip'); + var id = $(this).parents('form').attr('vnid'); + var obj = { ip: lease}; + Sunstone.runAction('Network.release',id,obj); + //Set spinner + $(this).parents('tr').html(''+spinner+''); + return false; + }); +} + + +/* function setupAddRemoveLeaseDialog() { dialogs_context.append('
'); $lease_vn_dialog = $('#lease_vn_dialog',dialogs_context) @@ -893,6 +1082,8 @@ function popUpRemoveLeaseDialog() { $lease_vn_dialog.dialog("open"); } +*/ + function setVNetAutorefresh() { setInterval(function(){ var checked = $('input.check_item:checked',dataTable_vNetworks); @@ -946,7 +1137,8 @@ $(document).ready(function(){ setupCreateVNetDialog(); setupVNetTemplateUpdateDialog(); - setupAddRemoveLeaseDialog(); + //setupAddRemoveLeaseDialog(); + setupLeasesOps(); setupVNetActionCheckboxes(); setVNetAutorefresh();