Class: VCAP::Services::CloudControllerServices
- Defined in:
- lib/base/cloud_controller_services.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #each(seed_url, description, &block) ⇒ Object
-
#initialize(http_client, headers, logger) ⇒ CloudControllerServices
constructor
A new instance of CloudControllerServices.
- #load_registered_services(service_list_uri) ⇒ Object
Constructor Details
#initialize(http_client, headers, logger) ⇒ CloudControllerServices
Returns a new instance of CloudControllerServices.
6 7 8 9 10 |
# File 'lib/base/cloud_controller_services.rb', line 6 def initialize(http_client, headers, logger) @http_client = http_client @headers = headers @logger = logger end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
12 13 14 |
# File 'lib/base/cloud_controller_services.rb', line 12 def logger @logger end |
Instance Method Details
#each(seed_url, description, &block) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/base/cloud_controller_services.rb', line 53 def each(seed_url, description, &block) url = seed_url logger.info("Fetching #{description} from: #{seed_url}") while !url.nil? do logger.debug("#{self.class.name}: Fetching #{description} from: #{url}") @http_client.call(:uri => url, :method => "get", :head => @headers, :need_raise => true) do |http| result = nil if (200..299) === http.response_header.status result = JSON.parse(http.response) else raise "CCNG Catalog Manager: - Multiple page fetch via: #{url} failed: (#{http.response_header.status}) - #{http.response}" end result.fetch("resources").each { |r| block.yield r } url = result["next_url"] end end end |
#load_registered_services(service_list_uri) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/base/cloud_controller_services.rb', line 14 def load_registered_services(service_list_uri) logger.debug("Getting services listing from cloud_controller") registered_services = [] self.each(service_list_uri, "Registered Offerings") do |s| entity = s["entity"] plans = [] logger.debug("Getting service plans for: #{entity["label"]}/#{entity["provider"]}") self.each(entity.fetch("service_plans_url"), "Service Plans") do |p| plan_entity = p.fetch('entity') = p.fetch('metadata') plans << Plan.new( :unique_id => plan_entity.fetch("unique_id"), :guid => .fetch("guid"), :name => plan_entity.fetch("name"), :description => plan_entity.fetch("description"), :free => plan_entity.fetch("free"), ) end registered_services << Service.new( 'guid' => s["metadata"]["guid"], 'label' => entity["label"], 'unique_id' => entity["unique_id"], 'description' => entity["description"], 'provider' => entity["provider"], 'version' => entity['version'], 'url' => entity["url"], 'info_url' => entity["info_url"], 'extra' => entity['extra'], 'plans' => plans, 'bindable' => entity['bindable'] ) end registered_services end |