knife-update 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/knife-update.gemspec CHANGED
@@ -16,6 +16,6 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ['lib']
18
18
 
19
- s.add_dependency 'chef', '>= 0.10.24'
19
+ s.add_dependency 'chef', '>= 10.24.0'
20
20
  s.add_development_dependency 'rspec'
21
21
  end
@@ -62,6 +62,7 @@ class Chef
62
62
  list[version] << node
63
63
  end
64
64
  end
65
+ ui.msg ''
65
66
 
66
67
  list
67
68
  end
@@ -81,6 +82,16 @@ class Chef
81
82
  def target_version
82
83
  config[:target_version] || Chef::VERSION
83
84
  end
85
+
86
+ def only(mapping, key)
87
+ mapping[key] || []
88
+ end
89
+
90
+ def except(mapping, key)
91
+ mapping.inject([]) do |memo, (k, values)|
92
+ k == key ? memo : memo += values
93
+ end
94
+ end
84
95
  end
85
96
  end
86
97
  end
@@ -62,16 +62,23 @@ class Chef
62
62
  :description => "Execute the update via sudo",
63
63
  :boolean => true
64
64
 
65
+ option :all,
66
+ :short => "-a",
67
+ :long => "--all",
68
+ :description => "Update all nodes found by the given search-query",
69
+ :boolean => true
70
+
65
71
  include Chef::Knife::Update
66
72
 
67
73
  def run
68
- list = node_list
69
- items = run_list_items(list[target_version])
74
+ list = node_list
75
+ compatible = run_list_items(only(list, target_version))
76
+ unknown = run_list_items(except(list, target_version)) - compatible
70
77
 
71
78
  nodes = list.inject([]) do |memo, (version, nodes)|
72
79
  if version != target_version
73
80
  nodes.each do |node|
74
- if node.run_list.all? { |item| items.include?(item.to_s) }
81
+ if config[:all] || node.run_list.all? { |item| items.include?(item.to_s) }
75
82
  memo << node
76
83
  end
77
84
  end
@@ -80,7 +87,11 @@ class Chef
80
87
  memo
81
88
  end
82
89
 
83
- ui.msg "\nUpdate #{nodes.size} nodes to chef #{target_version}"
90
+ if config[:all] && unknown.any?
91
+ ui.warn("It's unknown if the following run_list items are Chef #{target_version} compatible: #{unknown.sort.join(', ')}")
92
+ end
93
+
94
+ ui.confirm "Are you sure you want to update #{nodes.size} nodes to chef #{target_version}"
84
95
  update_ssh(nodes, target_version).run
85
96
  end
86
97
 
@@ -27,24 +27,23 @@ class Chef
27
27
 
28
28
  def run
29
29
  list = node_list
30
- old_nodes = list.inject([]) do |memo, (version, nodes)|
31
- version == target_version ? memo : memo += nodes
32
- end
33
- compatible = run_list_items(list[target_version])
34
- incompatible = run_list_items(old_nodes)
30
+ compatible = run_list_items(only(list, target_version))
31
+ unknown = run_list_items(except(list, target_version)) - compatible
35
32
 
36
33
  if compatible.any?
37
- ui.msg "\nCompatbile Chef #{target_version} run_list items:"
34
+ ui.msg "run_list items already running on Chef #{target_version}:"
38
35
  compatible.sort.each do |item|
39
36
  ui.msg " #{item}"
40
37
  end
38
+ ui.msg ''
41
39
  end
42
40
 
43
- if incompatible.any?
44
- ui.msg "\Incompatible / not tested run_list items:"
45
- incompatible.sort.each do |item|
41
+ if unknown.any?
42
+ ui.msg "run_list items not running on Chef #{target_version}:"
43
+ unknown.sort.each do |item|
46
44
  ui.msg " #{item}"
47
45
  end
46
+ ui.msg ''
48
47
  end
49
48
  end
50
49
 
@@ -28,7 +28,7 @@ class Chef
28
28
  def run
29
29
  list = node_list
30
30
 
31
- ui.msg "\nCurrently installed chef-client versions:"
31
+ ui.msg "Currently installed chef-client versions:"
32
32
  list.sort.each do |version, nodes|
33
33
  ui.msg " Chef #{version}: #{nodes.size} nodes"
34
34
  end
@@ -18,7 +18,7 @@
18
18
 
19
19
  module Knife
20
20
  module Update
21
- VERSION = '0.0.1'
21
+ VERSION = '0.0.2'
22
22
  MAJOR, MINOR, TINY = VERSION.split('.')
23
23
  end
24
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-update
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.10.24
21
+ version: 10.24.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.10.24
29
+ version: 10.24.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rspec
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -78,7 +78,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
78
  version: '0'
79
79
  segments:
80
80
  - 0
81
- hash: -334156609659399358
81
+ hash: -3366548039429717818
82
82
  required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  version: '0'
88
88
  segments:
89
89
  - 0
90
- hash: -334156609659399358
90
+ hash: -3366548039429717818
91
91
  requirements: []
92
92
  rubyforge_project:
93
93
  rubygems_version: 1.8.25