knife-update 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -25,22 +25,24 @@ Currently installed chef-client versions:
25
25
  Chef 10.24.0: 1000 nodes
26
26
  ```
27
27
 
28
- ### knife update run_list
28
+ ### knife update recipes
29
29
 
30
- Displays lists of run_list items both used and not yet used in the target
30
+ Displays recipes both used and not yet used on nodes with the target
31
31
  chef-client version.
32
32
 
33
33
  ```bash
34
- $ knife update run_list
34
+ $ knife update recipes
35
35
  Search nodes '*:*'
36
36
 
37
- Compatbile Chef 10.24.0 run_list items:
38
- role[base]
39
- role[web-server]
37
+ recipes already used on Chef 10.24.0:
38
+ apt::internal
39
+ barn::barn-ctrl
40
+ chef::bootstrap_client
41
+ ...
40
42
 
41
- Incompatible / not tested run_list items:
42
- role[loadbalancer]
43
- role[database-server]
43
+ recipes not used on Chef 10.24.0:
44
+ hadoop::client
45
+ hadoop::datanode
44
46
  ```
45
47
 
46
48
  ### knife update run
@@ -67,11 +67,11 @@ class Chef
67
67
  list
68
68
  end
69
69
 
70
- # List of all compatible run_list items
71
- def run_list_items(nodes)
70
+ # List of all compatible recipes
71
+ def recipes(nodes)
72
72
  nodes.inject([]) do |memo, node|
73
- node.run_list.each do |item|
74
- memo << item.to_s unless memo.include?(item.to_s)
73
+ node.recipes.each do |recipe|
74
+ memo << recipe.to_s unless memo.include?(recipe.to_s)
75
75
  end
76
76
 
77
77
  memo
@@ -20,18 +20,18 @@ require 'chef/knife'
20
20
 
21
21
  class Chef
22
22
  class Knife
23
- class UpdateRunList < Knife
24
- banner 'knife update run_list (options)'
23
+ class UpdateRecipes < Knife
24
+ banner 'knife update recipes (options)'
25
25
 
26
26
  include Chef::Knife::Update
27
27
 
28
28
  def run
29
29
  list = node_list
30
- compatible = run_list_items(only(list, target_version))
31
- unknown = run_list_items(except(list, target_version)) - compatible
30
+ compatible = recipes(only(list, target_version))
31
+ unknown = recipes(except(list, target_version)) - compatible
32
32
 
33
33
  if compatible.any?
34
- ui.msg "run_list items already running on Chef #{target_version}:"
34
+ ui.msg "recipes already used on Chef #{target_version}:"
35
35
  compatible.sort.each do |item|
36
36
  ui.msg " #{item}"
37
37
  end
@@ -39,7 +39,7 @@ class Chef
39
39
  end
40
40
 
41
41
  if unknown.any?
42
- ui.msg "run_list items not running on Chef #{target_version}:"
42
+ ui.msg "recipes not used on Chef #{target_version}:"
43
43
  unknown.sort.each do |item|
44
44
  ui.msg " #{item}"
45
45
  end
@@ -62,23 +62,29 @@ 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",
65
+ option :force,
66
+ :short => "-f",
67
+ :long => "--force",
68
68
  :description => "Update all nodes found by the given search-query",
69
69
  :boolean => true
70
70
 
71
+ option :dry_run,
72
+ :short => "-D",
73
+ :long => "--dry-run",
74
+ :description => "Only collect updateable nodes and display them",
75
+ :boolean => true
76
+
71
77
  include Chef::Knife::Update
72
78
 
73
79
  def run
74
80
  list = node_list
75
- compatible = run_list_items(only(list, target_version))
76
- unknown = run_list_items(except(list, target_version)) - compatible
81
+ compatible = recipes(only(list, target_version))
82
+ unknown = recipes(except(list, target_version)) - compatible
77
83
 
78
84
  nodes = list.inject([]) do |memo, (version, nodes)|
79
85
  if version != target_version
80
86
  nodes.each do |node|
81
- if config[:all] || node.run_list.all? { |item| items.include?(item.to_s) }
87
+ if config[:force] || node.recipes.all? { |recipe| compatible.include?(recipe) }
82
88
  memo << node
83
89
  end
84
90
  end
@@ -87,12 +93,23 @@ class Chef
87
93
  memo
88
94
  end
89
95
 
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(', ')}")
96
+ if config[:force] && unknown.any?
97
+ ui.warn "It's unknown if the following recipes are Chef #{target_version} compatible: #{unknown.sort.join(', ')}"
92
98
  end
93
99
 
94
- ui.confirm "Are you sure you want to update #{nodes.size} nodes to chef #{target_version}"
95
- update_ssh(nodes, target_version).run
100
+ if nodes.size > 0
101
+ if !config[:dry_run]
102
+ ui.confirm "Are you sure you want to update #{nodes.size} nodes to chef #{target_version}"
103
+ update_ssh(nodes, target_version).run
104
+ else
105
+ ui.msg "Dry run. The following #{nodes.size} nodes would get updated:"
106
+ nodes.each { |node| ui.msg " #{node.fqdn}" }
107
+ end
108
+ elsif list.size > 0
109
+ ui.msg "None of the nodes can be updated. Try option --force"
110
+ else
111
+ ui.msg "No nodes found."
112
+ end
96
113
  end
97
114
 
98
115
  # Update given nodes to specified version
@@ -103,13 +120,13 @@ class Chef
103
120
  ssh.ui = ui
104
121
  ssh.name_args = [ fqdns, ssh_command(version) ]
105
122
  ssh.config[:manual] = true
123
+ ssh.config[:on_error] = :skip
106
124
  ssh.config[:ssh_user] = Chef::Config[:knife][:ssh_user] || config[:ssh_user]
107
125
  ssh.config[:ssh_password] = config[:ssh_password]
108
126
  ssh.config[:ssh_port] = Chef::Config[:knife][:ssh_port] || config[:ssh_port]
109
127
  ssh.config[:ssh_gateway] = Chef::Config[:knife][:ssh_gateway] || config[:ssh_gateway]
110
128
  ssh.config[:identity_file] = Chef::Config[:knife][:identity_file] || config[:identity_file]
111
129
  ssh.config[:host_key_verify] = Chef::Config[:knife][:host_key_verify] || config[:host_key_verify]
112
- ssh.config[:on_error] = :raise
113
130
  ssh
114
131
  end
115
132
 
@@ -18,7 +18,7 @@
18
18
 
19
19
  module Knife
20
20
  module Update
21
- VERSION = '0.0.2'
21
+ VERSION = '0.0.4'
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.2
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-18 00:00:00.000000000 Z
12
+ date: 2013-05-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef
@@ -58,8 +58,8 @@ files:
58
58
  - Rakefile
59
59
  - knife-update.gemspec
60
60
  - lib/chef/knife/update.rb
61
+ - lib/chef/knife/update_recipes.rb
61
62
  - lib/chef/knife/update_run.rb
62
- - lib/chef/knife/update_run_list.rb
63
63
  - lib/chef/knife/update_status.rb
64
64
  - lib/knife-update/version.rb
65
65
  - spec/spec_helper.rb
@@ -78,7 +78,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
78
  version: '0'
79
79
  segments:
80
80
  - 0
81
- hash: -3366548039429717818
81
+ hash: 4121929708377413220
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: -3366548039429717818
90
+ hash: 4121929708377413220
91
91
  requirements: []
92
92
  rubyforge_project:
93
93
  rubygems_version: 1.8.25