knife-tar 1.3.1 → 2.0.0
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 +26 -42
- data/Rakefile +36 -164
- data/lib/chef/knife/cookbook_tar_upload.rb +1 -0
- data/lib/chef/knife/tar_download_all.rb +0 -1
- data/lib/chef/knife/tar_upload_all.rb +0 -6
- data/lib/chef/knife/user_tar_download.rb +3 -3
- data/lib/chef/knife/user_tar_upload.rb +13 -9
- metadata +76 -49
- checksums.yaml +0 -7
- data/lib/chef/knife/client_tar_download.rb +0 -40
- data/lib/chef/knife/client_tar_upload.rb +0 -49
data/README.md
CHANGED
@@ -1,12 +1,31 @@
|
|
1
1
|
knife-tar
|
2
2
|
=========
|
3
3
|
|
4
|
-
Description
|
5
|
-
-----------
|
6
|
-
|
7
4
|
A knife plugin facilitating uploading chef components from a tar.gz file/url to your
|
8
5
|
chef server as well as downloading components from chef-server to tar.gz format.
|
9
6
|
|
7
|
+
View the [Change Log](CHANGELOG.md) to see what has changed.
|
8
|
+
|
9
|
+
Installation
|
10
|
+
------------
|
11
|
+
|
12
|
+
Install the chef gem prior to installing knife-tar.
|
13
|
+
|
14
|
+
gem install knife-tar
|
15
|
+
|
16
|
+
Requirements
|
17
|
+
------------
|
18
|
+
|
19
|
+
* Chef >= 11
|
20
|
+
* `tar` is installed and on your `$PATH`
|
21
|
+
|
22
|
+
Branches
|
23
|
+
--------
|
24
|
+
|
25
|
+
* 1.X - Supports Chef 10
|
26
|
+
* 2.X - Supports Chef 11
|
27
|
+
* Lost support for API Clients
|
28
|
+
|
10
29
|
Why?
|
11
30
|
----
|
12
31
|
|
@@ -28,19 +47,6 @@ realized we could support all of the chef components and modeled the format afte
|
|
28
47
|
[chef-repo](https://github.com/opscode/chef-repo). From there we included the download
|
29
48
|
functionality and supported multiple versions of the same cookbook.
|
30
49
|
|
31
|
-
Installation
|
32
|
-
------------
|
33
|
-
|
34
|
-
Install the chef gem prior to installing knife-tar.
|
35
|
-
|
36
|
-
gem install knife-tar
|
37
|
-
|
38
|
-
Requirements
|
39
|
-
------------
|
40
|
-
|
41
|
-
* Chef >= 0.10.10 (Does not work with Chef 11)
|
42
|
-
* `tar` is installed and on your `$PATH`
|
43
|
-
|
44
50
|
Conventions
|
45
51
|
-----------
|
46
52
|
|
@@ -63,9 +69,7 @@ We assume that the tar file will look like,
|
|
63
69
|
|- roles
|
64
70
|
| |- \[roleName\].\[json|js|rb\]
|
65
71
|
|- web_users
|
66
|
-
| |- \[webUserName\].\[json|js|rb\]
|
67
|
-
|- api_clients
|
68
|
-
| | - \[clientName\].\[json|js|rb\]
|
72
|
+
| |- \[webUserName\].\[json|js|rb\]
|
69
73
|
|- nodes
|
70
74
|
| |- \[nodeName\].\[json|js|rb\]
|
71
75
|
|
@@ -83,9 +87,7 @@ OR
|
|
83
87
|
| |- roles
|
84
88
|
| | |- \[roleName\].\[json|js|rb\]
|
85
89
|
| |- web_users
|
86
|
-
| | |- \[webUserName\].\[json|js|rb\]
|
87
|
-
| |- api_clients
|
88
|
-
| | | - \[clientName\].\[json|js|rb\]
|
90
|
+
| | |- \[webUserName\].\[json|js|rb\]
|
89
91
|
| |- nodes
|
90
92
|
| | |- \[nodeName\].\[json|js|rb\]
|
91
93
|
|
@@ -175,24 +177,13 @@ following command,
|
|
175
177
|
|
176
178
|
Command: 'knife node tar upload tarPath (options)'
|
177
179
|
|
178
|
-
####
|
180
|
+
#### Users
|
179
181
|
|
180
182
|
If you want to upload only your users from your tar file you can use the
|
181
183
|
following command,
|
182
184
|
|
183
185
|
Command: 'knife user tar upload tarPath (options)'
|
184
186
|
|
185
|
-
|
186
|
-
#### API Clients
|
187
|
-
|
188
|
-
**NOTE**: This command requires that you either be running on the chef-server or
|
189
|
-
have configured 'couchdb_url' in your knife.rb to work properly.
|
190
|
-
|
191
|
-
If you want to upload only your clients from your tar file you can use the
|
192
|
-
following command,
|
193
|
-
|
194
|
-
Command: 'knife client tar upload tarPath (options)'
|
195
|
-
|
196
187
|
### Downloading
|
197
188
|
|
198
189
|
#### Everything
|
@@ -237,14 +228,7 @@ can use the following command,
|
|
237
228
|
|
238
229
|
Command: 'knife role tar download tarPath (options)'
|
239
230
|
|
240
|
-
####
|
241
|
-
|
242
|
-
If you want to download all your api clients from chef-server to a tar file you
|
243
|
-
can use the following command,
|
244
|
-
|
245
|
-
Command: 'knife client tar download tarPath (options)'
|
246
|
-
|
247
|
-
#### Web UI Users
|
231
|
+
#### Users
|
248
232
|
|
249
233
|
If you want to download all your web ui users from chef-server to a tar file you
|
250
234
|
can use the following command,
|
data/Rakefile
CHANGED
@@ -1,189 +1,61 @@
|
|
1
1
|
# coding: UTF-8
|
2
|
-
require 'octokit'
|
3
|
-
|
4
|
-
REPO = "cerner/knife-tar"
|
5
2
|
|
6
3
|
task :default => [:build]
|
7
4
|
|
8
5
|
task :build do
|
9
|
-
|
6
|
+
puts "Building the gem"
|
7
|
+
runCommand "gem build knife-tar.gemspec"
|
10
8
|
end
|
11
9
|
|
12
|
-
task :
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
closed_milestones.each do |milestone|
|
19
|
-
version = Gem::Version.new(milestone.title)
|
20
|
-
version_to_milestone.store version, milestone
|
21
|
-
versions.push version
|
22
|
-
end
|
23
|
-
|
24
|
-
versions = versions.sort.reverse
|
25
|
-
|
26
|
-
change_log = File.open('CHANGELOG.md', 'w')
|
27
|
-
|
10
|
+
task :release => [:build] do
|
11
|
+
deployGem
|
12
|
+
release
|
13
|
+
end
|
14
|
+
|
15
|
+
def deployGem
|
28
16
|
begin
|
29
|
-
|
30
|
-
|
31
|
-
change_log.write "\n"
|
32
|
-
|
33
|
-
versions.each do |version|
|
34
|
-
milestone = version_to_milestone[version]
|
35
|
-
change_log.write generate_milestone_markdown(milestone)
|
36
|
-
change_log.write "\n"
|
37
|
-
end
|
17
|
+
puts "Pushing the gem to rubygems.org"
|
18
|
+
runCommand "gem push knife-tar*.gem"
|
38
19
|
ensure
|
39
|
-
|
20
|
+
system "rm -f knife-tar*.gem"
|
40
21
|
end
|
41
22
|
end
|
42
23
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
version = IO.read(File.join(File.dirname(__FILE__), 'VERSION')).chomp
|
47
|
-
|
48
|
-
# Update change log
|
49
|
-
puts "Updating change log ..."
|
50
|
-
update_change_log version
|
51
|
-
puts "Change log updated!"
|
52
|
-
|
53
|
-
|
54
|
-
# Publish the gem
|
55
|
-
deploy
|
24
|
+
def release
|
25
|
+
|
26
|
+
rawVersion = `cat VERSION`.chomp
|
56
27
|
|
57
|
-
#
|
58
|
-
puts "Tagging the
|
59
|
-
|
60
|
-
|
61
|
-
puts "Release tagged!"
|
28
|
+
#Tag the release
|
29
|
+
puts "Tagging the release"
|
30
|
+
runCommand "git tag -a #{rawVersion} -m 'Released #{rawVersion}'"
|
31
|
+
runCommand "git push origin #{rawVersion}"
|
62
32
|
|
63
|
-
#
|
64
|
-
versions =
|
33
|
+
# Update bump VERSION file
|
34
|
+
versions = rawVersion.split "."
|
65
35
|
versions[1] = versions[1].to_i + 1
|
36
|
+
newVersion = versions.join "."
|
66
37
|
|
67
|
-
|
68
|
-
if versions.size == 3
|
69
|
-
versions[2] = 0
|
70
|
-
end
|
38
|
+
puts "Changing version from #{rawVersion} to #{newVersion}"
|
71
39
|
|
72
|
-
|
40
|
+
runCommand "echo '#{newVersion}' > VERSION"
|
73
41
|
|
74
|
-
|
75
|
-
|
76
|
-
|
42
|
+
#Commit the updated VERSION file
|
43
|
+
puts "Commiting the new VERSION file"
|
44
|
+
runCommand "git add VERSION"
|
45
|
+
runCommand "git commit -m 'Released #{rawVersion} and bumped version to #{newVersion}'"
|
46
|
+
runCommand "git push origin master"
|
77
47
|
|
78
|
-
# Commit the updated VERSION file
|
79
|
-
puts "Commiting the new version ..."
|
80
|
-
run_command "git add VERSION"
|
81
|
-
run_command "git commit -m 'Released #{version} and bumped version to #{new_version}'"
|
82
|
-
run_command "git push origin HEAD"
|
83
|
-
puts "Version commited!"
|
84
|
-
end
|
85
|
-
|
86
|
-
def build_gem
|
87
|
-
puts "Building the gem ..."
|
88
|
-
run_command "gem build knife-tar.gemspec"
|
89
|
-
puts "Gem built!"
|
90
|
-
end
|
91
|
-
|
92
|
-
def deploy
|
93
|
-
begin
|
94
|
-
build_gem
|
95
|
-
|
96
|
-
puts "Publishing the gem ..."
|
97
|
-
run_command "gem push knife-tar*.gem"
|
98
|
-
puts "Gem published!"
|
99
|
-
ensure
|
100
|
-
system "rm -f knife-tar*.gem"
|
101
|
-
end
|
102
48
|
end
|
103
49
|
|
104
|
-
def
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
begin
|
110
|
-
|
111
|
-
# Keep change log title
|
112
|
-
change_log.write change_log_lines.shift
|
113
|
-
change_log.write "\n"
|
114
|
-
change_log.write change_log_lines.shift
|
115
|
-
change_log.write "\n"
|
116
|
-
change_log.write "\n"
|
50
|
+
def runCommand command
|
51
|
+
output = system command
|
52
|
+
unless output
|
53
|
+
# Removes changes to tracked files
|
54
|
+
system "git reset --hard"
|
117
55
|
|
118
|
-
#
|
119
|
-
|
56
|
+
# Removes any new un-tracked files
|
57
|
+
system "git clean -f -d"
|
120
58
|
|
121
|
-
|
122
|
-
change_log_lines.each do |line|
|
123
|
-
change_log.write line
|
124
|
-
change_log.write "\n"
|
125
|
-
end
|
126
|
-
|
127
|
-
ensure
|
128
|
-
change_log.close
|
129
|
-
end
|
130
|
-
|
131
|
-
run_command "git add CHANGELOG.md"
|
132
|
-
run_command "git commit -m 'Added #{version} to change log'"
|
133
|
-
run_command "git push origin HEAD"
|
134
|
-
end
|
135
|
-
|
136
|
-
def generate_milestone_markdown milestone
|
137
|
-
strings = Array.new
|
138
|
-
|
139
|
-
title = "[#{milestone.title}](https://github.com/#{REPO}/issues?milestone=#{milestone.number}&state=closed)"
|
140
|
-
|
141
|
-
strings.push "#{title}"
|
142
|
-
strings.push "-" * title.length
|
143
|
-
strings.push ""
|
144
|
-
|
145
|
-
issues = Octokit.issues REPO, {:milestone => milestone.number, :state => "closed"}
|
146
|
-
|
147
|
-
issues.each do |issue|
|
148
|
-
strings.push " * [#{issue_type issue}] [Issue-#{issue.number}](https://github.com/#{REPO}/issues/#{issue.number}) : #{issue.title}"
|
149
|
-
end
|
150
|
-
|
151
|
-
strings.push ""
|
152
|
-
|
153
|
-
strings.join "\n"
|
154
|
-
end
|
155
|
-
|
156
|
-
def milestone version
|
157
|
-
closedMilestones = Octokit.milestones REPO, {:state => "closed"}
|
158
|
-
|
159
|
-
closedMilestones.each do |milestone|
|
160
|
-
if milestone["title"] == version
|
161
|
-
return milestone
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
openMilestones = Octokit.milestones REPO
|
166
|
-
|
167
|
-
openMilestones.each do |milestone|
|
168
|
-
if milestone["title"] == version
|
169
|
-
return milestone
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
raise "Unable to find milestone with title [#{version}]"
|
174
|
-
end
|
175
|
-
|
176
|
-
def issue_type issue
|
177
|
-
labels = Array.new
|
178
|
-
issue.labels.each do |label|
|
179
|
-
labels.push label.name.capitalize
|
180
|
-
end
|
181
|
-
labels.join "/"
|
182
|
-
end
|
183
|
-
|
184
|
-
def run_command command
|
185
|
-
output = `#{command}`
|
186
|
-
unless $?.success?
|
187
|
-
raise "Command : [#{command}] failed.\nOutput : \n#{output}"
|
59
|
+
raise "Command : #{command} failed"
|
188
60
|
end
|
189
61
|
end
|
@@ -19,7 +19,6 @@ class Chef
|
|
19
19
|
|
20
20
|
tar_file = Chef::TarFile.new(@name_args.first, true)
|
21
21
|
|
22
|
-
ClientTarDownload.download_clients tar_file
|
23
22
|
CookbookTarDownload.download_cookbooks tar_file
|
24
23
|
DataBagTarDownload.download_data_bags tar_file
|
25
24
|
EnvironmentTarDownload.download_environments tar_file
|
@@ -21,12 +21,6 @@ class Chef
|
|
21
21
|
|
22
22
|
# Attempt to upload all the components in the tar file
|
23
23
|
# If our tar file does not contain a component ignore the error and skip it
|
24
|
-
begin
|
25
|
-
ClientTarUpload.upload_clients tar_file
|
26
|
-
rescue TarFile::MissingChefComponentError => e
|
27
|
-
ui.info("No Client files to upload")
|
28
|
-
end
|
29
|
-
|
30
24
|
begin
|
31
25
|
CookbookTarUpload.upload_cookbooks tar_file
|
32
26
|
rescue TarFile::MissingChefComponentError => e
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'chef/knife'
|
2
2
|
require 'chef/knife/core/object_loader'
|
3
3
|
require 'chef/json_compat'
|
4
|
-
require 'chef/
|
4
|
+
require 'chef/user'
|
5
5
|
|
6
6
|
class Chef
|
7
7
|
class Knife
|
@@ -26,9 +26,9 @@ class Chef
|
|
26
26
|
|
27
27
|
def self.download_users(tar_file)
|
28
28
|
dir = tar_file.web_users_path
|
29
|
-
Chef::
|
29
|
+
Chef::User.list.each do |component_name, url|
|
30
30
|
Chef::Log.info("Backing up user #{component_name}")
|
31
|
-
component_obj = Chef::
|
31
|
+
component_obj = Chef::User.load(component_name)
|
32
32
|
File.open(File.join(dir, "#{component_name}.json"), "w") do |component_file|
|
33
33
|
component_file.print(component_obj.to_json)
|
34
34
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'chef/knife'
|
2
2
|
require 'chef/knife/core/object_loader'
|
3
3
|
require 'chef/json_compat'
|
4
|
-
require 'chef/
|
4
|
+
require 'chef/user'
|
5
|
+
require 'yajl'
|
5
6
|
|
6
7
|
class Chef
|
7
8
|
class Knife
|
@@ -24,20 +25,23 @@ class Chef
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def self.upload_users(tar_file)
|
27
|
-
current_users = Chef::
|
28
|
-
users_loader = Chef::Knife::Core::ObjectLoader.new(Chef::
|
28
|
+
current_users = Chef::User.list.keys
|
29
|
+
users_loader = Chef::Knife::Core::ObjectLoader.new(Chef::User, ui)
|
29
30
|
|
30
31
|
tar_file.web_users.each do |web_user_path|
|
31
32
|
|
32
|
-
|
33
|
+
unless users_loader.find_file("users", web_user_path).nil?
|
34
|
+
user_hash = Yajl::Parser.parse(IO.read(web_user_path))
|
35
|
+
end
|
36
|
+
user = Chef::User.from_hash(user_hash)
|
33
37
|
|
34
|
-
#
|
38
|
+
# Update existing users, otherwise save the new user
|
35
39
|
if current_users.include? user.name
|
36
|
-
|
37
|
-
|
40
|
+
user.update
|
41
|
+
else
|
42
|
+
user.save
|
38
43
|
end
|
39
|
-
|
40
|
-
user.save
|
44
|
+
|
41
45
|
ui.info("Updated User : #{user.name}")
|
42
46
|
end
|
43
47
|
end
|
metadata
CHANGED
@@ -1,53 +1,74 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-tar
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 2
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 2.0.0
|
5
10
|
platform: ruby
|
6
|
-
authors:
|
11
|
+
authors:
|
7
12
|
- Bryan Baugher
|
8
13
|
- Aaron Blythe
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
date: 2014-01-16 00:00:00 -06:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
15
22
|
name: chef
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 11
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
version: 11.0.0
|
21
33
|
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: yajl-ruby
|
22
37
|
prerelease: false
|
23
|
-
|
24
|
-
requirements:
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
25
40
|
- - ~>
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
|
28
|
-
-
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 1
|
45
|
+
version: "1.1"
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
29
49
|
name: rake
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - ~>
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: 0.9.2.2
|
35
|
-
type: :development
|
36
50
|
prerelease: false
|
37
|
-
|
38
|
-
requirements:
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
39
53
|
- - ~>
|
40
|
-
- !ruby/object:Gem::Version
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
- 9
|
58
|
+
- 2
|
59
|
+
- 2
|
41
60
|
version: 0.9.2.2
|
42
|
-
|
43
|
-
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
description: This is a knife plugin for Chef which can install and upload chef components from a tar file or url
|
44
64
|
email: Bryan.Baugher@Cerner.com
|
45
65
|
executables: []
|
66
|
+
|
46
67
|
extensions: []
|
68
|
+
|
47
69
|
extra_rdoc_files: []
|
48
|
-
|
49
|
-
|
50
|
-
- lib/chef/knife/client_tar_upload.rb
|
70
|
+
|
71
|
+
files:
|
51
72
|
- lib/chef/knife/cookbook_tar_download.rb
|
52
73
|
- lib/chef/knife/cookbook_tar_upload.rb
|
53
74
|
- lib/chef/knife/data_bag_tar_download.rb
|
@@ -67,29 +88,35 @@ files:
|
|
67
88
|
- Gemfile
|
68
89
|
- Rakefile
|
69
90
|
- README.md
|
91
|
+
has_rdoc: true
|
70
92
|
homepage: http://github.com/Cerner/knife-tar
|
71
|
-
licenses:
|
93
|
+
licenses:
|
72
94
|
- Apache License, Version 2.0
|
73
|
-
metadata: {}
|
74
95
|
post_install_message:
|
75
96
|
rdoc_options: []
|
76
|
-
|
97
|
+
|
98
|
+
require_paths:
|
77
99
|
- lib
|
78
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- -
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: "0"
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
segments:
|
112
|
+
- 0
|
113
|
+
version: "0"
|
88
114
|
requirements: []
|
89
|
-
|
90
|
-
|
115
|
+
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 1.3.6
|
91
118
|
signing_key:
|
92
|
-
specification_version:
|
93
|
-
summary: A Chef knife plugin to install/upload chef components from a tar file or
|
94
|
-
url
|
119
|
+
specification_version: 3
|
120
|
+
summary: A Chef knife plugin to install/upload chef components from a tar file or url
|
95
121
|
test_files: []
|
122
|
+
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 4e8511e64a86e613d01c98e287f7abb5a2284ab7
|
4
|
-
data.tar.gz: 8cfaaf1f41493c2a32d6b41dbc25598ae54b9610
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: e13aa6fc497ba20dbee01b94a03b58fe77c5124fc678c4a4d018b44ba29bee4c434559ba1efde221726ef89ded8ca4348f6bc77f06e1185d3b84eb5abfa98570
|
7
|
-
data.tar.gz: 5d462a08ebb757e0a10afbd1cbd002464f1b1429e0582ebbb6e2750f0e26ab442a02b976c472274434a5de66dd5d8d0af7aaa386ee936bdf714fd89b2d4a65ed
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'chef/knife'
|
2
|
-
require 'chef/knife/core/object_loader'
|
3
|
-
require 'chef/json_compat'
|
4
|
-
require 'chef/api_client'
|
5
|
-
|
6
|
-
class Chef
|
7
|
-
class Knife
|
8
|
-
class ClientTarDownload < Chef::Knife
|
9
|
-
|
10
|
-
banner "knife client tar download tarPath [options]"
|
11
|
-
category "client tar"
|
12
|
-
|
13
|
-
def run
|
14
|
-
#Get Arguments
|
15
|
-
if @name_args.size != 1
|
16
|
-
ui.info("Please specify a tar path")
|
17
|
-
show_usage
|
18
|
-
exit 1
|
19
|
-
end
|
20
|
-
|
21
|
-
tar_file = Chef::TarFile.new(@name_args.first, true)
|
22
|
-
ClientTarDownload.download_clients tar_file
|
23
|
-
tarFile.save
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.download_clients(tar_file)
|
28
|
-
dir = tar_file.api_clients_path
|
29
|
-
Chef::ApiClient.list.each do |component_name, url|
|
30
|
-
Chef::Log.info("Backing up client #{component_name}")
|
31
|
-
component_obj = Chef::ApiClient.load(component_name)
|
32
|
-
File.open(File.join(dir, "#{component_name}.json"), "w") do |component_file|
|
33
|
-
component_file.print(component_obj.to_json)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'chef/knife'
|
2
|
-
require 'chef/knife/core/object_loader'
|
3
|
-
require 'chef/json_compat'
|
4
|
-
|
5
|
-
class Chef
|
6
|
-
class Knife
|
7
|
-
class ClientTarUpload < Chef::Knife
|
8
|
-
|
9
|
-
banner "knife client tar upload tarPath [options]"
|
10
|
-
category "client tar"
|
11
|
-
|
12
|
-
def run
|
13
|
-
#Get Arguments
|
14
|
-
if @name_args.size != 1
|
15
|
-
ui.info("Please specify a tar path")
|
16
|
-
show_usage
|
17
|
-
exit 1
|
18
|
-
end
|
19
|
-
|
20
|
-
tar_file = Chef::TarFile.new(@name_args.first)
|
21
|
-
ClientTarUpload.upload_clients tar_file
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.upload_clients(tar_file)
|
26
|
-
ui.confirm "This command will only work when running on chef-server or by updating the couchdb_url in your knife config to point to your couchdb instance. Are you sure you want to continue"
|
27
|
-
|
28
|
-
client_loader = Chef::Knife::Core::ObjectLoader.new(Chef::ApiClient, ui)
|
29
|
-
current_clients = Chef::ApiClient.list.keys
|
30
|
-
|
31
|
-
tar_file.api_clients.each do |api_client_path|
|
32
|
-
|
33
|
-
client = client_loader.load_from("clients", api_client_path)
|
34
|
-
|
35
|
-
# In order to 'update' a client we have to remove it first, so if the client exists destroy it
|
36
|
-
if current_clients.include? client.name
|
37
|
-
ApiClient.load(client.name).destroy
|
38
|
-
end
|
39
|
-
|
40
|
-
client.cdb_save
|
41
|
-
|
42
|
-
ui.info("Updated Client : #{client.name}")
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|