knife-chop 0.7.8 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Rakefile +5 -0
- data/VERSION +1 -1
- data/knife-chop.gemspec +2 -2
- data/lib/chef/knife/chop/ui.rb +1 -4
- data/lib/chef/knife/chop_base.rb +17 -5
- data/lib/chef/knife/chop_upload.rb +56 -14
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjFlM2VlMTY3MDAzYTM0MzdkZjEyNzMyYTY0YzZkNzJmZTQ4OWZjMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzJiNmJlYTY1OTA4ZGFjNTViYmExNTA3M2ZjNzJiNjQ3YTRlMDRjNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDZjNWI1NmIyZTU3NGI4M2YwYmEzYjMzM2QwMjU1ZWE2Nzg5YjUzNGVmNDIw
|
10
|
+
Y2Y4NTI0MjMyZDEzY2FiMWEyZmQ1MWJiNmFhYzRhYmQ0NDkwNzJkZmEzYWY3
|
11
|
+
NmY5OTRjNmNjMTFlOWViNDE5OTRhZjIzMWIzNWVmZGFkYmVkMzU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGNiNDViZjA1N2Q2MGUzNTI1MmQwZmY1MWUzZDM4ZWU3MmI4Yjg3OGE5YjM0
|
14
|
+
NzBhOTZmZGFkN2I5NThjYTgyNTNmODIyNzM1ZDdhZjU5YjBhYjliZmI2NTAz
|
15
|
+
ZTc2ZGNiM2YwYzAwMTMxNGFlYWFhYzNiNWZhNzY5NmRkYWRhMGE=
|
data/Rakefile
CHANGED
@@ -40,6 +40,11 @@ Rake::RDocTask.new do |rdoc|
|
|
40
40
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
41
41
|
end
|
42
42
|
|
43
|
+
require 'rake'
|
44
|
+
|
45
|
+
require 'rubygems/tasks'
|
46
|
+
Gem::Tasks.new
|
47
|
+
|
43
48
|
require File.dirname(__FILE__) + '/lib/chef/knife/chop/version'
|
44
49
|
desc "Commit it, push it, build it, tag it and ship it"
|
45
50
|
task :ship => [:clobber_package,:clobber_rdoc,:gem] do
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.0
|
data/knife-chop.gemspec
CHANGED
@@ -5,7 +5,6 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
6
|
s.require_paths = ["lib"]
|
7
7
|
s.authors = ["Christo De Lange"]
|
8
|
-
s.date = "2014-07-01"
|
9
8
|
s.description = "Knife plugin to assist with the upload and sync of Chef server assets like roles, environments and cookbooks allowing for multiple parts to be uploaded at once to multiple environments. Resources can be matched with regular expressions."
|
10
9
|
s.email = "rubygems@dldinternet.com"
|
11
10
|
s.executables = ["chop"]
|
@@ -20,7 +19,6 @@ Gem::Specification.new do |s|
|
|
20
19
|
|
21
20
|
s.homepage = "http://github.com/dldinternet/knife-chop"
|
22
21
|
s.licenses = ["MIT"]
|
23
|
-
s.rubygems_version = "2.2.2"
|
24
22
|
s.summary = "Knife plugin to ease the upload and sync of Chef server assets"
|
25
23
|
|
26
24
|
s.add_dependency %q<awesome_print>, [">= 1.2.0", "~> 1.2"]
|
@@ -32,5 +30,7 @@ Gem::Specification.new do |s|
|
|
32
30
|
s.add_dependency %q<chef>, [">= 11.12.0", "~> 11.12"]
|
33
31
|
s.add_dependency %q<safe_yaml>, [">= 0"]
|
34
32
|
|
33
|
+
s.add_development_dependency 'rubygems-tasks', '~> 0.2'
|
34
|
+
|
35
35
|
end
|
36
36
|
|
data/lib/chef/knife/chop/ui.rb
CHANGED
@@ -64,10 +64,6 @@ class Chef
|
|
64
64
|
error(message)
|
65
65
|
end
|
66
66
|
|
67
|
-
def error(message)
|
68
|
-
msg(message)
|
69
|
-
end
|
70
|
-
|
71
67
|
# Print a warning message
|
72
68
|
def warn(message)
|
73
69
|
msg(message)
|
@@ -90,6 +86,7 @@ class Chef
|
|
90
86
|
end
|
91
87
|
|
92
88
|
def shifted(name)
|
89
|
+
name = 'info' unless ::Logging::LEVELS.has_key?(name)
|
93
90
|
num = ::Logging::LEVELS[name]+1
|
94
91
|
case name
|
95
92
|
when 'todo'
|
data/lib/chef/knife/chop_base.rb
CHANGED
@@ -280,14 +280,14 @@ class Chef
|
|
280
280
|
:short => "-P",
|
281
281
|
:long => "--cookbook-path PATH",
|
282
282
|
:description => "Cookbook search path, Default chef/cookbooks/:chef/vendor-cookbooks",
|
283
|
-
:default => ["cookbooks
|
283
|
+
:default => ["cookbooks","vendor-cookbooks"],
|
284
284
|
:proc => lambda{|v|
|
285
285
|
$CHOP.parseOptionString(v,'[:,]','parsePath')
|
286
286
|
}
|
287
287
|
option :repo_path,
|
288
288
|
:long => "--repo-path PATH",
|
289
289
|
:description => "Chef repo path, Default ./chef",
|
290
|
-
:default => "
|
290
|
+
:default => ".",
|
291
291
|
#:required => true,
|
292
292
|
:proc => lambda{|v|
|
293
293
|
File.expand_path(v)
|
@@ -307,12 +307,12 @@ class Chef
|
|
307
307
|
:proc => lambda{|v|
|
308
308
|
$CHOP.parseOptionString(v)
|
309
309
|
},
|
310
|
-
:default => ['
|
310
|
+
:default => ['.*']
|
311
311
|
option :databags,
|
312
312
|
:short => "-b",
|
313
313
|
:long => "--databags BAGS",
|
314
314
|
:description => "Data bags to upload",
|
315
|
-
:default => ['
|
315
|
+
:default => ['.*:.*'],
|
316
316
|
:proc => lambda{|v|
|
317
317
|
$CHOP.parseOptionString(v)
|
318
318
|
}
|
@@ -320,7 +320,7 @@ class Chef
|
|
320
320
|
:short => "-r",
|
321
321
|
:long => "--roles ROLES",
|
322
322
|
:description => "Roles to upload",
|
323
|
-
:default => ["
|
323
|
+
:default => [".*"],
|
324
324
|
:proc => lambda{|v|
|
325
325
|
$CHOP.parseOptionString(v)
|
326
326
|
}
|
@@ -750,6 +750,18 @@ class Chef
|
|
750
750
|
end
|
751
751
|
end
|
752
752
|
|
753
|
+
# --------------------------------------------------------------------------------
|
754
|
+
def getKnifeSubCommand(rsrc, verb)
|
755
|
+
# WARNING: Don't be clever ... rsrc and verb can each have one or more spaces ... argv = [rsrc, verb]
|
756
|
+
argv = "#{rsrc} #{verb}".split(%r(\s+))
|
757
|
+
klass= ::Chef::Knife.subcommand_class_from(argv)
|
758
|
+
subc = klass.new
|
759
|
+
subc.config = @config.dup
|
760
|
+
subc.config[:cookbook_path] = @config[:cookbook_path].map { |p| p.match(%r(^/)) ? p : "#{@config[:repo_path]}/#{p}" } #.join(::File::PATH_SEPARATOR)
|
761
|
+
subc.ui = ::Chef::Knife::ChopUI.new(@logger, @config)
|
762
|
+
subc
|
763
|
+
end
|
764
|
+
|
753
765
|
# --------------------------------------------------------------------------------
|
754
766
|
def callCmdProc(cmdp, a, b, c)
|
755
767
|
ret = nil
|
@@ -47,6 +47,38 @@ class Chef
|
|
47
47
|
private
|
48
48
|
# --------------------------------------------------------------------------------
|
49
49
|
|
50
|
+
# --------------------------------------------------------------------------------
|
51
|
+
def maybeCreateDataBag(bag)
|
52
|
+
subc = getKnifeSubCommand('data bag','show')
|
53
|
+
subc.name_args << bag
|
54
|
+
subc.name_args.flatten!
|
55
|
+
create = false
|
56
|
+
unless @config[:dry_run]
|
57
|
+
begin
|
58
|
+
subc.run
|
59
|
+
rescue => e
|
60
|
+
@logger.info "Searching for data bag yields: #{e.response.body if e.respond_to?('response')}"
|
61
|
+
@logger.warn "Create data bag #{bag}"
|
62
|
+
create = true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
if create
|
66
|
+
|
67
|
+
subc = getKnifeSubCommand('data bag','create')
|
68
|
+
subc.name_args << bag
|
69
|
+
subc.name_args.flatten!
|
70
|
+
|
71
|
+
unless @config[:dry_run]
|
72
|
+
begin
|
73
|
+
subc.run
|
74
|
+
rescue => e
|
75
|
+
@logger.error "#{e.class.name} #{e.message} #{e.response.body if e.respond_to?('response')}"
|
76
|
+
raise e
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
50
82
|
# --------------------------------------------------------------------------------
|
51
83
|
def uploadSet(set,args={})
|
52
84
|
raise ChopInternalError.new "Incorrect use of uploadSet method from #{Kernel.caller[0].ai}" unless args.is_a?(Hash)
|
@@ -66,18 +98,20 @@ class Chef
|
|
66
98
|
%(#{cmd} #{file})
|
67
99
|
}
|
68
100
|
cmd = callCmdProc(cmdp, rsrc,verb,xtra)
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
101
|
+
# [2014-07-28 Christo] Distilled out a reusable method called getKnifeSubCommand
|
102
|
+
# _getsubcmd = lambda do |r,v|
|
103
|
+
# argv = "#{r} #{v}".split(%r(\s+))
|
104
|
+
# klass= Chef::Knife.subcommand_class_from(argv)
|
105
|
+
# subc = klass.new
|
106
|
+
# subc.config = @config.dup
|
107
|
+
# subc.config[:cookbook_path] = @config[:cookbook_path].map { |p| p.match(%r(^/)) ? p : "#{@config[:repo_path]}/#{p}" } #.join(::File::PATH_SEPARATOR)
|
108
|
+
# subc.ui = ::Chef::Knife::ChopUI.new(@logger, @config)
|
109
|
+
# subc
|
110
|
+
# end
|
78
111
|
|
79
112
|
if args[:aggregate] and @use_knife_api
|
80
|
-
subc = _getsubcmd.call
|
113
|
+
# subc = _getsubcmd.call(rsrc,verb)
|
114
|
+
subc = getKnifeSubCommand(rsrc,verb)
|
81
115
|
subc.name_args << xtra if xtra != ''
|
82
116
|
subc.name_args << set.map{ |name,file|
|
83
117
|
extname = File.extname(file)
|
@@ -105,7 +139,6 @@ class Chef
|
|
105
139
|
end
|
106
140
|
}
|
107
141
|
subc.name_args.flatten!
|
108
|
-
#cmd = callCmdProc(filp, cmd, set.map{|name,file| name}.to_s, set.map{|name,file| file}.join(' '))
|
109
142
|
@logger.info "#{cmd} #{set.map{|name,file| file}.ai} ... "
|
110
143
|
@logger.info "#{cmd} #{subc.name_args.ai} ... "
|
111
144
|
unless @config[:dry_run]
|
@@ -158,7 +191,7 @@ class Chef
|
|
158
191
|
logStep "Upload data bags"
|
159
192
|
want = Hash.new
|
160
193
|
@config[:databags].each{ |b|
|
161
|
-
match = b.match(%r/^(
|
194
|
+
match = b.match(%r/^(.*?):(.*)$/)
|
162
195
|
if match
|
163
196
|
want[match[1]] = parseOptionString(match[2],'[:;]')
|
164
197
|
end
|
@@ -170,14 +203,23 @@ class Chef
|
|
170
203
|
name = File.basename(d)
|
171
204
|
regex = "^(#{want.keys.join('|')})"
|
172
205
|
match = matches(name,regex)
|
173
|
-
if match
|
174
|
-
|
206
|
+
if match
|
207
|
+
if want.has_key?(name)
|
208
|
+
keys = [ name ]
|
209
|
+
else
|
210
|
+
keys = want.keys.select{|k| name.match(/^#{k}/) }
|
211
|
+
end
|
212
|
+
databags[name] = {}
|
213
|
+
keys.each do |key|
|
214
|
+
databags[name].merge! getPathSet(want[key], "data_bags/#{name}")
|
215
|
+
end
|
175
216
|
@logger.debug "Data bags: (#{name}) #{databags[name].ai}"
|
176
217
|
end
|
177
218
|
end
|
178
219
|
}
|
179
220
|
@logger.info "Data bag list: (#{@config[:databags]}) #{databags.ai}"
|
180
221
|
databags.each{ |bag,files|
|
222
|
+
maybeCreateDataBag(bag)
|
181
223
|
uploadSet(files, :resource => 'data bag', :extra => bag, :aggregate => true)
|
182
224
|
}
|
183
225
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-chop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christo De Lange
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - ! '>='
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rubygems-tasks
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ~>
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0.2'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ~>
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0.2'
|
167
181
|
description: Knife plugin to assist with the upload and sync of Chef server assets
|
168
182
|
like roles, environments and cookbooks allowing for multiple parts to be uploaded
|
169
183
|
at once to multiple environments. Resources can be matched with regular expressions.
|