Module: Chef::Knife::Update
- Included in:
- UpdateRun, UpdateRunList, UpdateStatus
- Defined in:
- lib/chef/knife/update.rb
Class Method Summary collapse
Instance Method Summary collapse
- #except(mapping, key) ⇒ Object
-
#node_list ⇒ Object
Get a list of nodes and their used chef version.
- #only(mapping, key) ⇒ Object
-
#run_list_items(nodes) ⇒ Object
List of all compatible run_list items.
-
#target_version ⇒ Object
Returns target update chef version.
Class Method Details
.included(includer) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/chef/knife/update.rb', line 24 def self.included(includer) includer.class_eval do deps do require 'net/ssh' require 'net/ssh/multi' require 'chef/knife/ssh' require 'chef/search/query' Chef::Knife::Ssh.load_deps end option :query, :short => "-q QUERY", :long => "--search-query QUERY", :description => "Filter nodes by search query", :default => '*:*' option :target_version, :short => "-t VERSION", :long => "--target-version VERSION", :description => "The target chef-client version", :default => Chef::VERSION end end |
Instance Method Details
#except(mapping, key) ⇒ Object
90 91 92 93 94 |
# File 'lib/chef/knife/update.rb', line 90 def except(mapping, key) mapping.inject([]) do |memo, (k, values)| k == key ? memo : memo += values end end |
#node_list ⇒ Object
Get a list of nodes and their used chef version
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/chef/knife/update.rb', line 51 def node_list list = {} search = Chef::Search::Query.new query = config[:query] ui.msg "Search nodes '#{query}'" search.search('node', query) do |node| if node['chef'] && node['chef']['client_version'] version = node['chef']['client_version'] list[version] ||= [] list[version] << node end end ui.msg '' list end |
#only(mapping, key) ⇒ Object
86 87 88 |
# File 'lib/chef/knife/update.rb', line 86 def only(mapping, key) mapping[key] || [] end |
#run_list_items(nodes) ⇒ Object
List of all compatible run_list items
71 72 73 74 75 76 77 78 79 |
# File 'lib/chef/knife/update.rb', line 71 def run_list_items(nodes) nodes.inject([]) do |memo, node| node.run_list.each do |item| memo << item.to_s unless memo.include?(item.to_s) end memo end end |
#target_version ⇒ Object
Returns target update chef version
82 83 84 |
# File 'lib/chef/knife/update.rb', line 82 def target_version config[:target_version] || Chef::VERSION end |