mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
Feature #799: Refactor ozones.js code
This commit refactors the code in ozone.js. In order to allow as much refactoring as possible, server and zones plugin have been modified so that a better consistency is achieved: - "vnet" replaces "vn" to identify virtual networks resource. - "vmtemplate" replaces "template" to identify virtual machine templates. In the server side, all "vnet", "vn" / "vmtemplate", "template" produce the same result, so that the CLI spec and oZones doc are not affected by this change. Note: Additional changes on OzonesServer.rb correspond to whitespace cleanup.
This commit is contained in:
parent
09c0960d23
commit
b3ead895eb
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user