Class: Fog::Rackspace::Identity::ServiceCatalog
- Defined in:
- lib/fog/rackspace/models/identity/service_catalog.rb
Instance Attribute Summary collapse
-
#catalog ⇒ Object
readonly
Returns the value of attribute catalog.
Attributes inherited from Model
Class Method Summary collapse
Instance Method Summary collapse
- #display_service_regions(service_name, service_net = false) ⇒ Object
- #get_endpoint(service_name, region = nil, service_net = false) ⇒ Object
- #get_endpoints(service_name, service_net = false) ⇒ Object
-
#initialize(attributes) ⇒ ServiceCatalog
constructor
A new instance of ServiceCatalog.
- #reload ⇒ Object
- #services ⇒ Object
Methods inherited from Model
#inspect, #symbolize_keys, #to_json, #wait_for
Methods included from Attributes::ClassMethods
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
Methods included from Core::DeprecatedConnectionAccessors
#connection, #connection=, #prepare_service_value
Methods included from Attributes::InstanceMethods
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one
Constructor Details
#initialize(attributes) ⇒ ServiceCatalog
Returns a new instance of ServiceCatalog.
9 10 11 12 |
# File 'lib/fog/rackspace/models/identity/service_catalog.rb', line 9 def initialize(attributes) @service = attributes.delete(:service) @catalog = attributes.delete(:catalog) || {} end |
Instance Attribute Details
#catalog ⇒ Object (readonly)
Returns the value of attribute catalog.
7 8 9 |
# File 'lib/fog/rackspace/models/identity/service_catalog.rb', line 7 def catalog @catalog end |
Class Method Details
.from_response(service, hash) ⇒ Object
64 65 66 |
# File 'lib/fog/rackspace/models/identity/service_catalog.rb', line 64 def self.from_response(service, hash) ServiceCatalog.new :service => service, :catalog => hash["access"]["serviceCatalog"] end |
Instance Method Details
#display_service_regions(service_name, service_net = false) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/fog/rackspace/models/identity/service_catalog.rb', line 26 def display_service_regions(service_name, service_net=false) endpoints = get_endpoints(service_name, service_net) regions = endpoints.collect do |e| e["region"] ? ":#{e["region"].downcase}" : ":global" end regions.join(", ") end |
#get_endpoint(service_name, region = nil, service_net = false) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fog/rackspace/models/identity/service_catalog.rb', line 34 def get_endpoint(service_name, region=nil, service_net=false) service_region = region_key(region) network_type = network_type_key(service_net) endpoints = get_endpoints(service_name, service_net) raise "Unable to locate endpoint for service #{service_name}" if endpoints.empty? if endpoints.size > 1 && region.nil? raise "There are multiple endpoints available for #{service_name}. Please specify one of the following regions: #{display_service_regions(service_name)}." end # select multiple endpoints endpoint = endpoints.find {|e| matching_region?(e, service_region) } return endpoint[network_type] if endpoint && endpoint[network_type] # endpoint doesnt have region if endpoints.size == 1 && matching_region?(endpoints[0], "GLOBAL") return endpoints[0][network_type] end raise "Unknown region :#{region} for service #{service_name}. Please use one of the following regions: #{display_service_regions(service_name)}" end |
#get_endpoints(service_name, service_net = false) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/fog/rackspace/models/identity/service_catalog.rb', line 18 def get_endpoints(service_name, service_net=false) h = catalog.find {|service| service["name"] == service_name.to_s} return {} unless h key = network_type_key(service_net) h["endpoints"].select {|e| e[key]} end |
#reload ⇒ Object
58 59 60 61 62 |
# File 'lib/fog/rackspace/models/identity/service_catalog.rb', line 58 def reload @service.authenticate @catalog = @service.service_catalog.catalog self end |
#services ⇒ Object
14 15 16 |
# File 'lib/fog/rackspace/models/identity/service_catalog.rb', line 14 def services catalog.collect {|s| s["name"]} end |