Class: Openstack::Client::ServiceCatalog
- Inherits:
-
Object
- Object
- Openstack::Client::ServiceCatalog
- Defined in:
- lib/openstack-client/service_catalog.rb
Overview
Helper class for dealing with a Keystone Service Catalog.
Instance Attribute Summary collapse
-
#catalog ⇒ Object
Returns the value of attribute catalog.
Instance Method Summary collapse
-
#endpoints(options = {}) ⇒ Object
Fetch and filter endpoints for the specified service(s).
-
#initialize(resource_dict) ⇒ ServiceCatalog
constructor
A new instance of ServiceCatalog.
-
#token ⇒ Hash
Fetch token details fron service catalog.
-
#url_for(options = {}) ⇒ Object
Fetch an endpoint from the service catalog.
Constructor Details
#initialize(resource_dict) ⇒ ServiceCatalog
Returns a new instance of ServiceCatalog.
12 13 14 |
# File 'lib/openstack-client/service_catalog.rb', line 12 def initialize resource_dict self.catalog = resource_dict end |
Instance Attribute Details
#catalog ⇒ Object
Returns the value of attribute catalog.
10 11 12 |
# File 'lib/openstack-client/service_catalog.rb', line 10 def catalog @catalog end |
Instance Method Details
#endpoints(options = {}) ⇒ Object
Fetch and filter endpoints for the specified service(s)
Returns endpoints for the specified service (or all) and that contain the specified type (or all).
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/openstack-client/service_catalog.rb', line 65 def endpoints ={} service_type = [:service_type] endpoint_type = [:endpoint_type] return {}.tap do |rtn| catalog = self.catalog['serviceCatalog'] || [] catalog.each do |service| next if service_type and service_type != service['type'] rtn[service['type']] = [] service['endpoints'].each do |endpoint| next if endpoint_type and endpoint.include?(endpoint_type) rtn[service['type']] << endpoint end end end end |
#token ⇒ Hash
Fetch token details fron service catalog
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/openstack-client/service_catalog.rb', line 18 def token unless defined?(@token) @token = { 'id' => self.catalog['token']['id'], 'expires' => Time.parse(self.catalog['token']['expires']) } @token['tenant'] = self.catalog['token']['tenant']['id'] if self.catalog['token']['tenant'] end @token end |
#url_for(options = {}) ⇒ Object
Fetch an endpoint from the service catalog.
Fetch the specified endpoint from the service catalog for a particular endpoint attribute. If no attribute is given, return the first endpoint of the specified type.
See tests for a sample service catalog.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/openstack-client/service_catalog.rb', line 42 def url_for ={} service_type = [:service_type] || 'identity' endpoint_type = [:endpoint_type] || 'publicURL' attribute = [:attribute] filter_value = [:filter_value] catalog = self.catalog['serviceCatalog'] || [] catalog.each do |service| next unless service['type'] == service_type service['endpoints'].each do |endpoint| return endpoint[endpoint_type] if filter_value.nil? || endpoint[attribute] == filter_value end end raise 'Endpoint not found.' end |