Class: Yao::Client::ClientSet
- Inherits:
-
Object
- Object
- Yao::Client::ClientSet
- Defined in:
- lib/yao/client.rb
Instance Attribute Summary collapse
-
#admin_pool ⇒ Hash { String => Faraday::Connection }
readonly
#pool and #admin_pool returns Hash like below structure.
-
#pool ⇒ Hash { String => Faraday::Connection }
readonly
#pool and #admin_pool returns Hash like below structure.
Instance Method Summary collapse
-
#initialize ⇒ ClientSet
constructor
A new instance of ClientSet.
-
#register_endpoints(endpoints, token: nil) ⇒ Object
endpoints is a Hash like below structure.
Constructor Details
#initialize ⇒ ClientSet
Returns a new instance of ClientSet.
11 12 13 14 |
# File 'lib/yao/client.rb', line 11 def initialize @pool = {} @admin_pool = {} end |
Instance Attribute Details
#admin_pool ⇒ Hash { String => Faraday::Connection } (readonly)
#pool and #admin_pool returns Hash like below structure
"identity" => #<Faraday::Connection:...>,
"image" => #<Faraday::Connection:...>,
24 25 26 |
# File 'lib/yao/client.rb', line 24 def admin_pool @admin_pool end |
#pool ⇒ Hash { String => Faraday::Connection } (readonly)
#pool and #admin_pool returns Hash like below structure
"identity" => #<Faraday::Connection:...>,
"image" => #<Faraday::Connection:...>,
24 25 26 |
# File 'lib/yao/client.rb', line 24 def pool @pool end |
Instance Method Details
#register_endpoints(endpoints, token: nil) ⇒ Object
endpoints is a Hash like below structure
{
"identity" => {
public_url: "https://example.com/mitaka/keystone/v3",
internal_url: "https://example.com/mitaka/keystone/v3",
admin_url: "https://example.com/mitaka/admin/keystone/v3"
},
"image" => {
...
},
}
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/yao/client.rb', line 53 def register_endpoints(endpoints, token: nil) # type is String (e.g. network, identity, ... ) # urls is Hash{ Symbol => String } 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| url = File.join(url, "v2.0") [public_or_admin, url] }.to_h end # User can override the public_url and admin_url of endpoints by setting Yao.configure # For example. # # Yao.configure do # endpoints identity: { public: "http://override-endpoint.example.com:35357/v3.0" } # end # force_public_url = Yao.config.endpoints[type.to_sym][:public] rescue nil force_admin_url = Yao.config.endpoints[type.to_sym][:admin] rescue nil if force_public_url || urls[:public_url] self.pool[type] = Yao::Client.gen_client(force_public_url || urls[:public_url], token: token) end if force_admin_url || urls[:admin_url] self.admin_pool[type] = Yao::Client.gen_client(force_admin_url || urls[:admin_url], token: token) end end end |