1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-19 06:50:07 +03:00

Refactor get pool method from sunstone

This commit is contained in:
Tino Vazquez 2014-02-07 17:12:17 +01:00
parent 57ee51b077
commit 9983689e96
2 changed files with 15 additions and 50 deletions

View File

@ -42,43 +42,9 @@ class SunstoneServer < CloudServer
############################################################################
#
############################################################################
def get_pool(kind,gid)
if gid == "0"
user_flag = Pool::INFO_ALL
else
user_flag = POOL_FILTER
end
def get_pool(kind,gid, client=nil)
client = @client if !client
pool = case kind
when "group" then GroupPoolJSON.new(@client)
when "cluster" then ClusterPoolJSON.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)
when "datastore" then DatastorePoolJSON.new(@client)
when "zone" then ZonePoolJSON.new(@client)
else
error = Error.new("Error: #{kind} resource not supported")
return [404, error.to_json]
end
rc = pool.get_hash
if OpenNebula.is_error?(rc)
return [500, rc.to_json]
else
return [200, rc.to_json]
end
end
############################################################################
#
############################################################################
def get_pool_in_zone(kind,gid,client)
if gid == "0"
user_flag = Pool::INFO_ALL
else
@ -109,7 +75,7 @@ class SunstoneServer < CloudServer
else
return [200, rc.to_json]
end
end
end
############################################################################
#

View File

@ -405,21 +405,20 @@ end
# GET Pool information
##############################################################################
get '/:pool' do
zone_client = nil
if params[:zone_id]
zone = OpenNebula::Zone.new_with_id(params[:zone_id].to_i,
$cloud_auth.client(session[:user]))
rc = zone.info
return [500, rc.message] if OpenNebula.is_error?(rc)
zone_client = $cloud_auth.client(session[:user],
zone['TEMPLATE/ENDPOINT'])
@SunstoneServer.get_pool_in_zone(params[:pool],
session[:user_gid],
zone_client)
else
@SunstoneServer.get_pool(params[:pool], session[:user_gid])
end
if params[:zone_id]
zone = OpenNebula::Zone.new_with_id(params[:zone_id].to_i,
$cloud_auth.client(session[:user]))
rc = zone.info
return [500, rc.message] if OpenNebula.is_error?(rc)
zone_client = $cloud_auth.client(session[:user],
zone['TEMPLATE/ENDPOINT'])
end
@SunstoneServer.get_pool(params[:pool],
session[:user_gid],
zone_client)
end
##############################################################################