Class: RightScale::MetadataSources::SelectiveMetadataSource
- Inherits:
-
RightScale::MetadataSource
- Object
- RightScale::MetadataSource
- RightScale::MetadataSources::SelectiveMetadataSource
- Defined in:
- lib/clouds/metadata_sources/selective_metadata_source.rb
Overview
Provides metadata by attempting to get metadata from one or more listed sources; first responding successfully wins.
Instance Attribute Summary collapse
-
#metadata_sources ⇒ Object
Returns the value of attribute metadata_sources.
Attributes inherited from RightScale::MetadataSource
Instance Method Summary collapse
-
#finish ⇒ Object
Attempts to finish all child metadata sources.
-
#initialize(options) ⇒ SelectiveMetadataSource
constructor
A new instance of SelectiveMetadataSource.
-
#query(path) ⇒ Object
Queries for metadata using the given path.
-
#select_metadata(path, metadata_source_type, query_result, previous_metadata) ⇒ Object
Selects metadata by determining if the metadata condition has been satisfied.
Methods inherited from RightScale::MetadataSource
#append_branch_name, #append_leaf_name
Constructor Details
#initialize(options) ⇒ SelectiveMetadataSource
Returns a new instance of SelectiveMetadataSource.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/clouds/metadata_sources/selective_metadata_source.rb', line 33 def initialize() raise ArgumentError, "options[:metadata_sources] is required" unless = [:metadata_source_types] raise ArgumentError, "options[:cloud] is required" unless @cloud = [:cloud] = [:select_metadata_override] # keep types but create selective sources on demand in case not all are used. = [] .each do || << { :type => , :source => nil } end end |
Instance Attribute Details
#metadata_sources ⇒ Object
Returns the value of attribute metadata_sources.
31 32 33 |
# File 'lib/clouds/metadata_sources/selective_metadata_source.rb', line 31 def end |
Instance Method Details
#finish ⇒ Object
Attempts to finish all child metadata sources.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/clouds/metadata_sources/selective_metadata_source.rb', line 103 def finish last_exception = nil .each do || begin source = [:source] source.finish if source rescue Exception => e last_exception = e ensure [:source] = nil end end raise last_exception if last_exception end |
#query(path) ⇒ Object
Queries for metadata using the given path.
Parameters
- path(String)
-
metadata path
Return
- metadata(String)
-
query result
Raises
- QueryFailed
-
on any failure to query
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 |
# File 'lib/clouds/metadata_sources/selective_metadata_source.rb', line 55 def query(path) = "" last_query_failed = nil .each do || type = [:type] unless source = [:source] # note that sources are special in that they ignore cloud vs. user # specialization unlike other dependency types. kind = :cloud_metadata source = @cloud.create_dependency_type(kind, :metadata_source, type) [:source] = source end begin query_result = source.query(path) selected = (path, type, query_result, ) = selected[:merged_metadata] last_query_failed = nil # reset last failed query break unless selected[:query_next_metadata] rescue QueryFailed => e # temporarily ignore failed query in case next source query succeeds last_query_failed = e end end raise last_query_failed if last_query_failed return rescue Exception => e raise QueryFailed.new(e.) end |
#select_metadata(path, metadata_source_type, query_result, previous_metadata) ⇒ Object
Selects metadata by determining if the metadata condition has been satisfied. Supports merging of metadata (potentially in different formats) from different sources.
Parameters
- path(String)
-
metadata path
- metadata_source_type(String)
-
metadata source type
- query_result(String)
-
raw metadata from query
- previous_metadata(String)
-
previously merged metadata or empty
Returns
97 98 99 100 |
# File 'lib/clouds/metadata_sources/selective_metadata_source.rb', line 97 def (path, , query_result, ) return .call(self, path, , query_result, ) if return {:query_next_metadata => query_result.strip.empty?, :merged_metadata => query_result} end |