mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
Merge branch 'feature-565'
This commit is contained in:
commit
9ce34ecf3e
@ -20,6 +20,7 @@ include OpenNebula
|
||||
require 'OpenNebulaJSON/ClusterJSON'
|
||||
require 'OpenNebulaJSON/HostJSON'
|
||||
require 'OpenNebulaJSON/ImageJSON'
|
||||
require 'OpenNebulaJSON/TemplateJSON'
|
||||
require 'OpenNebulaJSON/JSONUtils'
|
||||
require 'OpenNebulaJSON/PoolJSON'
|
||||
require 'OpenNebulaJSON/UserJSON'
|
||||
|
@ -21,6 +21,7 @@ module OpenNebulaJSON
|
||||
class VirtualMachinePoolJSON < OpenNebula::VirtualMachinePool; include JSONUtils; end
|
||||
class VirtualNetworkPoolJSON < OpenNebula::VirtualNetworkPool; include JSONUtils; end
|
||||
class ImagePoolJSON < OpenNebula::ImagePool; include JSONUtils; end
|
||||
class TemplatePoolJSON < OpenNebula::TemplatePool; include JSONUtils; end
|
||||
class ClusterPoolJSON < OpenNebula::ClusterPool; include JSONUtils; end
|
||||
class UserPoolJSON < OpenNebula::UserPool; include JSONUtils; end
|
||||
end
|
||||
|
65
src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb
Normal file
65
src/sunstone/models/OpenNebulaJSON/TemplateJSON.rb
Normal file
@ -0,0 +1,65 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'OpenNebulaJSON/JSONUtils'
|
||||
|
||||
module OpenNebulaJSON
|
||||
class TemplateJSON < OpenNebula::Template
|
||||
include JSONUtils
|
||||
|
||||
def create(template_json)
|
||||
template_hash = parse_json(template_json, 'vmtemplate')
|
||||
if OpenNebula.is_error?(template_hash)
|
||||
return template_hash
|
||||
end
|
||||
|
||||
if template_hash['template_raw']
|
||||
template = template_hash['template_raw']
|
||||
else
|
||||
template = template_to_str(template_hash)
|
||||
end
|
||||
|
||||
self.allocate(template)
|
||||
end
|
||||
|
||||
def perform_action(template_json)
|
||||
action_hash = parse_json(template_json, 'action')
|
||||
if OpenNebula.is_error?(action_hash)
|
||||
return action_hash
|
||||
end
|
||||
|
||||
rc = case action_hash['perform']
|
||||
when "publish" then self.publish
|
||||
when "rm_attr" then self.remove_attr(action_hash['params'])
|
||||
when "unpublish" then self.unpublish
|
||||
when "update" then self.update(action_hash['params'])
|
||||
else
|
||||
error_msg = "#{action_hash['perform']} action not " <<
|
||||
" available for this resource"
|
||||
OpenNebula::Error.new(error_msg)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def update(params=Hash.new)
|
||||
super(params['name'], params['value'])
|
||||
end
|
||||
|
||||
def remove_attr(params=Hash.new)
|
||||
super(params['name'])
|
||||
end
|
||||
end
|
||||
end
|
@ -28,6 +28,12 @@ module OpenNebulaJSON
|
||||
|
||||
if vm_hash['vm_raw']
|
||||
template = vm_hash['vm_raw']
|
||||
elsif vm_hash['template_id']
|
||||
template_id = vm_hash['template_id']
|
||||
|
||||
template = "TEMPLATE_ID = #{template_id}"
|
||||
template << "\nNAME = #{vm_hash[:vm_name]}" if vm_hash[:vm_name]
|
||||
|
||||
else
|
||||
template = template_to_str(vm_hash)
|
||||
end
|
||||
@ -55,7 +61,7 @@ module OpenNebulaJSON
|
||||
when "restart" then self.restart
|
||||
when "saveas" then self.save_as(action_hash['params'])
|
||||
when "shutdown" then self.shutdown
|
||||
when "resubmit" then self.resubmit
|
||||
when "resubmit" then self.resubmit
|
||||
else
|
||||
error_msg = "#{action_hash['perform']} action not " <<
|
||||
" available for this resource"
|
||||
|
@ -68,12 +68,13 @@ class SunstoneServer
|
||||
def get_pool(kind)
|
||||
user_flag = -2
|
||||
pool = case kind
|
||||
when "cluster" then ClusterPoolJSON.new(@client)
|
||||
when "host" then HostPoolJSON.new(@client)
|
||||
when "image" then ImagePoolJSON.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 "cluster" then ClusterPoolJSON.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)
|
||||
else
|
||||
error = Error.new("Error: #{kind} resource not supported")
|
||||
return [404, error.to_json]
|
||||
@ -104,12 +105,13 @@ class SunstoneServer
|
||||
############################################################################
|
||||
def create_resource(kind, template)
|
||||
resource = case kind
|
||||
when "cluster" then ClusterJSON.new(Cluster.build_xml, @client)
|
||||
when "host" then HostJSON.new(Host.build_xml, @client)
|
||||
when "image" then ImageJSON.new(Image.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 "cluster" then ClusterJSON.new(Cluster.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)
|
||||
else
|
||||
error = Error.new("Error: #{kind} resource not supported")
|
||||
return [404, error.to_json]
|
||||
@ -217,12 +219,13 @@ class SunstoneServer
|
||||
|
||||
def retrieve_resource(kind, id)
|
||||
resource = case kind
|
||||
when "cluster" then ClusterJSON.new_with_id(id, @client)
|
||||
when "host" then HostJSON.new_with_id(id, @client)
|
||||
when "image" then ImageJSON.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)
|
||||
when "cluster" then ClusterJSON.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 "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)
|
||||
else
|
||||
error = Error.new("Error: #{kind} resource not supported")
|
||||
return error
|
||||
|
@ -142,7 +142,7 @@ var OpenNebula = {
|
||||
{
|
||||
return Error('Incorrect Pool');
|
||||
}
|
||||
|
||||
|
||||
var p_pool = [];
|
||||
|
||||
if (response[pool_name]) {
|
||||
@ -1931,5 +1931,301 @@ var OpenNebula = {
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
"Template" : {
|
||||
"resource" : "VMTEMPLATE",
|
||||
|
||||
"create" : function(params)
|
||||
{
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var data = params.data;
|
||||
var resource = OpenNebula.Template.resource;
|
||||
|
||||
var request = OpenNebula.Helper.request(resource,"create",data);
|
||||
|
||||
$.ajax({
|
||||
url: "/template",
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: JSON.stringify(data),
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
callback(request, response);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, OpenNebula.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
"addattr" : function(params)
|
||||
{
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var id = params.data.id;
|
||||
var name = params.data.name;
|
||||
var value = params.data.value;
|
||||
|
||||
var method = "update";
|
||||
var action = OpenNebula.Helper.action(method, {
|
||||
"name" : name,
|
||||
"value" : value
|
||||
});
|
||||
|
||||
var resource = OpenNebula.Template.resource;
|
||||
var request = OpenNebula.Helper.request(resource,method, [id, name, value]);
|
||||
|
||||
$.ajax({
|
||||
url: "/template/" + id + "/action",
|
||||
type: "POST",
|
||||
data: JSON.stringify(action),
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
callback(request, response);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, OpenNebula.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
"update" : function(params)
|
||||
{
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var id = params.data.id;
|
||||
var name = params.data.name;
|
||||
var value = params.data.value;
|
||||
|
||||
var method = "update";
|
||||
var action = OpenNebula.Helper.action(method, {
|
||||
"name" : name,
|
||||
"value" : value
|
||||
});
|
||||
|
||||
var resource = OpenNebula.Template.resource;
|
||||
var request = OpenNebula.Helper.request(resource,method, [id, name, value]);
|
||||
|
||||
$.ajax({
|
||||
url: "/template/" + id + "/action",
|
||||
type: "POST",
|
||||
data: JSON.stringify(action),
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
callback(request, response);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, OpenNebula.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
"rmattr" : function(params)
|
||||
{
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var id = params.data.id;
|
||||
var name = params.data.name;
|
||||
var value = params.data.value;
|
||||
|
||||
var method = "rm_attr";
|
||||
var action = OpenNebula.Helper.action(method, {
|
||||
"name" : name
|
||||
});
|
||||
|
||||
var resource = OpenNebula.Template.resource;
|
||||
var request = OpenNebula.Helper.request(resource,method, [id, name]);
|
||||
|
||||
$.ajax({
|
||||
url: "/template/" + id + "/action",
|
||||
type: "POST",
|
||||
data: JSON.stringify(action),
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
callback(request, response);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, OpenNebula.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
"publish" : function(params)
|
||||
{
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var id = params.data.id;
|
||||
|
||||
var method = "publish";
|
||||
var action = OpenNebula.Helper.action(method);
|
||||
var resource = OpenNebula.Template.resource;
|
||||
var request = OpenNebula.Helper.request(resource,method, id);
|
||||
|
||||
$.ajax({
|
||||
url: "/template/" + id + "/action",
|
||||
type: "POST",
|
||||
data: JSON.stringify(action),
|
||||
success: function()
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
callback(request);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if(callback_error)
|
||||
{
|
||||
callback_error(request, OpenNebula.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
"unpublish" : function(params)
|
||||
{
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var id = params.data.id;
|
||||
|
||||
var method = "unpublish";
|
||||
var action = OpenNebula.Helper.action(method);
|
||||
var resource = OpenNebula.Template.resource;
|
||||
var request = OpenNebula.Helper.request(resource,method, id);
|
||||
|
||||
$.ajax({
|
||||
url: "/template/" + id + "/action",
|
||||
type: "POST",
|
||||
data: JSON.stringify(action),
|
||||
success: function()
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
callback(request);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if(callback_error)
|
||||
{
|
||||
callback_error(request, OpenNebula.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
"list" : function(params)
|
||||
{
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var timeout = params.timeout || false;
|
||||
|
||||
var resource = OpenNebula.Template.resource;
|
||||
var request = OpenNebula.Helper.request(resource,"list");
|
||||
|
||||
$.ajax({
|
||||
url: "/template",
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
data: {timeout: timeout},
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
var template_pool = OpenNebula.Helper.pool(resource,response);
|
||||
callback(request, template_pool);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, OpenNebula.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
"show" : function(params)
|
||||
{
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var id = params.data.id;
|
||||
|
||||
var resource = OpenNebula.Template.resource;
|
||||
var request = OpenNebula.Helper.request(resource,"show", id);
|
||||
|
||||
$.ajax({
|
||||
url: "/template/" + id,
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
callback(request, response);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, OpenNebula.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
"delete" : function(params)
|
||||
{
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var id = params.data.id;
|
||||
var resource = OpenNebula.Template.resource;
|
||||
|
||||
var request = OpenNebula.Helper.request(resource,"delete", id);
|
||||
|
||||
$.ajax({
|
||||
url: "/template/" + id,
|
||||
type: "DELETE",
|
||||
success: function()
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
callback(request);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, OpenNebula.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1714
src/sunstone/public/js/plugins/templates-tab.js
Normal file
1714
src/sunstone/public/js/plugins/templates-tab.js
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -93,6 +93,7 @@ function tableCheckboxesListener(dataTable){
|
||||
last_action_b.button("disable");
|
||||
};
|
||||
$('.create_dialog_button',context).button("enable");
|
||||
$('.alwaysActive',context).button("enable");
|
||||
|
||||
//listen to changes in the visible inputs
|
||||
$('tbody input',dataTable).live("change",function(){
|
||||
@ -127,6 +128,7 @@ function tableCheckboxesListener(dataTable){
|
||||
|
||||
//any case the create dialog buttons should always be enabled.
|
||||
$('.create_dialog_button',context).button("enable");
|
||||
$('.alwaysActive',context).button("enable");
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -448,6 +448,10 @@ function insertButtonsInTab(tab_name){
|
||||
|
||||
}
|
||||
|
||||
if (button.alwaysActive) {
|
||||
button_code = $(button_code).addClass("alwaysActive");
|
||||
}
|
||||
|
||||
$('div#'+tab_name+' .action_blocks').append(button_code);
|
||||
|
||||
}//for each button in tab
|
||||
|
@ -25,6 +25,7 @@
|
||||
<script type="text/javascript" src="/js/sunstone-util.js"></script>
|
||||
<script type="text/javascript" src="/js/plugins/dashboard-tab.js"></script>
|
||||
<script type="text/javascript" src="/js/plugins/hosts-tab.js"></script>
|
||||
<script type="text/javascript" src="/js/plugins/templates-tab.js"></script>
|
||||
<script type="text/javascript" src="/js/plugins/vms-tab.js"></script>
|
||||
<script type="text/javascript" src="/js/plugins/vnets-tab.js"></script>
|
||||
<script type="text/javascript" src="/js/plugins/images-tab.js"></script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user