diff --git a/src/cloud/occi/lib/occi-server.rb b/src/cloud/occi/lib/occi-server.rb index 3c84e43d81..85df192ca9 100755 --- a/src/cloud/occi/lib/occi-server.rb +++ b/src/cloud/occi/lib/occi-server.rb @@ -123,6 +123,18 @@ before do end end +after do + unless request.path=='/ui/login' || request.path=='/ui' + unless session[:remember] + if params[:timeout] == true + env['rack.session.options'][:defer] = true + else + env['rack.session.options'][:expire_after] = 60*10 + end + end + end +end + # Response treatment helpers do def authorized? @@ -141,8 +153,29 @@ helpers do else client = settings.cloud_auth.client(username) @occi_server = OCCIServer.new(client, settings.config) + + user_id = OpenNebula::User::SELF + user = OpenNebula::User.new_with_id(user_id, client) + rc = user.info + if OpenNebula.is_error?(rc) + # Add a log message + return [500, ""] + end + session[:ip] = request.ip session[:user] = username + session[:remember] = params[:remember] + + if user['TEMPLATE/LANG'] + session[:lang] = user['TEMPLATE/LANG'] + else + session[:lang] = settings.config[:lang] + end + + if params[:remember] + env['rack.session.options'][:expire_after] = 30*60*60*24 + end + return [204, ""] end end @@ -295,8 +328,12 @@ get '/ui' do return File.read(File.dirname(__FILE__)+'/ui/templates/login.html') end + time = Time.now + 60 + response.set_cookie("occi-user", + :value=>"#{session[:user]}", + :expires=>time) + erb :index - #return File.read(File.dirname(__FILE__)+'/ui/templates/index.html') end post '/ui/upload' do diff --git a/src/cloud/occi/lib/ui/public/js/occi.js b/src/cloud/occi/lib/ui/public/js/occi.js index 2fe3c61ff2..fba3b39144 100644 --- a/src/cloud/occi/lib/ui/public/js/occi.js +++ b/src/cloud/occi/lib/ui/public/js/occi.js @@ -50,21 +50,11 @@ var OCCI = { "Error": function(resp) { - var error = {}; - if (resp.responseText) - { - try { - error = JSON.parse(resp.responseText); - } - catch (e) { - error.error = {message: "It appears there was a server exception. Please check server's log."}; - }; - } - else - { - error.error = {}; - } - error.error.http_status = resp.status; + var error = { + error : { + message: resp.responseText, + http_status : resp.status} + }; return error; }, @@ -484,7 +474,7 @@ var OCCI = { var im_name = obj.image_name; params.data.body = ''; OCCI.Action.update(params,OCCI.VM.resource,"saveas"); - } + }, /* "vnc" : function(params,startstop){ var callback = params.success; var callback_error = params.error; @@ -619,4 +609,11 @@ var OCCI = { } }, + "Instance_type" : { + "resource" : "INSTANCE_TYPE", + "list" : function(params){ + OCCI.Action.list(params,OCCI.Instance_type.resource); + }, + }, + } diff --git a/src/cloud/occi/lib/ui/public/js/plugins/compute.js b/src/cloud/occi/lib/ui/public/js/plugins/compute.js index e7c510c783..44f5066e10 100644 --- a/src/cloud/occi/lib/ui/public/js/plugins/compute.js +++ b/src/cloud/occi/lib/ui/public/js/plugins/compute.js @@ -75,9 +75,7 @@ var create_vm_tmpl ='
\
\ \
\
\
\ @@ -170,7 +168,7 @@ var vm_actions = { "VM.suspend" : { type: "multiple", call: OCCI.VM.suspend, - callback: vmShow, + //callback: vmShow, elements: vmElements, error: onError, notify: true @@ -179,7 +177,7 @@ var vm_actions = { "VM.resume" : { type: "multiple", call: OCCI.VM.resume, - callback: vmShow, + //callback: vmShow, elements: vmElements, error: onError, notify: true @@ -188,7 +186,7 @@ var vm_actions = { "VM.stop" : { type: "multiple", call: OCCI.VM.stop, - callback: vmShow, + //callback: vmShow, elements: vmElements, error: onError, notify: true @@ -197,7 +195,7 @@ var vm_actions = { "VM.done" : { type: "multiple", call: OCCI.VM.done, - callback: vmShow, + //callback: vmShow, elements: vmElements, error: onError, notify: true @@ -206,7 +204,7 @@ var vm_actions = { "VM.shutdown" : { type: "multiple", call: OCCI.VM.shutdown, - callback: vmShow, + //callback: vmShow, elements: vmElements, error: onError, notify: true @@ -215,7 +213,7 @@ var vm_actions = { "VM.cancel" : { type: "multiple", call: OCCI.VM.cancel, - callback: vmShow, + //callback: vmShow, elements: vmElements, error: onError, notify: true @@ -232,7 +230,7 @@ var vm_actions = { "VM.saveas" : { type: "single", call: OCCI.VM.saveas, - callback: vmShow, + //callback: vmShow, error:onError }, @@ -242,6 +240,23 @@ var vm_actions = { callback: saveasDisksCallback, error: onError }, + "VM.getInstanceTypes" : { + type: "list", + call: OCCI.Instance_type.list, + callback: function(request,response){ + if (response.constructor != Array){ + response = [response]; + }; + var options = ""; + for (var i = 0; i'+type+''; + }; + $('#dialog select#instance_type').html(options); + }, + error: onError + }, + /* "VM.startvnc" : { type: "single", @@ -338,7 +353,15 @@ var vm_buttons = { var vm_info_panel = { "vm_info_tab" : { - title: tr("Compute resource information"), + title: tr("Compute resource"), + content: "" + }, + "vm_disks_tab" : { + title: tr("Disks"), + content: "" + }, + "vm_networks_tab" : { + title: tr("Networks"), content: "" }, } @@ -366,10 +389,6 @@ function vmElements() { return getSelectedNodes(dataTable_vMachines); } -function vmShow(req) { -// Sunstone.runAction("VM.show",req.request.data[0]); -} - // Returns a human readable running time for a VM function str_start_time(vm){ return pretty_time(vm.STIME); @@ -466,9 +485,13 @@ function updateVMInfo(request,vm){ '+tr("Name")+'\ '+vm_info.NAME+'\ \ + \ + '+tr("Instance type")+'\ + '+vm_info.INSTANCE_TYPE+'\ + \ \ '+tr("State")+'\ - '+tr(vm_state)+'\ + '+tr(vm_info.STATE)+'\ \ \ '+tr("CPU")+'\ @@ -482,7 +505,95 @@ function updateVMInfo(request,vm){ \
\
' - } + }; + + var disks_str = '\ +\ +\ +'; + + var disks = vm_info.DISK; + if (disks){ + if (disks.constructor != Array) // 1lease + disks = [disks]; + + for (var i=0;i\ +\ +\ +\ +\ +\ +\ +\ +\ +\ +\ +\ +\ +\ +'; + }; + + } else { + disks_str += ''; + }; + + disks_str += '
'+tr("Disks information")+'
'+disks[i].id+'
'+tr("Name")+''+disks[i].STORAGE.name+'
'+tr("Target")+''+disks[i].TARGET+'
'+tr("Type")+''+disks[i].TYPE+'
'+ + tr("No disks defined")+'
\ +
\ +
'; + + var disks_tab = { + title : tr("Disks"), + content : disks_str + }; + + var networks_str = '\ +\ +\ +'; + + var networks = vm_info.NIC; + if (networks){ + if (networks.constructor != Array) // 1lease + networks = [networks]; + + for (var i=0;i\ +\ +\ +\ +\ +\ +\ +\ +\ +\ +\ +\ +\ +\ +'; + }; + + } else { + networks_str += ''; + }; + + networks_str += '
'+tr("Networks information")+'
'+net_id+'
'+tr("Name")+''+networks[i].NETWORK.name+'
'+tr("IP")+''+networks[i].IP+'
'+tr("MAC")+''+networks[i].MAC+'
'+ + tr("No networks defined")+'
\ +
\ +
'; + + var networks_tab = { + title : tr("Networks"), + content : networks_str + }; /* var monitoring_tab = { @@ -492,6 +603,8 @@ function updateVMInfo(request,vm){ */ Sunstone.updateInfoPanelTab("vm_info_panel","vm_info_tab",info_tab); + Sunstone.updateInfoPanelTab("vm_info_panel","vm_disks_tab",disks_tab); + Sunstone.updateInfoPanelTab("vm_info_panel","vm_networks_tab",networks_tab); //Sunstone.updateInfoPanelTab("vm_info_panel","vm_monitoring_tab",monitoring_tab); //Pop up the info panel and asynchronously get vm_log and stats @@ -510,6 +623,7 @@ function updateVMInfo(request,vm){ // Open creation dialog function popUpCreateVMDialog(){ Sunstone.popUpInfoPanel("vm_create_panel"); + Sunstone.runAction("VM.getInstanceTypes"); var dialog = $('#dialog'); $create_vm_dialog = dialog; @@ -523,7 +637,7 @@ function popUpCreateVMDialog(){ }); $('#reset_vm',dialog).button({ icons: { - primary: "ui-icon-document" + primary: "ui-icon-scissors" }, text: false }); @@ -601,11 +715,11 @@ function popUpCreateVMDialog(){ var nets = $('#network_box option[clicked="clicked"]'); if (nets.length){ - vm["NETWORK"] = []; + vm["NIC"] = []; nets.each(function(){ var value = $(this).val(); - vm["NETWORK"].push(''); + vm["NIC"].push(''); }); }; diff --git a/src/cloud/occi/lib/ui/public/js/plugins/network.js b/src/cloud/occi/lib/ui/public/js/plugins/network.js index 1a759b663f..279ea60f31 100644 --- a/src/cloud/occi/lib/ui/public/js/plugins/network.js +++ b/src/cloud/occi/lib/ui/public/js/plugins/network.js @@ -125,23 +125,23 @@ var vnet_actions = { } }, - "Network.publish" : { - type: "multiple", - call: OCCI.Network.publish, - callback: vnShow, - elements: vnElements, - error: onError, - notify: true - }, + // "Network.publish" : { + // type: "multiple", + // call: OCCI.Network.publish, + // //callback: vnShow, + // elements: vnElements, + // error: onError, + // notify: true + // }, - "Network.unpublish" : { - type: "multiple", - call: OCCI.Network.unpublish, - callback: vnShow, - elements: vnElements, - error: onError, - notify: true - }, + // "Network.unpublish" : { + // type: "multiple", + // call: OCCI.Network.unpublish, + // //callback: vnShow, + // elements: vnElements, + // error: onError, + // notify: true + // }, "Network.delete" : { type: "multiple", @@ -166,15 +166,15 @@ var vnet_buttons = { text: tr("+ New") }, - "Network.publish" : { - type: "action", - text: tr("Publish") - }, + // "Network.publish" : { + // type: "action", + // text: tr("Publish") + // }, - "Network.unpublish" : { - type: "action", - text: tr("Unpublish") - }, + // "Network.unpublish" : { + // type: "action", + // text: tr("Unpublish") + // }, "Network.delete" : { type: "action", @@ -213,10 +213,6 @@ function vnElements(){ return getSelectedNodes(dataTable_vNetworks); } -function vnShow(req){ - //Sunstone.runAction("Network.show",req.request.data[0]); -} - //returns an array with the VNET information fetched from the JSON object function vNetworkElementArray(vn_json){ var network = vn_json.NETWORK; @@ -301,10 +297,6 @@ function updateVNetworkInfo(request,vn){ '+tr("Name")+'\ '+vn_info.NAME+'\ \ - \ - '+tr("Public")+'\ - '+ vn_info.PUBLIC.toLowerCase() +'\ - \ \
\
'; @@ -339,7 +331,7 @@ function popUpCreateVnetDialog() { }); $('#reset_vn',dialog).button({ icons: { - primary: "ui-icon-document" + primary: "ui-icon-scissors" }, text: false }); diff --git a/src/cloud/occi/lib/ui/public/js/plugins/storage.js b/src/cloud/occi/lib/ui/public/js/plugins/storage.js index e710d1fd0b..f50b63ad37 100644 --- a/src/cloud/occi/lib/ui/public/js/plugins/storage.js +++ b/src/cloud/occi/lib/ui/public/js/plugins/storage.js @@ -166,9 +166,6 @@ var image_actions = { "Image.persistent" : { type: "multiple", call: OCCI.Image.persistent, - callback: function (req) { - //Sunstone.runAction("Image.show",req.request.data[0]); - }, elements: imageElements, error: onError, notify: true @@ -177,35 +174,32 @@ var image_actions = { "Image.nonpersistent" : { type: "multiple", call: OCCI.Image.nonpersistent, - callback: function (req) { - //Sunstone.runAction("Image.show",req.request.data[0]); - }, elements: imageElements, error: onError, notify: true }, - "Image.publish" : { - type: "multiple", - call: OCCI.Image.publish, - callback: function (req) { - //Sunstone.runAction("Image.show",req.request.data[0]); - }, - elements: imageElements, - error: onError, - notify: true - }, + // "Image.publish" : { + // type: "multiple", + // call: OCCI.Image.publish, + // callback: function (req) { + // //Sunstone.runAction("Image.show",req.request.data[0]); + // }, + // elements: imageElements, + // error: onError, + // notify: true + // }, - "Image.unpublish" : { - type: "multiple", - call: OCCI.Image.unpublish, - callback: function (req) { - //Sunstone.runAction("Image.show",req.request.data[0]); - }, - elements: imageElements, - error: onError, - notify: true - }, + // "Image.unpublish" : { + // type: "multiple", + // call: OCCI.Image.unpublish, + // callback: function (req) { + // //Sunstone.runAction("Image.show",req.request.data[0]); + // }, + // elements: imageElements, + // error: onError, + // notify: true + // }, "Image.delete" : { type: "multiple", @@ -228,32 +222,27 @@ var image_buttons = { type: "create_dialog", text: tr('+ New') }, - "Image.update_dialog" : { + "Image.persistent" : { type: "action", - text: tr("Update a template"), - alwaysActive: true + text: tr("Make persistent") }, - "action_list" : { - type: "select", - actions: { - "Image.publish" : { - type: "action", - text: tr("Publish") - }, - "Image.unpublish" : { - type: "action", - text: tr("Unpublish") - }, - "Image.persistent" : { - type: "action", - text: tr("Make persistent") - }, - "Image.nonpersistent" : { - type: "action", - text: tr("Make non persistent") - } - } + "Image.nonpersistent" : { + type: "action", + text: tr("Make non persistent") }, + // "action_list" : { + // type: "select", + // actions: { + // "Image.publish" : { + // type: "action", + // text: tr("Publish") + // }, + // "Image.unpublish" : { + // type: "action", + // text: tr("Unpublish") + // }, + // } + // }, "Image.delete" : { type: "action", text: tr("Delete") @@ -367,7 +356,7 @@ function updateImageInfo(request,img){ var info_tab = { title: tr("Image information"), content: - '\ + '
\ \ \ @@ -380,16 +369,17 @@ function updateImageInfo(request,img){ \ \ \ + \ + \ + \ + \ \ \ \ - \ - \ - \ \ \ \ - \ +\ \ \ \ @@ -399,7 +389,7 @@ function updateImageInfo(request,img){ \ \ \ -
'+tr("Image")+' "'+img_info.NAME+'" '+ tr("information")+'
'+tr("Name")+''+img_info.NAME+'
'+tr("Name")+''+img_info.DESCRIPTION+'
'+tr("Type")+''+OCCI.Helper.image_type(img_info.TYPE)+'
'+tr("Public")+''+img_info.PUBLIC.toLowerCase()+'
'+tr("Persistent")+''+img_info.PERSISTENT.toLowerCase()+'
'+tr("Filesystem type")+''+tr("Size (Mb)")+''+img_info.SIZE+'
\ + \
\
' }; @@ -410,6 +400,12 @@ function updateImageInfo(request,img){ text:false, icons: { primary: "ui-icon-closethick" } }); + $('#dialog input').click(function(){ + if ($(this).is(':checked')) + Sunstone.runAction("Image.persistent",[img_info.ID]) + else + Sunstone.runAction("Image.nonpersistent",[img_info.ID]) + }); } function popUpCreateImageDialog(){ @@ -425,7 +421,7 @@ function popUpCreateImageDialog(){ }); $('#reset_image',dialog).button({ icons: { - primary: "ui-icon-document" + primary: "ui-icon-scissors" }, text: false }); @@ -441,6 +437,7 @@ function popUpCreateImageDialog(){ $('#img_fstype',dialog).parents('div.img_param').hide(); $('#img_size',dialog).parents('div.img_param').hide(); +/* $('#img_public',dialog).click(function(){ $('#img_persistent',$create_image_dialog).removeAttr('checked'); }); @@ -448,7 +445,7 @@ function popUpCreateImageDialog(){ $('#img_persistent',dialog).click(function(){ $('#img_public',$create_image_dialog).removeAttr('checked'); }); - +*/ $('#img_type',dialog).change(function(){ if ($(this).val() == "DATABLOCK"){ $('#img_fstype',$create_image_dialog).parents('div.img_param').show(); @@ -639,7 +636,7 @@ $(document).ready(function(){ }); $('.image_close_dialog_link').live("click",function(){ - popUpVNetDashboard(); + popUpImageDashboard(); return false; }); diff --git a/src/cloud/occi/lib/ui/public/js/sunstone.js b/src/cloud/occi/lib/ui/public/js/sunstone.js index 59b9f50c4f..235791ec1f 100644 --- a/src/cloud/occi/lib/ui/public/js/sunstone.js +++ b/src/cloud/occi/lib/ui/public/js/sunstone.js @@ -366,6 +366,7 @@ $(document).ready(function(){ $('.action_blocks .action_list:visible',main_tabs_context).hide(); }); + //Close open panel $('.close_dialog_link').live("click",function(){ hideDialog(); return false; @@ -402,6 +403,9 @@ function setLogin(){ case "ozones": username = cookie["ozones-user"]; break; + case "occi": + username = cookie["occi-user"]; + break; }; @@ -416,6 +420,9 @@ function setLogin(){ case "ozones": oZones.Auth.logout({success:redirect}); break; + case "occi": + OCCI.Auth.logout({success:function(){window.location.href = "ui";}}); + break; } return false; }); @@ -424,8 +431,13 @@ function setLogin(){ //returns whether we are Sunstone, or oZones //not the most elegant way, but better in its own function function whichUI(){ - return (typeof(OpenNebula)!="undefined"? "sunstone" : "ozones"); -} + if (typeof(OpenNebula)!="undefined") + return "sunstone"; + if (typeof(oZones)!="undefined") + return "ozones"; + if (typeof(OCCI)!="undefined") + return "occi"; +}; //Inserts all main tabs in the DOM function insertTabs(){ diff --git a/src/sunstone/public/js/sunstone.js b/src/sunstone/public/js/sunstone.js index d49d800970..235791ec1f 100644 --- a/src/sunstone/public/js/sunstone.js +++ b/src/sunstone/public/js/sunstone.js @@ -403,6 +403,9 @@ function setLogin(){ case "ozones": username = cookie["ozones-user"]; break; + case "occi": + username = cookie["occi-user"]; + break; }; @@ -417,6 +420,9 @@ function setLogin(){ case "ozones": oZones.Auth.logout({success:redirect}); break; + case "occi": + OCCI.Auth.logout({success:function(){window.location.href = "ui";}}); + break; } return false; }); @@ -425,8 +431,13 @@ function setLogin(){ //returns whether we are Sunstone, or oZones //not the most elegant way, but better in its own function function whichUI(){ - return (typeof(OpenNebula)!="undefined"? "sunstone" : "ozones"); -} + if (typeof(OpenNebula)!="undefined") + return "sunstone"; + if (typeof(oZones)!="undefined") + return "ozones"; + if (typeof(OCCI)!="undefined") + return "occi"; +}; //Inserts all main tabs in the DOM function insertTabs(){