Class: Miasma::Contrib::OpenStackApiCore
- Inherits:
-
Object
- Object
- Miasma::Contrib::OpenStackApiCore
- Includes:
- Utils::Memoization
- Defined in:
- lib/miasma/contrib/open_stack.rb
Overview
OpenStack API core helper
Direct Known Subclasses
Defined Under Namespace
Modules: ApiCommon Classes: Authenticate
Constant Summary collapse
- API_MAP =
Returns Mapping to external service name.
Smash.new( 'compute' => 'nova', 'orchestration' => 'heat', 'network' => 'neutron', 'identity' => 'keystone' )
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#api_token ⇒ String
API token.
-
#endpoint_for(api_name, region) ⇒ String
Provide end point URL for service.
-
#identity_class(i_name) ⇒ Class
Class from instance class, falls back to parent.
-
#initialize(creds) ⇒ self
constructor
Create a new api instance.
Methods included from Utils::Memoization
#_memo, #clear_memoizations!, #memoize, #unmemoize
Constructor Details
#initialize(creds) ⇒ self
Create a new api instance
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/miasma/contrib/open_stack.rb', line 271 def initialize(creds) @credentials = creds memo_key = "miasma_open_stack_identity_#{creds.checksum}" if(creds[:open_stack_identity_url].include?('v3')) @identity = memoize(memo_key, :direct) do identity_class('Authenticate::Version3').new(creds) end elsif(creds[:open_stack_identity_url].include?('v2')) @identity = memoize(memo_key, :direct) do identity_class('Authenticate::Version2').new(creds) end else # @todo allow attribute to override? raise ArgumentError.new('Failed to determine Identity service version') end end |
Instance Attribute Details
#identity ⇒ Miasma::Contrib::OpenStackApiCore::Authenticate (readonly)
265 266 267 |
# File 'lib/miasma/contrib/open_stack.rb', line 265 def identity @identity end |
Instance Method Details
#api_token ⇒ String
Returns API token.
332 333 334 |
# File 'lib/miasma/contrib/open_stack.rb', line 332 def api_token identity.api_token end |
#endpoint_for(api_name, region) ⇒ String
Provide end point URL for service
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/miasma/contrib/open_stack.rb', line 306 def endpoint_for(api_name, region) api = self.class.const_get(:API_MAP)[api_name] srv = identity.service_catalog.detect do |info| info[:name] == api end unless(srv) raise NotImplementedError.new("No API mapping found for `#{api_name}`") end if(region) point = srv[:endpoints].detect do |endpoint| endpoint[:region].to_s.downcase == region.to_s.downcase end else point = srv[:endpoints].first end if(point) point.fetch( :publicURL, point[:url] ) else raise KeyError.new("Lookup failed for `#{api_name}` within region `#{region}`") end end |
#identity_class(i_name) ⇒ Class
Returns class from instance class, falls back to parent.
289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/miasma/contrib/open_stack.rb', line 289 def identity_class(i_name) [self.class, Miasma::Contrib::OpenStackApiCore].map do |klass| i_name.split('::').inject(klass) do |memo, key| if(memo.const_defined?(key)) memo.const_get(key) else break end end end.compact.first end |