Class: Yao::Client::ClientSet

Inherits:
Object
  • Object
show all
Defined in:
lib/yao/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClientSet

Returns a new instance of ClientSet.



8
9
10
11
# File 'lib/yao/client.rb', line 8

def initialize
  @pool       = {}
  @admin_pool = {}
end

Instance Attribute Details

#admin_poolObject (readonly)

Returns the value of attribute admin_pool.



12
13
14
# File 'lib/yao/client.rb', line 12

def admin_pool
  @admin_pool
end

#poolObject (readonly)

Returns the value of attribute pool.



12
13
14
# File 'lib/yao/client.rb', line 12

def pool
  @pool
end

Instance Method Details

#register_endpoints(endpoints, token: nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/yao/client.rb', line 24

def register_endpoints(endpoints, token: nil)
  endpoints.each_pair do |type, urls|
    # XXX: neutron just have v2.0 API and endpoint may not have version prefix
    if type == "network"
      urls = urls.map {|public_or_admin, url|
        path = URI.parse(url).path
        url = (path == '' || path == '/') ? File.join(url, "v2.0") : url
        [public_or_admin, url]
      }.to_h
    end

    self.pool[type]       = Yao::Client.gen_client(urls[:public_url], token: token) if urls[:public_url]
    self.admin_pool[type] = Yao::Client.gen_client(urls[:admin_url],  token: token) if urls[:admin_url]
  end
end