Method: KnifeCloudstack::CsStackCreate#search_nodes

Defined in:
lib/chef/knife/cs_stack_create.rb

#search_nodes(query, attribute = nil) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/chef/knife/cs_stack_create.rb', line 169

def search_nodes(query, attribute=nil)
  if get_environment
    query = "(#{query})" + " AND chef_environment:#{get_environment}"
  end

  Chef::Log.debug("Searching for nodes: #{query}")

  q = Chef::Search::Query.new
  nodes = Array(q.search(:node, query))

  # the array of nodes is the first item in the array returned by the search
  if nodes.length > 1
    nodes = nodes.first || []
  end

  # return attribute values instead of nodes
  if attribute
    nodes.map do |node|
      node[attribute.to_s]
    end
  else
    nodes
  end
end