Class: RightScale::MetadataSource
- Defined in:
- lib/clouds/metadata_source.rb
Overview
Interface for a metadata source.
Direct Known Subclasses
RightScale::MetadataSources::CertificateMetadataSource, RightScale::MetadataSources::FileMetadataSource, RightScale::MetadataSources::HttpMetadataSource, RightScale::MetadataSources::SelectiveMetadataSource
Defined Under Namespace
Classes: QueryFailed
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#append_branch_name(path, branch_name) ⇒ Object
Appends a branch name to the given path.
-
#append_leaf_name(path, leaf_name) ⇒ Object
Appends a leaf name to the given path.
-
#finish ⇒ Object
Releases any resources used to query metadata.
-
#initialize(options) ⇒ MetadataSource
constructor
A new instance of MetadataSource.
-
#query(path) ⇒ Object
Queries for metadata using the given path.
Constructor Details
#initialize(options) ⇒ MetadataSource
Returns a new instance of MetadataSource.
33 34 35 |
# File 'lib/clouds/metadata_source.rb', line 33 def initialize() raise ArgumentError, "options[:logger] is required" unless @logger = [:logger] end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
31 32 33 |
# File 'lib/clouds/metadata_source.rb', line 31 def logger @logger end |
Instance Method Details
#append_branch_name(path, branch_name) ⇒ Object
Appends a branch name to the given path.
Parameters
- path(String)
-
metadata path
- branch_name(String)
-
branch name to append
Return
- result(String)
-
updated path
45 46 47 48 49 50 |
# File 'lib/clouds/metadata_source.rb', line 45 def append_branch_name(path, branch_name) # remove anything after equals. branch_name = branch_name.gsub(/\=.*$/, '') branch_name = "#{branch_name}/" unless '/' == branch_name[-1..-1] return append_leaf_name(path, branch_name) end |
#append_leaf_name(path, leaf_name) ⇒ Object
Appends a leaf name to the given path.
Parameters
- path(String)
-
metadata path
- leaf_name(String)
-
leaf name to append
Return
- result(String)
-
updated path
60 61 62 63 |
# File 'lib/clouds/metadata_source.rb', line 60 def append_leaf_name(path, leaf_name) path = "#{path}/" unless '/' == path[-1..-1] return "#{path}#{URI.escape(leaf_name)}" end |
#finish ⇒ Object
Releases any resources used to query metadata. Must be called before releasing source.
81 82 83 |
# File 'lib/clouds/metadata_source.rb', line 81 def finish raise NotImplementedError end |
#query(path) ⇒ Object
Queries for metadata using the given path.
Parameters
- path(String)
-
metadata path
Return
- metadata(String)
-
query result or empty
Raises
- QueryFailed
-
on any failure to query
75 76 77 |
# File 'lib/clouds/metadata_source.rb', line 75 def query(path) raise NotImplementedError end |