1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

Feature #799: opennebula.js refactor

This commit contains a full refactoring of opennebula.js, the Javascript API to interact with Sunstone server.

Refactoring includes some other smaller changes in order to achieve consistency:

 - SunstoneServer.rb: vm logs are returned in JSON format instead of plain text. VM template resource is now accessed via "/vmtemplate" instead of "template".
 - Images plugin: update "register" references to "create".
 - VM plugin: update VM log processing. Improve the "saveas" action object, making it a standard "single" action instead of "custom".
This commit is contained in:
Hector Sanjuan 2011-09-08 23:21:22 +02:00
parent c2d3c4b3fd
commit b288c319e7
4 changed files with 442 additions and 2408 deletions

View File

@ -67,14 +67,14 @@ class SunstoneServer
end
pool = case kind
when "group" then GroupPoolJSON.new(@client)
when "host" then HostPoolJSON.new(@client)
when "image" then ImagePoolJSON.new(@client, user_flag)
when "template" then TemplatePoolJSON.new(@client, user_flag)
when "vm" then VirtualMachinePoolJSON.new(@client, user_flag)
when "vnet" then VirtualNetworkPoolJSON.new(@client, user_flag)
when "user" then UserPoolJSON.new(@client)
when "acl" then AclPoolJSON.new(@client)
when "group" then GroupPoolJSON.new(@client)
when "host" then HostPoolJSON.new(@client)
when "image" then ImagePoolJSON.new(@client, user_flag)
when "vmtemplate" then TemplatePoolJSON.new(@client, user_flag)
when "vm" then VirtualMachinePoolJSON.new(@client, user_flag)
when "vnet" then VirtualNetworkPoolJSON.new(@client, user_flag)
when "user" then UserPoolJSON.new(@client)
when "acl" then AclPoolJSON.new(@client)
else
error = Error.new("Error: #{kind} resource not supported")
return [404, error.to_json]
@ -119,14 +119,14 @@ class SunstoneServer
############################################################################
def create_resource(kind, template)
resource = case kind
when "group" then GroupJSON.new(Group.build_xml, @client)
when "host" then HostJSON.new(Host.build_xml, @client)
when "image" then ImageJSON.new(Image.build_xml, @client)
when "template" then TemplateJSON.new(Template.build_xml, @client)
when "vm" then VirtualMachineJSON.new(VirtualMachine.build_xml,@client)
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 "group" then GroupJSON.new(Group.build_xml, @client)
when "host" then HostJSON.new(Host.build_xml, @client)
when "image" then ImageJSON.new(Image.build_xml, @client)
when "vmtemplate" then TemplateJSON.new(Template.build_xml, @client)
when "vm" then VirtualMachineJSON.new(VirtualMachine.build_xml,@client)
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)
else
error = Error.new("Error: #{kind} resource not supported")
return [404, error.to_json]
@ -226,7 +226,7 @@ class SunstoneServer
return [200, "Log for VM #{id} not available"]
end
return [200, log]
return [200, {:vm_log => log}.to_json]
end
end
@ -339,7 +339,7 @@ class SunstoneServer
when "group" then GroupJSON.new_with_id(id, @client)
when "host" then HostJSON.new_with_id(id, @client)
when "image" then ImageJSON.new_with_id(id, @client)
when "template" then TemplateJSON.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)

File diff suppressed because it is too large Load Diff

View File

@ -161,9 +161,9 @@ var $create_image_dialog;
var image_actions = {
"Image.register" : {
"Image.create" : {
type: "create",
call: OpenNebula.Image.register,
call: OpenNebula.Image.create,
callback: addImageElement,
error: onError,
notify:true
@ -710,7 +710,7 @@ function setupCreateImageDialog(){
break;
}
var obj = { "image" : img_json };
Sunstone.runAction("Image.register", obj);
Sunstone.runAction("Image.create", obj);
$create_image_dialog.dialog('close');
return false;
@ -718,7 +718,7 @@ function setupCreateImageDialog(){
$('#create_image_form_manual',dialog).submit(function(){
var template=$('#template',this).val();
Sunstone.runAction("Image.register",template);
Sunstone.runAction("Image.create",template);
$create_image_dialog.dialog('close');
return false;
});

View File

@ -250,13 +250,10 @@ var vm_actions = {
},
"VM.saveas" : {
type: "custom",
call: function(obj) {
OpenNebula.VM.saveas(
{data:obj,
success: vmShow,
error: onError });
}
type: "single",
call: OpenNebula.VM.saveas,
callback: vmShow,
error:onError
},
"VM.saveas_disks" : {
@ -299,6 +296,7 @@ var vm_actions = {
callback: function(req,res) {
//after calling VM.log we process the answer
//update the tab and pop it up again
res = res['vm_log'];
var log_lines = res.split("\n");
var colored_log = '';
for (var i = 0; i < log_lines.length;i++){
@ -822,13 +820,12 @@ function setupSaveasDialog(){
}
else {
var obj = {
vm_id: id,
disk_id : disk_id,
image_name : image_name
//type: type
};
args.push(id);
Sunstone.runAction("VM.saveas",obj);
Sunstone.runAction("VM.saveas",id,obj);
}
});
if (args.length > 0){