knife-flip 0.1.7 → 0.1.9
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.
- checksums.yaml +15 -0
- data/knife-flip.gemspec +5 -4
- data/lib/chef/knife/environmentflip.rb +94 -0
- metadata +9 -13
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OWUyMWE2MTljYjk4MzMxN2ZmZGQwNmQzZWI0MWI3MDVjMmM1MjQwYg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YjdjNzdmY2Y0ZDgwOTNiZmJiYTBmNGY1ZWZlNGU1ZjI3NmU0ZWE4ZQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZmUwNWQ5YWVhOTFkZmQ0ZjFjYzg5NmU4Y2M0YTU3MjBlNTFmM2YyMmIwYjU4
|
10
|
+
OWYyNTU4ZjZkZjJmZmVlYmJiNzFiNDU1NTE4M2Y1MGM3NDJiY2UzZmY4MDhh
|
11
|
+
M2JkMmJhNmNmMmY1MjUyMmFjNDFmNTdhMGM3MTM3NWY4ZTAwMjQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZWYwMzJhNTk3NDllOGEwNjUwYjAzYWY5MWU3ZDk0Yzg2YWJhNjRhOTU3Y2Qy
|
14
|
+
N2E5NjFjMTM2YjEzY2E4ZTljZDQ1YTQxNzMzNjVlZWY1ZTVjZGQ2NDdiZTM0
|
15
|
+
OTM0MTNkZjMxOTg4YzI1ZjgwODM5N2Y0ODE5NTcxNjQxYmVkYjI=
|
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 = '
|
16
|
+
s.version = '0.1.9'
|
17
|
+
s.date = '2014-07-02'
|
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, 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"
|
22
|
+
s.summary = "A knife plugin to move a node, or all nodes in a role or environment, to a specific environment"
|
23
|
+
s.description = "A knife plugin to move a node, or all nodes in a role or environment, 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
|
@@ -53,6 +53,7 @@ Gem::Specification.new do |s|
|
|
53
53
|
knife-flip.gemspec
|
54
54
|
lib/chef/knife/nodeflip.rb
|
55
55
|
lib/chef/knife/roleflip.rb
|
56
|
+
lib/chef/knife/environmentflip.rb
|
56
57
|
lib/knife-flip.rb
|
57
58
|
]
|
58
59
|
# = MANIFEST =
|
@@ -0,0 +1,94 @@
|
|
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 EnvironmentFlip < Chef::Knife
|
11
|
+
|
12
|
+
deps do
|
13
|
+
require 'chef/search/query'
|
14
|
+
require 'chef/knife/search'
|
15
|
+
end
|
16
|
+
|
17
|
+
banner "knife environment flip ENV_FROM ENV_TO"
|
18
|
+
|
19
|
+
def run
|
20
|
+
unless @old_env = name_args[0]
|
21
|
+
ui.error "You need to specify an environment 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 environment called #{@old_env} to flip nodes from..."
|
31
|
+
|
32
|
+
searcher = Chef::Search::Query.new
|
33
|
+
result = searcher.search(:environment, "name:#{@old_env}")
|
34
|
+
|
35
|
+
env = result.first.first
|
36
|
+
if env.nil?
|
37
|
+
puts "Could not find an environment named #{@old_env}. Can't update nodes in a non-existant environment!"
|
38
|
+
exit 1
|
39
|
+
else
|
40
|
+
puts "Found!\n"
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
puts "Checking for an environment called #{@new_env} to update to..."
|
45
|
+
|
46
|
+
searcher = Chef::Search::Query.new
|
47
|
+
result = searcher.search(:environment, "name:#{@new_env}")
|
48
|
+
|
49
|
+
env = result.first.first
|
50
|
+
if env.nil?
|
51
|
+
puts "Could not find an environment named #{@new_env}. Please create it before trying to put nodes in it!"
|
52
|
+
exit 1
|
53
|
+
else
|
54
|
+
puts "Found!\n"
|
55
|
+
end
|
56
|
+
|
57
|
+
q_nodes = Chef::Search::Query.new
|
58
|
+
node_query = "chef_environment:#{@old_env}"
|
59
|
+
query_nodes = URI.escape(node_query,
|
60
|
+
Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
61
|
+
|
62
|
+
result_items = []
|
63
|
+
result_count = 0
|
64
|
+
|
65
|
+
#ui.msg("\nFinding all nodes in environment #{@old_env} and moving them to environment #{@new_env}...\n")
|
66
|
+
|
67
|
+
begin
|
68
|
+
q_nodes.search('node', query_nodes) do |node_item|
|
69
|
+
|
70
|
+
node_item.chef_environment(@new_env)
|
71
|
+
node_item.save
|
72
|
+
formatted_item_node = format_for_display(node_item)
|
73
|
+
if formatted_item_node.respond_to?(:has_key?) && !formatted_item_node.has_key?('id')
|
74
|
+
formatted_item_node.normal['id'] = node_item.has_key?('id') ? node_item['id'] : node_item.name
|
75
|
+
end
|
76
|
+
ui.msg("Moving #{formatted_item_node.name} to environment #{@new_env}...")
|
77
|
+
result_items << formatted_item_node
|
78
|
+
result_count += 1
|
79
|
+
end
|
80
|
+
rescue Net::HTTPServerException => e
|
81
|
+
msg = Chef::JSONCompat.from_json(e.response.body)["error"].first
|
82
|
+
ui.error("knife role flip failed: #{msg}")
|
83
|
+
exit 1
|
84
|
+
end
|
85
|
+
|
86
|
+
if ui.interchange?
|
87
|
+
output({:results => result_count, :rows => result_items})
|
88
|
+
else
|
89
|
+
ui.msg "#{result_count} Nodes updated"
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-flip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.9
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jon Cowie
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-07-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: chef
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: colorize
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,13 +34,12 @@ dependencies:
|
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: 0.5.8
|
46
|
-
description: A knife plugin to move a node, or all nodes in a role
|
47
|
-
environment
|
41
|
+
description: A knife plugin to move a node, or all nodes in a role or environment,
|
42
|
+
to a specific environment
|
48
43
|
email: jonlives@gmail.com
|
49
44
|
executables: []
|
50
45
|
extensions: []
|
@@ -54,33 +49,34 @@ files:
|
|
54
49
|
- README.md
|
55
50
|
- Rakefile
|
56
51
|
- knife-flip.gemspec
|
52
|
+
- lib/chef/knife/environmentflip.rb
|
57
53
|
- lib/chef/knife/nodeflip.rb
|
58
54
|
- lib/chef/knife/roleflip.rb
|
59
55
|
- lib/knife-flip.rb
|
60
56
|
homepage: https://github.com/jonlives/knife-flip
|
61
57
|
licenses: []
|
58
|
+
metadata: {}
|
62
59
|
post_install_message:
|
63
60
|
rdoc_options:
|
64
61
|
- --charset=UTF-8
|
65
62
|
require_paths:
|
66
63
|
- lib
|
67
64
|
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
-
none: false
|
69
65
|
requirements:
|
70
66
|
- - ! '>='
|
71
67
|
- !ruby/object:Gem::Version
|
72
68
|
version: '0'
|
73
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
70
|
requirements:
|
76
71
|
- - ! '>='
|
77
72
|
- !ruby/object:Gem::Version
|
78
73
|
version: '0'
|
79
74
|
requirements: []
|
80
75
|
rubyforge_project: knife-flip
|
81
|
-
rubygems_version:
|
76
|
+
rubygems_version: 2.2.1
|
82
77
|
signing_key:
|
83
78
|
specification_version: 2
|
84
|
-
summary: A knife plugin to move a node, or all nodes in a role, to
|
79
|
+
summary: A knife plugin to move a node, or all nodes in a role or environment, to
|
80
|
+
a specific environment
|
85
81
|
test_files: []
|
86
82
|
has_rdoc:
|