berkshelf / ridley

A reliable Chef API client with a clean syntax
Other
231 stars 85 forks source link

Allow ridley.search to return only a list of attrs for selected nodes/roles/.. #304

Closed BarthV closed 8 years ago

BarthV commented 9 years ago

Hi !

Something I like with knife search is -a option. I personally make a intensive use of it, like this trivial example :

> knife search node 'name:my-server-*' -a memory.total -a memory.swap.total
4 items found

my-server-04:
  memory.swap.total: 8388600kB
  memory.total:      8178868kB

my-server-01:
  memory.swap.total: 0kB
  memory.total:      33000552kB

my-server-03:
  memory.swap.total: 24012792kB
  memory.total:      16417888kB

my-server-02:
  memory.swap.total: 0kB
  memory.total:      32945692kB

Is It possible to create an option in ridley.search to return only the selected key(s) ? It could be possible to pass an attribute array to search function as optionnal attr.

saikiranrgda commented 9 years ago

Try this.

require 'ridley'
r = Ridley.from_chef_config(File.expand_path('~/.chef/knife.rb'))
nodes = r.partial_search(:node, 'name:my-server-*', ['memory.total'])
nodes.each { |n| puts n.automatic.memory.total }

you can also list multiple attributes in the query array.

BarthV commented 8 years ago

I'll try thanks