mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-23 22:50:09 +03:00
Merge branch 'feature-799'
This commit is contained in:
commit
6f99e91fb4
@ -21,7 +21,7 @@ require 'JSONUtils'
|
||||
class OzonesServer
|
||||
|
||||
include JSONUtils
|
||||
|
||||
|
||||
def initialize
|
||||
@ocaInt = OCAInteraction.new
|
||||
end
|
||||
@ -38,69 +38,69 @@ class OzonesServer
|
||||
"Error: #{kind} resource not supported")
|
||||
return [404, error.to_json]
|
||||
end
|
||||
|
||||
|
||||
return [200, pool.to_json]
|
||||
end
|
||||
|
||||
|
||||
# Gets an aggreageted pool for a zone or vdc
|
||||
# ie All the hosts in all the Zones
|
||||
# ie All the hosts in all the Zones
|
||||
def get_aggregated_pool(kind, aggkind)
|
||||
aggpool = case kind
|
||||
when "zone" then
|
||||
when "zone" then
|
||||
case aggkind
|
||||
when "host" then OZones::AggregatedHosts.new
|
||||
when "image" then OZones::AggregatedImages.new
|
||||
when "user" then OZones::AggregatedUsers.new
|
||||
when "vm" then OZones::AggregatedVirtualMachines.new
|
||||
when "vn" then OZones::AggregatedVirtualNetworks.new
|
||||
when "template" then OZones::AggregatedTemplates.new
|
||||
when "host" then OZones::AggregatedHosts.new
|
||||
when "image" then OZones::AggregatedImages.new
|
||||
when "user" then OZones::AggregatedUsers.new
|
||||
when "vm" then OZones::AggregatedVirtualMachines.new
|
||||
when "vn","vnet" then OZones::AggregatedVirtualNetworks.new
|
||||
when "template","vmtemplate" then OZones::AggregatedTemplates.new
|
||||
end
|
||||
else
|
||||
error = OZones::Error.new(
|
||||
"Error: #{aggkind} aggregated pool for #{kind} not supported")
|
||||
return [404, error.to_json]
|
||||
end
|
||||
|
||||
|
||||
return [200, aggpool.to_json]
|
||||
end
|
||||
|
||||
|
||||
# Gets an aggreageted pool for a zone or vdc in json
|
||||
# ie All the hosts in all the Zones
|
||||
# ie All the hosts in all the Zones
|
||||
def get_full_resource(kind, id, aggkind)
|
||||
resource = retrieve_resource(kind, id)
|
||||
|
||||
|
||||
if OZones.is_error?(resource)
|
||||
return [404, resource.to_json]
|
||||
end
|
||||
|
||||
|
||||
# TODO build the vdc retrieval
|
||||
|
||||
|
||||
if kind == "zone"
|
||||
client = OpenNebula::Client.new(
|
||||
resource.onename + ":" + resource.onepass,
|
||||
resource.endpoint,
|
||||
false)
|
||||
false)
|
||||
|
||||
simple_pool = case aggkind
|
||||
when "host" then OpenNebulaJSON::HostPoolJSON.new(client)
|
||||
when "image" then OpenNebulaJSON::ImagePoolJSON.new(client)
|
||||
when "user" then OpenNebulaJSON::UserPoolJSON.new(client)
|
||||
when "vm" then OpenNebulaJSON::VirtualMachinePoolJSON.new(client)
|
||||
when "vn" then OpenNebulaJSON::VirtualNetworkPoolJSON.new(client)
|
||||
when "template" then OpenNebulaJSON::TemplatePoolJSON.new(client)
|
||||
when "host" then OpenNebulaJSON::HostPoolJSON.new(client)
|
||||
when "image" then OpenNebulaJSON::ImagePoolJSON.new(client)
|
||||
when "user" then OpenNebulaJSON::UserPoolJSON.new(client)
|
||||
when "vm" then OpenNebulaJSON::VirtualMachinePoolJSON.new(client)
|
||||
when "vn","vnet" then OpenNebulaJSON::VirtualNetworkPoolJSON.new(client)
|
||||
when "template","vmtemplate" then OpenNebulaJSON::TemplatePoolJSON.new(client)
|
||||
else
|
||||
error = OZones::Error.new(
|
||||
"Error: #{aggkind} aggregated pool for #{kind} #{id} not supported")
|
||||
return [404, error.to_json]
|
||||
end
|
||||
|
||||
|
||||
simple_pool.info
|
||||
|
||||
|
||||
return [200, simple_pool.to_json]
|
||||
end
|
||||
end
|
||||
|
||||
# Get a json representation resource with local (DB) info
|
||||
|
||||
# Get a json representation resource with local (DB) info
|
||||
def get_resource(kind, id)
|
||||
resource = retrieve_resource(kind, id)
|
||||
if OZones.is_error?(resource)
|
||||
@ -108,7 +108,7 @@ class OzonesServer
|
||||
else
|
||||
return [200, resource.to_json]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Get hold of a object of a particular kind
|
||||
def retrieve_resource(kind, id)
|
||||
@ -119,10 +119,10 @@ class OzonesServer
|
||||
return OZones::Error.new(
|
||||
"Error: #{kind} resource not supported")
|
||||
end
|
||||
|
||||
|
||||
if resource
|
||||
return resource
|
||||
else
|
||||
else
|
||||
return OZones::Error.new(
|
||||
"Error: Resource #{kind} with id #{id} not found")
|
||||
end
|
||||
@ -134,45 +134,45 @@ class OzonesServer
|
||||
############################################################################
|
||||
# Creates a resource of a kind, and updates the Proxy Rules
|
||||
def create_resource(kind, data, body, pr)
|
||||
|
||||
if body.size > 0
|
||||
|
||||
if body.size > 0
|
||||
result = parse_json(body,kind)
|
||||
data = result if !OpenNebula.is_error?(result)
|
||||
end
|
||||
|
||||
resource = case kind
|
||||
when "vdc" then
|
||||
when "vdc" then
|
||||
vdc_data=Hash.new
|
||||
data.each{|key,value|
|
||||
vdc_data[key.downcase.to_sym]=value if key!="pool"
|
||||
}
|
||||
|
||||
|
||||
# Check parameters
|
||||
if !vdc_data[:vdcadminname] || !vdc_data[:vdcadminpass] ||
|
||||
!vdc_data[:zoneid] || !vdc_data[:name] || !vdc_data[:hosts]
|
||||
!vdc_data[:zoneid] || !vdc_data[:name] || !vdc_data[:hosts]
|
||||
return [400, OZones::Error.new(
|
||||
"Error: Couldn't create resource #{kind}. " +
|
||||
"Error: Couldn't create resource #{kind}. " +
|
||||
"Not enough information on the template").to_json]
|
||||
end
|
||||
|
||||
# Check if the referenced zone exists
|
||||
|
||||
# Check if the referenced zone exists
|
||||
zone=OZones::Zones.get(vdc_data[:zoneid])
|
||||
if !zone
|
||||
error = OZones::Error.new("Error: Zone " +
|
||||
error = OZones::Error.new("Error: Zone " +
|
||||
"#{vdc_data[:zoneid]} not found, cannot create Vdc.")
|
||||
return [404, error.to_json]
|
||||
end
|
||||
|
||||
vdcadminname = vdc_data[:vdcadminname]
|
||||
vdcadminpass = vdc_data[:vdcadminpass]
|
||||
vdc_data.delete(:zoneid)
|
||||
vdc_data.delete(:zoneid)
|
||||
vdc_data.delete(:vdcadminpass)
|
||||
|
||||
|
||||
vdc = OZones::Vdc.create(vdc_data)
|
||||
|
||||
zone.vdcs << vdc
|
||||
zone.save
|
||||
|
||||
|
||||
if zone.saved? and vdc.saved?
|
||||
vdcadminpass = Digest::SHA1.hexdigest(vdcadminpass)
|
||||
rc = @ocaInt.create_vdc_in_zone(zone,
|
||||
@ -196,26 +196,26 @@ class OzonesServer
|
||||
" Maybe duplicated name?").to_json]
|
||||
end
|
||||
|
||||
when "zone" then
|
||||
when "zone" then
|
||||
zone_data=Hash.new
|
||||
data.each{|key,value|
|
||||
zone_data[key.downcase.to_sym]=value if key!="pool"
|
||||
}
|
||||
|
||||
|
||||
# Check parameters
|
||||
if !zone_data[:onename] || !zone_data[:onepass] ||
|
||||
!zone_data[:endpoint] || !zone_data[:name]
|
||||
!zone_data[:endpoint] || !zone_data[:name]
|
||||
return [400, OZones::Error.new(
|
||||
"Error: Couldn't create resource #{kind}. " +
|
||||
"Error: Couldn't create resource #{kind}. " +
|
||||
"Not enough information on the template").to_json]
|
||||
end
|
||||
|
||||
|
||||
# Digest and check credentials
|
||||
zone_data[:onepass] =
|
||||
zone_data[:onepass] =
|
||||
Digest::SHA1.hexdigest(zone_data[:onepass])
|
||||
|
||||
rc = @ocaInt.check_oneadmin(zone_data[:onename],
|
||||
zone_data[:onepass],
|
||||
|
||||
rc = @ocaInt.check_oneadmin(zone_data[:onename],
|
||||
zone_data[:onepass],
|
||||
zone_data[:endpoint])
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
@ -223,19 +223,19 @@ class OzonesServer
|
||||
"Error: Couldn't create resource #{kind}. Reason: "+
|
||||
rc.message).to_json]
|
||||
end
|
||||
|
||||
|
||||
# Create the zone
|
||||
zone = OZones::Zones.create(zone_data)
|
||||
rc = zone.save
|
||||
|
||||
|
||||
if rc
|
||||
pr.update # Rewrite proxy conf file
|
||||
return [200, zone.to_json]
|
||||
else
|
||||
return [400, OZones::Error.new(
|
||||
"Error: Couldn't create resource #{kind.upcase}." +
|
||||
"Error: Couldn't create resource #{kind.upcase}." +
|
||||
" Maybe duplicated name?").to_json]
|
||||
end
|
||||
end
|
||||
else
|
||||
error = OZones::Error.new(
|
||||
"Error: #{kind.upcase} resource not supported")
|
||||
@ -252,16 +252,16 @@ class OzonesServer
|
||||
if OZones.is_error?(resource)
|
||||
return [404, resource.to_json]
|
||||
end
|
||||
|
||||
|
||||
if kind == "vdc"
|
||||
rc = @ocaInt.delete_vdc_in_zone(id)
|
||||
if OpenNebula.is_error?(rc)
|
||||
return [500, OZones::Error.new(
|
||||
"Error: Couldn't delete resources from VDC with id #{id}, " +
|
||||
"Error: Couldn't delete resources from VDC with id #{id}, " +
|
||||
"aborting VDC deletion. Reason:" + rc.message).to_json]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if !resource.destroy
|
||||
return [500, OZones::Error.new(
|
||||
"Error: Couldn't delete resource #{kind} with id #{id}").to_json]
|
||||
|
@ -38,14 +38,7 @@ var oZones = {
|
||||
|
||||
"is_error": function(obj)
|
||||
{
|
||||
if (obj.error)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return obj.error ? true : false;
|
||||
},
|
||||
|
||||
"Helper": {
|
||||
@ -186,6 +179,99 @@ var oZones = {
|
||||
}
|
||||
},
|
||||
|
||||
"Action": {
|
||||
"create": function(params,resource){
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var data = params.data;
|
||||
var request = oZones.Helper.request(resource,"create", data);
|
||||
|
||||
$.ajax({
|
||||
url: resource.toLowerCase(),
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: JSON.stringify(data),
|
||||
success: function(response){
|
||||
return callback ? callback(request, response) : null;
|
||||
},
|
||||
error: function(response){
|
||||
return callback_error ?
|
||||
callback_error(request, oZones.Error(response)) : null;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
"delete": function(params,resource){
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var id = params.data.id;
|
||||
var request = oZones.Helper.request(resource,"delete", id);
|
||||
|
||||
$.ajax({
|
||||
url: resource.toLowerCase() + "/" + id,
|
||||
type: "DELETE",
|
||||
success: function(){
|
||||
return callback ? callback(request) : null;
|
||||
},
|
||||
error: function(response){
|
||||
return callback_error ?
|
||||
callback_error(request, oZones.Error(response)) : null;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
"list": function(params,resource,subresource){
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var timeout = params.timeout || false;
|
||||
var request = oZones.Helper.request(resource,"list");
|
||||
|
||||
var url = resource.toLowerCase();
|
||||
url = subresource ? url + "/" + subresource : url;
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: "GET",
|
||||
data: {timeout: timeout},
|
||||
dataType: "json",
|
||||
success: function(response){
|
||||
return callback ?
|
||||
callback(request, oZones.Helper.pool(resource,response)) : null;
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
return callback_error ?
|
||||
callback_error(request, oZones.Error(response)) : null;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
//Subresource examples: "fetch_template", "log"...
|
||||
"show": function(params,resource,subresource){
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var id = params.data.id;
|
||||
var request = subresource ?
|
||||
oZones.Helper.request(resource,subresource,id) :
|
||||
oZones.Helper.request(resource,"show", id);
|
||||
|
||||
var url = resource.toLowerCase() + "/" + id;
|
||||
url = subresource? url + "/" + subresource : url;
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function(response){
|
||||
return callback ? callback(request, response) : null;
|
||||
},
|
||||
error: function(response){
|
||||
return callback_error ?
|
||||
callback_error(request, oZones.Error(response)) : null;
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
"Auth": {
|
||||
"resource": "AUTH",
|
||||
|
||||
@ -209,19 +295,12 @@ var oZones = {
|
||||
"Basic " + btoa(username + ":" + password)
|
||||
)
|
||||
},
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
callback(request, response);
|
||||
}
|
||||
success: function(response){
|
||||
return callback ? callback(request, response) : null;
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
error: function(response){
|
||||
return callback_error ?
|
||||
callback_error(request, oZones.Error(response)) : null;
|
||||
}
|
||||
});
|
||||
},
|
||||
@ -237,19 +316,12 @@ var oZones = {
|
||||
$.ajax({
|
||||
url: "logout",
|
||||
type: "POST",
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
callback(request, response);
|
||||
}
|
||||
success: function(response){
|
||||
return callback ? callback(request, response) : null;
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
error: function(response){
|
||||
return callback_error ?
|
||||
callback_error(request, oZones.Error(response)) : null;
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -270,19 +342,12 @@ var oZones = {
|
||||
url: "config",
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
callback(request, response);
|
||||
}
|
||||
success: function(response){
|
||||
return callback ? callback(request,response) : null;
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
error: function(response){
|
||||
return callback_error ?
|
||||
callback_error(request, oZones.Error(response)) : null;
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -291,696 +356,121 @@ var oZones = {
|
||||
"Zone": {
|
||||
"resource": "ZONE",
|
||||
|
||||
"create": function(params)
|
||||
{
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var data = params.data;
|
||||
var resource = oZones.Zone.resource;
|
||||
|
||||
var request = oZones.Helper.request(resource,"create", data);
|
||||
|
||||
$.ajax({
|
||||
url: "zone",
|
||||
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, oZones.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
"create": function(params){
|
||||
oZones.Action.create(params,oZones.Zone.resource);
|
||||
},
|
||||
"delete" : function(params){
|
||||
oZones.Action.delete(params,oZones.Zone.resource);
|
||||
},
|
||||
"list": function(params){
|
||||
oZones.Action.list(params,oZones.Zone.resource);
|
||||
},
|
||||
"show": function(params){
|
||||
oZones.Action.show(params,oZones.Zone.resource);
|
||||
},
|
||||
|
||||
"delete": function(params)
|
||||
{
|
||||
"subresource" : function(params,subresource){
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var id = params.data.id;
|
||||
var resource = oZones.Zone.resource;
|
||||
|
||||
|
||||
var request = oZones.Helper.request(resource,"delete", id);
|
||||
|
||||
$.ajax({
|
||||
url: "zone/" + id,
|
||||
type: "DELETE",
|
||||
success: function()
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
callback(request);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
"list": function(params)
|
||||
{
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var timeout = params.timeout || false;
|
||||
|
||||
var resource = oZones.Zone.resource;
|
||||
var request = oZones.Helper.request(resource,"list");
|
||||
var request = oZones.Helper.request(resource,subresource, id);
|
||||
|
||||
$.ajax({
|
||||
url: "zone",
|
||||
type: "GET",
|
||||
data: {timeout: timeout},
|
||||
dataType: "json",
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
var zone_pool = oZones.Helper.pool(resource,response);
|
||||
callback(request, zone_pool);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
"show": function(params)
|
||||
{
|
||||
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var id = params.data.id;
|
||||
|
||||
var resource = oZones.Zone.resource;
|
||||
var request = oZones.Helper.request(resource,"show", id);
|
||||
|
||||
$.ajax({
|
||||
url: "zone/" + id,
|
||||
url: "zone/" + id + "/" + subresource,
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
callback(request, response);
|
||||
}
|
||||
success: function(response){
|
||||
return callback ?
|
||||
callback(request, oZones.Helper.pool(subresource.toUpperCase(),response)) : null;
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
error: function(response){
|
||||
return callback_error ? calback_error(request,oZones.Error(response)) : null;
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
"host": function(params)
|
||||
{
|
||||
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var id = params.data.id;
|
||||
|
||||
var resource = oZones.Zone.resource;
|
||||
var request = oZones.Helper.request(resource,"host", id);
|
||||
|
||||
$.ajax({
|
||||
url: "zone/" + id + "/host",
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
var host_pool = oZones.Helper.pool("HOST",response);
|
||||
callback(request, host_pool);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
"host": function(params){
|
||||
oZones.Zone.subresource(params,"host");
|
||||
},
|
||||
"image": function(params){
|
||||
oZones.Zone.subresource(params,"image");
|
||||
},
|
||||
"vmtemplate": function(params){
|
||||
oZones.Zone.subresource(params,"vmtemplate");
|
||||
},
|
||||
"user": function(params){
|
||||
oZones.Zone.subresource(params,"user");
|
||||
},
|
||||
"vm": function(params){
|
||||
oZones.Zone.subresource(params,"vm");
|
||||
},
|
||||
"vnet": function(params){
|
||||
oZones.Zone.subresource(params,"vnet");
|
||||
},
|
||||
|
||||
"image": function(params)
|
||||
{
|
||||
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var id = params.data.id;
|
||||
|
||||
var resource = oZones.Zone.resource;
|
||||
var request = oZones.Helper.request(resource,"image", id);
|
||||
|
||||
$.ajax({
|
||||
url: "zone/" + id + "/image",
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
var pool = oZones.Helper.pool("IMAGE",response);
|
||||
callback(request, pool);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
"template": function(params)
|
||||
{
|
||||
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var id = params.data.id;
|
||||
|
||||
var resource = oZones.Zone.resource;
|
||||
var request = oZones.Helper.request(resource,"template", id);
|
||||
|
||||
$.ajax({
|
||||
url: "zone/" + id + "/template",
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
var pool = oZones.Helper.pool("VMTEMPLATE",response);
|
||||
callback(request, pool);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
"user": function(params)
|
||||
{
|
||||
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var id = params.data.id;
|
||||
|
||||
var resource = oZones.Zone.resource;
|
||||
var request = oZones.Helper.request(resource,"user", id);
|
||||
|
||||
$.ajax({
|
||||
url: "zone/" + id + "/user",
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
var pool = oZones.Helper.pool("USER",response);
|
||||
callback(request, pool);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
"vm": function(params)
|
||||
{
|
||||
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var id = params.data.id;
|
||||
|
||||
var resource = oZones.Zone.resource;
|
||||
var request = oZones.Helper.request(resource,"vm", id);
|
||||
|
||||
$.ajax({
|
||||
url: "zone/" + id + "/vm",
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
var pool = oZones.Helper.pool("VM",response);
|
||||
callback(request, pool);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
"vn": function(params)
|
||||
{
|
||||
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var id = params.data.id;
|
||||
|
||||
var resource = oZones.Zone.resource;
|
||||
var request = oZones.Helper.request(resource,"vn", id);
|
||||
|
||||
$.ajax({
|
||||
url: "zone/" + id + "/vn",
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
var pool = oZones.Helper.pool("VNET",response);
|
||||
callback(request, pool);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
"group": function(params)
|
||||
{
|
||||
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var id = params.data.id;
|
||||
|
||||
var resource = oZones.Zone.resource;
|
||||
var request = oZones.Helper.request(resource,"group", id);
|
||||
|
||||
$.ajax({
|
||||
url: "zone/" + id + "/group",
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
var pool = oZones.Helper.pool("GROUP",response);
|
||||
callback(request, pool);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
"group": function(params){
|
||||
oZones.Zone.subresource(params,"group");
|
||||
}
|
||||
},
|
||||
|
||||
"VDC": {
|
||||
"resource": "VDC",
|
||||
|
||||
"create": function(params)
|
||||
{
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var data = params.data;
|
||||
var resource = oZones.VDC.resource;
|
||||
|
||||
var request = oZones.Helper.request(resource,"create", data);
|
||||
|
||||
$.ajax({
|
||||
url: "vdc",
|
||||
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, oZones.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
"create": function(params){
|
||||
oZones.Action.create(params,oZones.VDC.resource);
|
||||
},
|
||||
|
||||
"delete": function(params)
|
||||
{
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var id = params.data.id;
|
||||
var resource = oZones.VDC.resource;
|
||||
|
||||
|
||||
var request = oZones.Helper.request(resource,"delete", id);
|
||||
|
||||
$.ajax({
|
||||
url: "vdc/" + id,
|
||||
type: "DELETE",
|
||||
success: function()
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
callback(request);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
"delete": function(params){
|
||||
oZones.Action.delete(params,oZones.VDC.resource);
|
||||
},
|
||||
|
||||
"list": function(params)
|
||||
{
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var timeout = params.timeout || false;
|
||||
|
||||
var resource = oZones.VDC.resource;
|
||||
var request = oZones.Helper.request(resource,"list");
|
||||
|
||||
$.ajax({
|
||||
url: "vdc",
|
||||
type: "GET",
|
||||
data: {timeout: timeout},
|
||||
dataType: "json",
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
var vdc_pool = oZones.Helper.pool(resource,response);
|
||||
callback(request, vdc_pool);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
"list": function(params){
|
||||
oZones.Action.list(params,oZones.VDC.resource);
|
||||
},
|
||||
"show": function(params){
|
||||
oZones.Action.show(params,oZones.VDC.resource);
|
||||
},
|
||||
|
||||
"show": function(params)
|
||||
{
|
||||
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var id = params.data.id;
|
||||
|
||||
var resource = oZones.VDC.resource;
|
||||
var request = oZones.Helper.request(resource,"show", id);
|
||||
|
||||
$.ajax({
|
||||
url: "vdc/" + id,
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
callback(request, response);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
"ZoneHosts": {
|
||||
"resource": "ZONE",
|
||||
|
||||
"list": function(params)
|
||||
{
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var timeout = params.timeout || false;
|
||||
|
||||
var resource = oZones.ZoneHosts.resource;
|
||||
var request = oZones.Helper.request(resource,"list");
|
||||
|
||||
$.ajax({
|
||||
url: "zone/host",
|
||||
type: "GET",
|
||||
data: {timeout: timeout},
|
||||
dataType: "json",
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
var zonehosts_pool = oZones.Helper.pool(resource,response);
|
||||
callback(request, zonehosts_pool);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
"list": function(params){
|
||||
oZones.Action.list(params,oZones.ZoneHosts.resource,"host");
|
||||
}
|
||||
},
|
||||
|
||||
"ZoneVMs": {
|
||||
"resource": "ZONE",
|
||||
|
||||
"list": function(params)
|
||||
{
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var timeout = params.timeout || false;
|
||||
|
||||
var resource = oZones.ZoneVMs.resource;
|
||||
var request = oZones.Helper.request(resource,"list");
|
||||
|
||||
$.ajax({
|
||||
url: "zone/vm",
|
||||
type: "GET",
|
||||
data: {timeout: timeout},
|
||||
dataType: "json",
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
var zonevms_pool = oZones.Helper.pool(resource,response);
|
||||
callback(request, zonevms_pool);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
"list": function(params){
|
||||
oZones.Action.list(params,oZones.ZoneVMs.resource,"vm");
|
||||
}
|
||||
},
|
||||
|
||||
"ZoneVNs": {
|
||||
"resource": "ZONE",
|
||||
|
||||
"list": function(params)
|
||||
{
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var timeout = params.timeout || false;
|
||||
|
||||
var resource = oZones.ZoneVMs.resource;
|
||||
var request = oZones.Helper.request(resource,"list");
|
||||
|
||||
$.ajax({
|
||||
url: "zone/vn",
|
||||
type: "GET",
|
||||
data: {timeout: timeout},
|
||||
dataType: "json",
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
var zonevns_pool = oZones.Helper.pool(resource,response);
|
||||
callback(request, zonevns_pool);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
"list": function(params){
|
||||
oZones.Action.list(params,oZones.ZoneVNs.resource,"vnet");
|
||||
}
|
||||
},
|
||||
|
||||
"ZoneImages": {
|
||||
"resource": "ZONE",
|
||||
|
||||
"list": function(params)
|
||||
{
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var timeout = params.timeout || false;
|
||||
|
||||
var resource = oZones.ZoneImages.resource;
|
||||
var request = oZones.Helper.request(resource,"list");
|
||||
|
||||
$.ajax({
|
||||
url: "zone/image",
|
||||
type: "GET",
|
||||
data: {timeout: timeout},
|
||||
dataType: "json",
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
var zoneimages_pool = oZones.Helper.pool(resource,response);
|
||||
callback(request, zoneimages_pool);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
"list": function(params){
|
||||
oZones.Action.list(params,oZones.ZoneImages.resource,"image");
|
||||
}
|
||||
},
|
||||
|
||||
"ZoneUsers": {
|
||||
"resource": "ZONE",
|
||||
|
||||
"list": function(params)
|
||||
{
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var timeout = params.timeout || false;
|
||||
|
||||
var resource = oZones.ZoneUsers.resource;
|
||||
var request = oZones.Helper.request(resource,"list");
|
||||
|
||||
$.ajax({
|
||||
url: "zone/user",
|
||||
type: "GET",
|
||||
data: {timeout: timeout},
|
||||
dataType: "json",
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
var zoneusers_pool = oZones.Helper.pool(resource,response);
|
||||
callback(request, zoneusers_pool);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
"list": function(params){
|
||||
oZones.Action.list(params,oZones.ZoneImages.resource,"user");
|
||||
}
|
||||
},
|
||||
|
||||
"ZoneTemplates": {
|
||||
"resource": "ZONE",
|
||||
|
||||
"list": function(params)
|
||||
{
|
||||
var callback = params.success;
|
||||
var callback_error = params.error;
|
||||
var timeout = params.timeout || false;
|
||||
|
||||
var resource = oZones.ZoneTemplates.resource;
|
||||
var request = oZones.Helper.request(resource,"list");
|
||||
|
||||
$.ajax({
|
||||
url: "zone/template",
|
||||
type: "GET",
|
||||
data: {timeout: timeout},
|
||||
dataType: "json",
|
||||
success: function(response)
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
var zonetemplates_pool = oZones.Helper.pool(resource,response);
|
||||
callback(request, zonetemplates_pool);
|
||||
}
|
||||
},
|
||||
error: function(response)
|
||||
{
|
||||
if (callback_error)
|
||||
{
|
||||
callback_error(request, oZones.Error(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
"list": function(params){
|
||||
oZones.Action.list(params,oZones.ZoneImages.resource,"vmtemplate");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ var vdc_actions = {
|
||||
type: "custom",
|
||||
call: function() {
|
||||
waitingNodes(dataTable_vdcs);
|
||||
Sunstone.runAction("Zone.list");
|
||||
Sunstone.runAction("VDC.list");
|
||||
},
|
||||
error: onError
|
||||
},
|
||||
|
@ -133,9 +133,9 @@ var zone_actions = {
|
||||
},
|
||||
error: onError
|
||||
},
|
||||
"Zone.vn" : {
|
||||
"Zone.vnet" : {
|
||||
type: "single",
|
||||
call: oZones.Zone.vn,
|
||||
call: oZones.Zone.vnet,
|
||||
callback: function(req, vn_json){
|
||||
updateVNsList(req,vn_json,'#datatable_zone_vnets');
|
||||
},
|
||||
@ -149,9 +149,9 @@ var zone_actions = {
|
||||
},
|
||||
error: onError
|
||||
},
|
||||
"Zone.template" : {
|
||||
"Zone.vmtemplate" : {
|
||||
type: "single",
|
||||
call: oZones.Zone.template,
|
||||
call: oZones.Zone.vmtemplate,
|
||||
callback: function(req,template_json){
|
||||
updateTemplatesList(req,template_json,'#datatable_zone_templates');
|
||||
},
|
||||
@ -519,9 +519,9 @@ function updateZoneInfo(req,zone_json){
|
||||
|
||||
//Retrieve pools in the meantime
|
||||
Sunstone.runAction("Zone.host",zone.id);
|
||||
Sunstone.runAction("Zone.template",zone.id);
|
||||
Sunstone.runAction("Zone.vmtemplate",zone.id);
|
||||
Sunstone.runAction("Zone.vms",zone.id);
|
||||
Sunstone.runAction("Zone.vn",zone.id);
|
||||
Sunstone.runAction("Zone.vnet",zone.id);
|
||||
Sunstone.runAction("Zone.image",zone.id);
|
||||
Sunstone.runAction("Zone.user",zone.id);
|
||||
}
|
||||
|
@ -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
@ -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;
|
||||
});
|
||||
|
@ -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){
|
||||
|
Loading…
x
Reference in New Issue
Block a user