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 ='
\
\
'
};
@@ -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(){