Class: Aether::Chef
- Inherits:
-
Object
- Object
- Aether::Chef
- Defined in:
- lib/aether/chef.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
Instance Method Summary collapse
- #build_search_query(options = {}) ⇒ Object
- #find_data_bag_item(bag_name, item_name) ⇒ Object
- #find_nodes(options = {}, include_environment = true) ⇒ Object
-
#initialize(opts = {}) ⇒ Chef
constructor
A new instance of Chef.
Constructor Details
#initialize(opts = {}) ⇒ Chef
Returns a new instance of Chef.
6 7 8 9 10 11 12 13 14 |
# File 'lib/aether/chef.rb', line 6 def initialize(opts = {}) @connection = Ridley.new( server_url: opts[:server_url], client_name: opts[:client_name], client_key: opts[:client_key] ) @environment = opts[:environment] end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
4 5 6 |
# File 'lib/aether/chef.rb', line 4 def connection @connection end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
4 5 6 |
# File 'lib/aether/chef.rb', line 4 def environment @environment end |
Instance Method Details
#build_search_query(options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/aether/chef.rb', line 33 def build_search_query( = {}) include_environment = [:include_environment] roles = [:roles] || [] str = '' str << "chef_environment:#{environment}" if include_environment unless roles.empty? str << " AND " if include_environment str << build_search_roles_query(roles) end str end |
#find_data_bag_item(bag_name, item_name) ⇒ Object
28 29 30 31 |
# File 'lib/aether/chef.rb', line 28 def find_data_bag_item(bag_name, item_name) data_bag_item = connection.data_bag.all.find{ |bag| bag.name == bag_name }.item.find(item_name) Aether::DataBagItem.new(data_bag_item) end |
#find_nodes(options = {}, include_environment = true) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/aether/chef.rb', line 16 def find_nodes( = {}, include_environment = true) roles = [:roles] || [] results = [] search_str = build_search_query(:include_environment => include_environment, :roles => roles) connection.search(:node, search_str).each do |node| results << Aether::Node.new(node) end results end |