knife-flip 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +7 -1
- data/knife-flip.gemspec +6 -5
- data/lib/chef/knife/{flip.rb → nodeflip.rb} +0 -0
- data/lib/chef/knife/roleflip.rb +100 -0
- data/lib/knife-flip.rb +1 -1
- metadata +7 -6
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# knife-flip
|
2
2
|
|
3
|
-
A knife plugin to move a node
|
3
|
+
A knife plugin to move a node, or all nodes in a role, to a specific environment
|
4
4
|
|
5
5
|
## What it does
|
6
6
|
|
@@ -10,3 +10,9 @@ knife node flip mynode.foo.com myenv
|
|
10
10
|
|
11
11
|
will move the node mynode.foo.com into the environment myenv
|
12
12
|
|
13
|
+
|
14
|
+
````
|
15
|
+
knife role flip MyRole myenv
|
16
|
+
````
|
17
|
+
|
18
|
+
will move all nodes containing the role MyRole in their runlists into the environment myenv
|
data/knife-flip.gemspec
CHANGED
@@ -13,14 +13,14 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'knife-flip'
|
16
|
-
s.version = '0.1.
|
17
|
-
s.date = '2012-01
|
16
|
+
s.version = '0.1.2'
|
17
|
+
s.date = '2012-02-01'
|
18
18
|
s.rubyforge_project = 'knife-flip'
|
19
19
|
|
20
20
|
## Make sure your summary is short. The description may be as long
|
21
21
|
## as you like.
|
22
|
-
s.summary = "A knife plugin to move a node
|
23
|
-
s.description = "A knife plugin to move a node
|
22
|
+
s.summary = "A knife plugin to move a node, or all nodes in a role, to a specific environment"
|
23
|
+
s.description = "A knife plugin to move a node, or all nodes in a role, to a specific environment"
|
24
24
|
|
25
25
|
## List the primary authors. If there are a bunch of authors, it's probably
|
26
26
|
## better to set the email to an email list or something. If you don't have
|
@@ -50,7 +50,8 @@ Gem::Specification.new do |s|
|
|
50
50
|
README.md
|
51
51
|
Rakefile
|
52
52
|
knife-flip.gemspec
|
53
|
-
lib/chef/knife/
|
53
|
+
lib/chef/knife/nodeflip.rb
|
54
|
+
lib/chef/knife/roleflip.rb
|
54
55
|
lib/knife-flip.rb
|
55
56
|
]
|
56
57
|
# = MANIFEST =
|
File without changes
|
@@ -0,0 +1,100 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Jon Cowie (<jonlives@gmail.com>)
|
3
|
+
# Copyright:: Copyright (c) 2011 Jon Cowie
|
4
|
+
# License:: GPL
|
5
|
+
|
6
|
+
|
7
|
+
require 'chef/knife'
|
8
|
+
|
9
|
+
module KnifeFlip
|
10
|
+
class RoleFlip < Chef::Knife
|
11
|
+
|
12
|
+
deps do
|
13
|
+
require 'chef/search/query'
|
14
|
+
require 'chef/knife/search'
|
15
|
+
end
|
16
|
+
|
17
|
+
banner "knife role flip ROLENAME ENVIRONMENT"
|
18
|
+
|
19
|
+
def run
|
20
|
+
unless @role = name_args[0]
|
21
|
+
ui.error "You need to specify a role to search against"
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
|
25
|
+
unless @new_env = name_args[1]
|
26
|
+
ui.error "You need to specify an environment to move nodes to"
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
|
30
|
+
puts "Checking for a role called #{@role} to flip nodes from..."
|
31
|
+
|
32
|
+
searcher = Chef::Search::Query.new
|
33
|
+
result = searcher.search(:role, "name:#{@role}")
|
34
|
+
|
35
|
+
knife_search = Chef::Knife::Search.new
|
36
|
+
env = result.first.first
|
37
|
+
if env.nil?
|
38
|
+
puts "Could not find an role named #{@role}. Can't update nodes which run a non-existant role!"
|
39
|
+
exit 1
|
40
|
+
else
|
41
|
+
puts "Found!\n"
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
puts "Checking for an environment called #{@new_env} to update to..."
|
46
|
+
|
47
|
+
searcher = Chef::Search::Query.new
|
48
|
+
result = searcher.search(:environment, "name:#{@new_env}")
|
49
|
+
|
50
|
+
knife_search = Chef::Knife::Search.new
|
51
|
+
env = result.first.first
|
52
|
+
if env.nil?
|
53
|
+
puts "Could not find an environment named #{@new_env}. Please create it before trying to put nodes in it!"
|
54
|
+
exit 1
|
55
|
+
else
|
56
|
+
puts "Found!\n"
|
57
|
+
end
|
58
|
+
|
59
|
+
#puts "Setting environment to #{@environment}"
|
60
|
+
#node.chef_environment(@environment)
|
61
|
+
#node.save
|
62
|
+
|
63
|
+
q_nodes = Chef::Search::Query.new
|
64
|
+
node_query = "role:#{@role}"
|
65
|
+
query_nodes = URI.escape(node_query,
|
66
|
+
Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
67
|
+
|
68
|
+
result_items = []
|
69
|
+
result_count = 0
|
70
|
+
|
71
|
+
#ui.msg("\nFinding all nodes in environment #{@old_env} and moving them to environment #{@new_env}...\n")
|
72
|
+
|
73
|
+
begin
|
74
|
+
q_nodes.search('node', query_nodes) do |node_item|
|
75
|
+
|
76
|
+
node_item.chef_environment(@new_env)
|
77
|
+
node_item.save
|
78
|
+
formatted_item_node = format_for_display(node_item)
|
79
|
+
if formatted_item_node.respond_to?(:has_key?) && !formatted_item_node.has_key?('id')
|
80
|
+
formatted_item_node['id'] = node_item.has_key?('id') ? node_item['id'] : node_item.name
|
81
|
+
end
|
82
|
+
ui.msg("Moving #{formatted_item_node.name} to environment #{@new_env}...")
|
83
|
+
result_items << formatted_item_node
|
84
|
+
result_count += 1
|
85
|
+
end
|
86
|
+
rescue Net::HTTPServerException => e
|
87
|
+
msg = Chef::JSONCompat.from_json(e.response.body)["error"].first
|
88
|
+
ui.error("knife role flip failed: #{msg}")
|
89
|
+
exit 1
|
90
|
+
end
|
91
|
+
|
92
|
+
if ui.interchange?
|
93
|
+
output({:results => result_count, :rows => result_items})
|
94
|
+
else
|
95
|
+
ui.msg "#{result_count} Nodes updated"
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/lib/knife-flip.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jon Cowie
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-01
|
17
|
+
date: 2012-02-01 00:00:00 +00:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: 0.10.4
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
|
-
description: A knife plugin to move a node
|
35
|
+
description: A knife plugin to move a node, or all nodes in a role, to a specific environment
|
36
36
|
email: jonlives@gmail.com
|
37
37
|
executables: []
|
38
38
|
|
@@ -44,7 +44,8 @@ files:
|
|
44
44
|
- README.md
|
45
45
|
- Rakefile
|
46
46
|
- knife-flip.gemspec
|
47
|
-
- lib/chef/knife/
|
47
|
+
- lib/chef/knife/nodeflip.rb
|
48
|
+
- lib/chef/knife/roleflip.rb
|
48
49
|
- lib/knife-flip.rb
|
49
50
|
has_rdoc: true
|
50
51
|
homepage: https://github.com/jonlives/knife-flip
|
@@ -77,6 +78,6 @@ rubyforge_project: knife-flip
|
|
77
78
|
rubygems_version: 1.3.7
|
78
79
|
signing_key:
|
79
80
|
specification_version: 2
|
80
|
-
summary: A knife plugin to move a node
|
81
|
+
summary: A knife plugin to move a node, or all nodes in a role, to a specific environment
|
81
82
|
test_files: []
|
82
83
|
|