Module: Chef::Knife::Update

Included in:
UpdateRecipes, UpdateRun, UpdateStatus
Defined in:
lib/chef/knife/update.rb

Class Method Summary collapse

Instance Method Summary collapse

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



91
92
93
94
95
# File 'lib/chef/knife/update.rb', line 91

def except(mapping, key)
  mapping.inject([]) do |memo, (k, values)|
    k == key ? memo : memo += values
  end
end

#node_listObject

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



87
88
89
# File 'lib/chef/knife/update.rb', line 87

def only(mapping, key)
  mapping[key] || []
end

#recipes(nodes) ⇒ Object

List of all compatible recipes



71
72
73
74
75
76
77
78
79
80
# File 'lib/chef/knife/update.rb', line 71

def recipes(nodes)
  nodes.inject({}) do |memo, node|
    node.recipes.each do |recipe|
      memo[recipe.to_s] ||= 0
      memo[recipe.to_s] += 1
    end

    memo
  end
end

#target_versionObject

Returns target update chef version



83
84
85
# File 'lib/chef/knife/update.rb', line 83

def target_version
  config[:target_version] || Chef::VERSION
end