mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[rackspace|identity] updated service catalog support service net
This commit is contained in:
parent
49debe9146
commit
e98fb89882
2 changed files with 17 additions and 8 deletions
|
@ -15,25 +15,29 @@ module Fog
|
||||||
catalog.collect {|s| s["name"]}
|
catalog.collect {|s| s["name"]}
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_endpoints(service_type)
|
def get_endpoints(service_type, service_net=false)
|
||||||
h = catalog.find {|service| service["name"] == service_type.to_s}
|
h = catalog.find {|service| service["name"] == service_type.to_s}
|
||||||
h ? h["endpoints"] : {}
|
return {} unless h
|
||||||
|
|
||||||
|
key = network_type_key(service_net)
|
||||||
|
h["endpoints"].select {|e| e[key]}
|
||||||
end
|
end
|
||||||
|
|
||||||
def display_service_regions(service_type)
|
|
||||||
endpoints = get_endpoints(service_type)
|
def display_service_regions(service_type, service_net=false)
|
||||||
|
endpoints = get_endpoints(service_type, service_net)
|
||||||
regions = endpoints.collect do |e|
|
regions = endpoints.collect do |e|
|
||||||
e["region"] ? ":#{e["region"].downcase}" : ":global"
|
e["region"] ? ":#{e["region"].downcase}" : ":global"
|
||||||
end
|
end
|
||||||
regions.join(", ")
|
regions.join(", ")
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_endpoint(service_type, region=nil, service_net=nil)
|
def get_endpoint(service_type, region=nil, service_net=false)
|
||||||
service_region = region_key(region)
|
service_region = region_key(region)
|
||||||
|
|
||||||
network_type = service_net ? "internalURL" : "publicURL"
|
network_type = network_type_key(service_net)
|
||||||
|
|
||||||
endpoints = get_endpoints(service_type)
|
endpoints = get_endpoints(service_type, service_net)
|
||||||
raise "Unable to locate endpoint for service #{service_type}" if endpoints.empty?
|
raise "Unable to locate endpoint for service #{service_type}" if endpoints.empty?
|
||||||
|
|
||||||
if endpoints.size > 1 && region.nil?
|
if endpoints.size > 1 && region.nil?
|
||||||
|
@ -64,6 +68,10 @@ module Fog
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def network_type_key(service_net)
|
||||||
|
service_net ? "internalURL" : "publicURL"
|
||||||
|
end
|
||||||
|
|
||||||
def matching_region?(h, region)
|
def matching_region?(h, region)
|
||||||
region_key(h["region"]) == region
|
region_key(h["region"]) == region
|
||||||
end
|
end
|
||||||
|
|
|
@ -109,5 +109,6 @@ Shindo.tests('Fog::Rackspace::ServiceCatalog | users', ['rackspace']) do
|
||||||
|
|
||||||
tests('display_service_regions') do
|
tests('display_service_regions') do
|
||||||
returns(":dfw, :ord, :global") { @service_catalog.display_service_regions(:cloudServersOpenStack) }
|
returns(":dfw, :ord, :global") { @service_catalog.display_service_regions(:cloudServersOpenStack) }
|
||||||
|
returns(":dfw, :ord") { @service_catalog.display_service_regions(:cloudFiles, true) }
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in a new issue