knife-spork-berks 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +284 -0
- data/Gemfile +3 -0
- data/LICENSE +35 -0
- data/README.md +406 -0
- data/Rakefile +2 -0
- data/knife-spork-berks.gemspec +22 -0
- data/lib/chef/knife/spork-bump.rb +86 -0
- data/lib/chef/knife/spork-check.rb +149 -0
- data/lib/chef/knife/spork-databag-create.rb +53 -0
- data/lib/chef/knife/spork-databag-delete.rb +51 -0
- data/lib/chef/knife/spork-databag-edit.rb +54 -0
- data/lib/chef/knife/spork-databag-fromfile.rb +82 -0
- data/lib/chef/knife/spork-environment-create.rb +43 -0
- data/lib/chef/knife/spork-environment-delete.rb +36 -0
- data/lib/chef/knife/spork-environment-edit.rb +37 -0
- data/lib/chef/knife/spork-environment-fromfile.rb +42 -0
- data/lib/chef/knife/spork-info.rb +30 -0
- data/lib/chef/knife/spork-node-create.rb +38 -0
- data/lib/chef/knife/spork-node-delete.rb +38 -0
- data/lib/chef/knife/spork-node-edit.rb +45 -0
- data/lib/chef/knife/spork-node-fromfile.rb +43 -0
- data/lib/chef/knife/spork-node-runlistadd.rb +48 -0
- data/lib/chef/knife/spork-node-runlistremove.rb +42 -0
- data/lib/chef/knife/spork-node-runlistset.rb +42 -0
- data/lib/chef/knife/spork-omni.rb +107 -0
- data/lib/chef/knife/spork-promote.rb +166 -0
- data/lib/chef/knife/spork-role-create.rb +43 -0
- data/lib/chef/knife/spork-role-delete.rb +36 -0
- data/lib/chef/knife/spork-role-edit.rb +37 -0
- data/lib/chef/knife/spork-role-fromfile.rb +42 -0
- data/lib/chef/knife/spork-upload.rb +129 -0
- data/lib/knife-spork.rb +3 -0
- data/lib/knife-spork/plugins.rb +25 -0
- data/lib/knife-spork/plugins/campfire.rb +211 -0
- data/lib/knife-spork/plugins/eventinator.rb +317 -0
- data/lib/knife-spork/plugins/foodcritic.rb +46 -0
- data/lib/knife-spork/plugins/git.rb +197 -0
- data/lib/knife-spork/plugins/graphite.rb +25 -0
- data/lib/knife-spork/plugins/grove.rb +161 -0
- data/lib/knife-spork/plugins/hipchat.rb +131 -0
- data/lib/knife-spork/plugins/irccat.rb +298 -0
- data/lib/knife-spork/plugins/jabber.rb +129 -0
- data/lib/knife-spork/plugins/plugin.rb +105 -0
- data/lib/knife-spork/plugins/statusnet.rb +118 -0
- data/lib/knife-spork/runner.rb +277 -0
- data/plugins/Campfire.md +43 -0
- data/plugins/Eventinator.md +30 -0
- data/plugins/Foodcritic.md +53 -0
- data/plugins/Git.md +46 -0
- data/plugins/Graphite.md +30 -0
- data/plugins/Grove.md +31 -0
- data/plugins/HipChat.md +50 -0
- data/plugins/Irccat.md +50 -0
- data/plugins/Jabber.md +61 -0
- data/plugins/README.md +70 -0
- data/plugins/StatusNet.md +41 -0
- data/plugins/Template.md +34 -0
- metadata +170 -0
@@ -0,0 +1,298 @@
|
|
1
|
+
require 'knife-spork/plugins/plugin'
|
2
|
+
|
3
|
+
module KnifeSpork
|
4
|
+
module Plugins
|
5
|
+
class Irccat < Plugin
|
6
|
+
name :irccat
|
7
|
+
|
8
|
+
TEMPLATES = {
|
9
|
+
:upload => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} uploaded #TEAL%{cookbooks}#NORMAL',
|
10
|
+
:promote => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} promoted #TEAL%{cookbooks}#NORMAL to %{environment} %{gist}',
|
11
|
+
:environmentfromfile => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} uploaded environment #TEAL%{object_name}#NORMAL %{gist}',
|
12
|
+
:environmentedit => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} edited environment #TEAL%{object_name}#NORMAL %{gist}',
|
13
|
+
:environmentcreate => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} created environment #TEAL%{object_name}#NORMAL %{gist}',
|
14
|
+
:environmentdelete => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} deleted environment #TEAL%{object_name}#NORMAL %{gist}',
|
15
|
+
:rolefromfile => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} uploaded role #TEAL%{object_name}#NORMAL %{gist}',
|
16
|
+
:roleedit => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} edited role #TEAL%{object_name}#NORMAL %{gist}',
|
17
|
+
:rolecreate => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} created role #TEAL%{object_name}#NORMAL %{gist}',
|
18
|
+
:roledelete => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} deleted role #TEAL%{object_name}#NORMAL %{gist}',
|
19
|
+
:databagedit => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} edited data bag item #TEAL%{object_name}:%{object_secondary_name}#NORMAL %{gist}',
|
20
|
+
:databagdelete => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} deleted data bag #TEAL%{object_name}#NORMAL %{gist}',
|
21
|
+
:databagitemdelete => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} deleted data bag item #TEAL%{object_name}:%{object_secondary_name}#NORMAL %{gist}',
|
22
|
+
:databagcreate => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} created data bag #TEAL%{object_name}#NORMAL %{gist}',
|
23
|
+
:databagfromfile => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} uploaded data bag item #TEAL%{object_name}:%{object_secondary_name}#NORMAL %{gist}',
|
24
|
+
:nodeedit => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} edited node #TEAL%{object_name}#NORMAL %{gist}',
|
25
|
+
:nodedelete => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} deleted node #TEAL%{object_name}#NORMAL %{gist}',
|
26
|
+
:nodecreate => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} created node #TEAL%{object_name}#NORMAL %{gist}',
|
27
|
+
:nodefromfile => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} uploaded node #TEAL%{object_name}#NORMAL %{gist}',
|
28
|
+
:noderunlistadd => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} added run_list items to #TEAL%{object_name}: %{object_secondary_name}#NORMAL %{gist}',
|
29
|
+
:noderunlistremove => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} removed run_list items from #TEAL%{object_name}: %{object_secondary_name}#NORMAL %{gist}',
|
30
|
+
:noderunlistset => '#BOLD#PURPLECHEF:#NORMAL %{organization}%{current_user} set the run_list for #TEAL%{object_name} to %{object_secondary_name}#NORMAL %{gist}'
|
31
|
+
}
|
32
|
+
|
33
|
+
def perform; end
|
34
|
+
|
35
|
+
def after_upload
|
36
|
+
irccat(template(:upload) % {
|
37
|
+
:organization => organization,
|
38
|
+
:current_user => current_user,
|
39
|
+
:cookbooks => cookbooks.collect { |c| "#{c.name}@#{c.version}" }.join(", ")
|
40
|
+
})
|
41
|
+
end
|
42
|
+
|
43
|
+
def after_promote_remote
|
44
|
+
environments.each do |environment|
|
45
|
+
diff = environment_diffs[environment.name]
|
46
|
+
env_gist = env_gist(environment, diff) if config.gist
|
47
|
+
irccat(template(:promote) % {
|
48
|
+
:organization => organization,
|
49
|
+
:current_user => current_user,
|
50
|
+
:cookbooks => cookbooks.collect{ |c| "#{c.name}@#{c.version}" }.join(", "),
|
51
|
+
:environment => environment.name,
|
52
|
+
:gist => env_gist
|
53
|
+
})
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def after_environmentfromfile
|
58
|
+
environment_gist = object_gist("environment", object_name, object_difference) if config.gist and !object_difference.empty?
|
59
|
+
irccat(template(:environmentfromfile) % {
|
60
|
+
:organization => organization,
|
61
|
+
:current_user => current_user,
|
62
|
+
:object_name => object_name,
|
63
|
+
:gist => environment_gist
|
64
|
+
})
|
65
|
+
end
|
66
|
+
|
67
|
+
def after_environmentedit
|
68
|
+
environment_gist = object_gist("environment", object_name, object_difference) if config.gist and !object_difference.empty?
|
69
|
+
irccat(template(:environmentedit) % {
|
70
|
+
:organization => organization,
|
71
|
+
:current_user => current_user,
|
72
|
+
:object_name => object_name,
|
73
|
+
:gist => environment_gist
|
74
|
+
})
|
75
|
+
end
|
76
|
+
|
77
|
+
def after_environmentcreate
|
78
|
+
environment_gist = object_gist("environment", object_name, object_difference) if config.gist and !object_difference.empty?
|
79
|
+
irccat(template(:environmentcreate) % {
|
80
|
+
:organization => organization,
|
81
|
+
:current_user => current_user,
|
82
|
+
:object_name => object_name,
|
83
|
+
:gist => environment_gist
|
84
|
+
})
|
85
|
+
end
|
86
|
+
|
87
|
+
def after_environmentdelete
|
88
|
+
environment_gist = object_gist("environment", object_name, object_difference) if config.gist and !object_difference.empty?
|
89
|
+
irccat(template(:environmentdelete) % {
|
90
|
+
:organization => organization,
|
91
|
+
:current_user => current_user,
|
92
|
+
:object_name => object_name,
|
93
|
+
:gist => environment_gist
|
94
|
+
})
|
95
|
+
end
|
96
|
+
|
97
|
+
def after_rolefromfile
|
98
|
+
role_gist = object_gist("role", object_name, object_difference) if config.gist and !object_difference.empty?
|
99
|
+
irccat(template(:rolefromfile) % {
|
100
|
+
:organization => organization,
|
101
|
+
:current_user => current_user,
|
102
|
+
:object_name => object_name,
|
103
|
+
:gist => role_gist
|
104
|
+
})
|
105
|
+
end
|
106
|
+
|
107
|
+
def after_roleedit
|
108
|
+
role_gist = object_gist("role", object_name, object_difference) if config.gist and !object_difference.empty?
|
109
|
+
irccat(template(:roleedit) % {
|
110
|
+
:organization => organization,
|
111
|
+
:current_user => current_user,
|
112
|
+
:object_name => object_name,
|
113
|
+
:gist => role_gist
|
114
|
+
})
|
115
|
+
end
|
116
|
+
|
117
|
+
def after_rolecreate
|
118
|
+
role_gist = object_gist("role", object_name, object_difference) if config.gist and !object_difference.empty?
|
119
|
+
irccat(template(:rolecreate) % {
|
120
|
+
:organization => organization,
|
121
|
+
:current_user => current_user,
|
122
|
+
:object_name => object_name,
|
123
|
+
:gist => role_gist
|
124
|
+
})
|
125
|
+
end
|
126
|
+
|
127
|
+
def after_roledelete
|
128
|
+
role_gist = object_gist("role", object_name, object_difference) if config.gist and !object_difference.empty?
|
129
|
+
irccat(template(:roledelete) % {
|
130
|
+
:organization => organization,
|
131
|
+
:current_user => current_user,
|
132
|
+
:object_name => object_name,
|
133
|
+
:gist => role_gist
|
134
|
+
})
|
135
|
+
end
|
136
|
+
|
137
|
+
def after_databagedit
|
138
|
+
databag_gist = object_gist("databag item", "#{object_name}:#{object_secondary_name}", object_difference) if config.gist and !object_difference.empty?
|
139
|
+
irccat(template(:databagedit) % {
|
140
|
+
:organization => organization,
|
141
|
+
:current_user => current_user,
|
142
|
+
:object_name => object_name,
|
143
|
+
:object_secondary_name => object_secondary_name,
|
144
|
+
:gist => databag_gist
|
145
|
+
})
|
146
|
+
end
|
147
|
+
|
148
|
+
def after_databagdelete
|
149
|
+
databag_gist = object_gist("databag item", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
|
150
|
+
irccat(template(:databagdelete) % {
|
151
|
+
:organization => organization,
|
152
|
+
:current_user => current_user,
|
153
|
+
:object_name => object_name,
|
154
|
+
:gist => databag_gist
|
155
|
+
})
|
156
|
+
end
|
157
|
+
|
158
|
+
def after_databagitemdelete
|
159
|
+
databag_gist = object_gist("databag item", "#{object_name}:#{object_secondary_name}", object_difference) if config.gist and !object_difference.empty?
|
160
|
+
irccat(template(:databagitemdelete) % {
|
161
|
+
:organization => organization,
|
162
|
+
:current_user => current_user,
|
163
|
+
:object_name => object_name,
|
164
|
+
:object_secondary_name => object_secondary_name,
|
165
|
+
:gist => databag_gist
|
166
|
+
})
|
167
|
+
end
|
168
|
+
|
169
|
+
def after_databagcreate
|
170
|
+
databag_gist = object_gist("databag", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
|
171
|
+
irccat(template(:databagcreate) % {
|
172
|
+
:organization => organization,
|
173
|
+
:current_user => current_user,
|
174
|
+
:object_name => object_name,
|
175
|
+
:gist => databag_gist
|
176
|
+
})
|
177
|
+
end
|
178
|
+
|
179
|
+
def after_databagfromfile
|
180
|
+
databag_gist = object_gist("databag", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
|
181
|
+
irccat(template(:databagfromfile) % {
|
182
|
+
:organization => organization,
|
183
|
+
:current_user => current_user,
|
184
|
+
:object_name => object_name,
|
185
|
+
:object_secondary_name => object_secondary_name,
|
186
|
+
:gist => databag_gist
|
187
|
+
})
|
188
|
+
end
|
189
|
+
|
190
|
+
def after_nodeedit
|
191
|
+
node_gist = object_gist("node", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
|
192
|
+
irccat(template(:nodeedit) % {
|
193
|
+
:organization => organization,
|
194
|
+
:current_user => current_user,
|
195
|
+
:object_name => object_name,
|
196
|
+
:gist => node_gist
|
197
|
+
})
|
198
|
+
end
|
199
|
+
|
200
|
+
def after_nodedelete
|
201
|
+
node_gist = object_gist("node", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
|
202
|
+
irccat(template(:nodedelete) % {
|
203
|
+
:organization => organization,
|
204
|
+
:current_user => current_user,
|
205
|
+
:object_name => object_name,
|
206
|
+
:gist => node_gist
|
207
|
+
})
|
208
|
+
end
|
209
|
+
|
210
|
+
def after_nodecreate
|
211
|
+
node_gist = object_gist("node", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
|
212
|
+
irccat(template(:nodecreate) % {
|
213
|
+
:organization => organization,
|
214
|
+
:current_user => current_user,
|
215
|
+
:object_name => object_name,
|
216
|
+
:gist => node_gist
|
217
|
+
})
|
218
|
+
end
|
219
|
+
|
220
|
+
def after_nodefromfile
|
221
|
+
node_gist = object_gist("node", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
|
222
|
+
irccat(template(:nodefromfile) % {
|
223
|
+
:organization => organization,
|
224
|
+
:current_user => current_user,
|
225
|
+
:object_name => object_name,
|
226
|
+
:gist => node_gist
|
227
|
+
})
|
228
|
+
end
|
229
|
+
|
230
|
+
def after_noderunlistadd
|
231
|
+
node_gist = object_gist("node", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
|
232
|
+
irccat(template(:noderunlistadd) % {
|
233
|
+
:organization => organization,
|
234
|
+
:current_user => current_user,
|
235
|
+
:object_name => object_name,
|
236
|
+
:object_secondary_name => object_secondary_name,
|
237
|
+
:gist => node_gist
|
238
|
+
})
|
239
|
+
end
|
240
|
+
|
241
|
+
def after_noderunlistremove
|
242
|
+
node_gist = object_gist("node", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
|
243
|
+
irccat(template(:noderunlistremove) % {
|
244
|
+
:organization => organization,
|
245
|
+
:current_user => current_user,
|
246
|
+
:object_name => object_name,
|
247
|
+
:object_secondary_name => object_secondary_name,
|
248
|
+
:gist => node_gist
|
249
|
+
})
|
250
|
+
end
|
251
|
+
|
252
|
+
def after_noderunlistset
|
253
|
+
node_gist = object_gist("node", "#{object_name}", object_difference) if config.gist and !object_difference.empty?
|
254
|
+
irccat(template(:noderunlistset) % {
|
255
|
+
:organization => organization,
|
256
|
+
:current_user => current_user,
|
257
|
+
:object_name => object_name,
|
258
|
+
:object_secondary_name => object_secondary_name,
|
259
|
+
:gist => node_gist
|
260
|
+
})
|
261
|
+
end
|
262
|
+
|
263
|
+
private
|
264
|
+
def irccat(message)
|
265
|
+
channels.each do |channel|
|
266
|
+
begin
|
267
|
+
# Write the message using a TCP Socket
|
268
|
+
socket = TCPSocket.open(config.server, config.port)
|
269
|
+
socket.write("#{channel} #{message}")
|
270
|
+
rescue Exception => e
|
271
|
+
ui.error 'Failed to post message with irccat.'
|
272
|
+
ui.error e.to_s
|
273
|
+
ensure
|
274
|
+
socket.close unless socket.nil?
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
def env_gist(environment, diff)
|
280
|
+
msg = "Environment #{environment} uploaded at #{Time.now.getutc} by #{current_user}\n\nConstraints updated on server in this version:\n\n#{diff.collect { |k, v| "#{k}: #{v}\n" }.join}"
|
281
|
+
%x[ echo "#{msg}" | #{config.gist}]
|
282
|
+
end
|
283
|
+
|
284
|
+
def object_gist(object_type, object_name, object_diff)
|
285
|
+
msg = "#{object_type.capitalize} #{object_name} changed at #{Time.now.getutc} by #{current_user}\n\nDiff is as follows:\n\n#{object_diff}"
|
286
|
+
%x[ echo "#{msg}" | #{config.gist}]
|
287
|
+
end
|
288
|
+
|
289
|
+
def channels
|
290
|
+
[ config.channel || config.channels ].flatten
|
291
|
+
end
|
292
|
+
|
293
|
+
def template(name)
|
294
|
+
(config.template && config.template[name]) || TEMPLATES[name]
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'knife-spork/plugins/plugin'
|
2
|
+
|
3
|
+
module KnifeSpork
|
4
|
+
module Plugins
|
5
|
+
class Jabber < Plugin
|
6
|
+
name :jabber
|
7
|
+
|
8
|
+
def perform; end
|
9
|
+
|
10
|
+
def after_upload
|
11
|
+
jabber "#{organization}#{current_user} uploaded the following cookbooks:\n#{cookbooks.collect{ |c| " #{c.name}@#{c.version}" }.join("\n")}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def after_promote_remote
|
15
|
+
jabber "#{organization}#{current_user} promoted the following cookbooks:\n#{cookbooks.collect{ |c| " #{c.name}@#{c.version}" }.join("\n")} to #{environments.collect{ |e| "#{e.name}" }.join(", ")}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def after_environmentfromfile
|
19
|
+
jabber "#{organization}#{current_user} uploaded environment #{object_name}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def after_environmentedit
|
23
|
+
jabber "#{organization}#{current_user} edited environment #{object_name}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def after_environmentcreate
|
27
|
+
jabber "#{organization}#{current_user} created environment #{object_name}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def after_environmentdelete
|
31
|
+
jabber "#{organization}#{current_user} deleted environment #{object_name}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def after_rolefromfile
|
35
|
+
jabber "#{organization}#{current_user} uploaded role #{object_name}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def after_roleedit
|
39
|
+
jabber "#{organization}#{current_user} edited role #{object_name}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def after_rolecreate
|
43
|
+
jabber "#{organization}#{current_user} created role #{object_name}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def after_roledelete
|
47
|
+
jabber "#{organization}#{current_user} deleted role #{object_name}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def after_databagedit
|
51
|
+
jabber "#{organization}#{current_user} edited data bag item #{object_name}:#{object_secondary_name}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def after_databagcreate
|
55
|
+
jabber "#{organization}#{current_user} created data bag #{object_name}"
|
56
|
+
end
|
57
|
+
|
58
|
+
def after_databagdelete
|
59
|
+
jabber "#{organization}#{current_user} deleted data bag #{object_name}"
|
60
|
+
end
|
61
|
+
|
62
|
+
def after_databagitemdelete
|
63
|
+
jabber "#{organization}#{current_user} deleted data bag item #{object_name}:#{object_secondary_name}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def after_databagfromfile
|
67
|
+
jabber "#{organization}#{current_user} uploaded data bag item #{object_name}:#{object_secondary_name}"
|
68
|
+
end
|
69
|
+
|
70
|
+
def after_nodeedit
|
71
|
+
jabber "#{organization}#{current_user} edited node #{object_name}"
|
72
|
+
end
|
73
|
+
|
74
|
+
def after_nodedelete
|
75
|
+
jabber "#{organization}#{current_user} deleted node #{object_name}"
|
76
|
+
end
|
77
|
+
|
78
|
+
def after_nodecreate
|
79
|
+
jabber "#{organization}#{current_user} created node #{object_name}"
|
80
|
+
end
|
81
|
+
|
82
|
+
def after_nodefromfile
|
83
|
+
jabber "#{organization}#{current_user} uploaded node #{object_name}"
|
84
|
+
end
|
85
|
+
|
86
|
+
def after_noderunlistadd
|
87
|
+
jabber "#{organization}#{current_user} added run_list items to #{object_name}: #{object_secondary_name}"
|
88
|
+
end
|
89
|
+
|
90
|
+
def after_noderunlistremove
|
91
|
+
jabber "#{organization}#{current_user} removed run_list items from #{object_name}: #{object_secondary_name}"
|
92
|
+
end
|
93
|
+
|
94
|
+
def after_noderunlistset
|
95
|
+
jabber "#{organization}#{current_user} set the run_list for #{object_name} to #{object_secondary_name}"
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def jabber(message)
|
101
|
+
safe_require 'xmpp4r'
|
102
|
+
safe_require 'xmpp4r/muc/helper/simplemucclient'
|
103
|
+
|
104
|
+
client = ::Jabber::Client.new(config.username)
|
105
|
+
client.connect(host = config.server_name, port = config.server_port ||= '5222')
|
106
|
+
client.auth(config.password)
|
107
|
+
|
108
|
+
rooms.each do |room_name|
|
109
|
+
begin
|
110
|
+
conference = ::Jabber::MUC::SimpleMUCClient.new(client)
|
111
|
+
conference.join("#{room_name}/#{nickname}")
|
112
|
+
conference.say(message)
|
113
|
+
rescue Exception => e
|
114
|
+
ui.error 'Something went wrong sending to Jabber.'
|
115
|
+
ui.error e.to_s
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def rooms
|
121
|
+
[ config.room || config.rooms ].flatten
|
122
|
+
end
|
123
|
+
|
124
|
+
def nickname
|
125
|
+
config.nickname || 'KnifeSpork'
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module KnifeSpork
|
2
|
+
module Plugins
|
3
|
+
class Plugin
|
4
|
+
# This is the name of the plugin. It must correspond to the name in the yaml configuration
|
5
|
+
# file in order to load this plugin. If an attribute is passed in, the name is set to that
|
6
|
+
# given value. Otherwise, the name is returned.
|
7
|
+
def self.name(name = nil)
|
8
|
+
if name.nil?
|
9
|
+
class_variable_get(:@@name)
|
10
|
+
else
|
11
|
+
class_variable_set(:@@name, name)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# This is a convenience method for defining multiple hooks in a single call.
|
16
|
+
def self.hooks(*the_hooks)
|
17
|
+
[the_hooks].flatten.each{ |the_hook| hook(the_hook) }
|
18
|
+
end
|
19
|
+
|
20
|
+
# When defining a hook, we define a method on the instance that corresponds to that
|
21
|
+
# hook. That will be fired when the hook is fired.
|
22
|
+
def self.hook(the_hook)
|
23
|
+
self.send(:define_method, the_hook.to_sym) do
|
24
|
+
perform
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(options = {})
|
29
|
+
@options = {
|
30
|
+
:payload => {}
|
31
|
+
}.merge(options)
|
32
|
+
end
|
33
|
+
|
34
|
+
def enabled?
|
35
|
+
!(config.nil? || config.enabled == false)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def config
|
40
|
+
@options[:config].plugins.send(self.class.name.to_sym) unless @options[:config].nil? || @options[:config].plugins.nil?
|
41
|
+
end
|
42
|
+
|
43
|
+
def organization
|
44
|
+
unless ::Chef::Config.chef_server_url.nil?
|
45
|
+
split_server_url = Chef::Config.chef_server_url.gsub(/http(s)?:\/\//,"").split('/')
|
46
|
+
if split_server_url.length > 1
|
47
|
+
return "#{split_server_url.last}: "
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
|
54
|
+
def cookbooks
|
55
|
+
@options[:cookbooks]
|
56
|
+
end
|
57
|
+
|
58
|
+
def environments
|
59
|
+
@options[:environments]
|
60
|
+
end
|
61
|
+
|
62
|
+
def environment_diffs
|
63
|
+
@options[:environment_diffs]
|
64
|
+
end
|
65
|
+
|
66
|
+
def environment_path
|
67
|
+
@options[:environment_path]
|
68
|
+
end
|
69
|
+
|
70
|
+
def cookbook_path
|
71
|
+
@options[:cookbook_path]
|
72
|
+
end
|
73
|
+
|
74
|
+
def object_name
|
75
|
+
@options[:object_name]
|
76
|
+
end
|
77
|
+
|
78
|
+
def object_secondary_name
|
79
|
+
@options[:object_secondary_name]
|
80
|
+
end
|
81
|
+
|
82
|
+
def object_difference
|
83
|
+
@options[:object_difference]
|
84
|
+
end
|
85
|
+
|
86
|
+
def ui
|
87
|
+
@options[:ui]
|
88
|
+
end
|
89
|
+
|
90
|
+
def current_user
|
91
|
+
(begin `git config user.name`.chomp; rescue nil; end || ENV['USERNAME'] || ENV['USER']).strip
|
92
|
+
end
|
93
|
+
|
94
|
+
# Wrapper method around require that attempts to include the associated file. If it does not exist
|
95
|
+
# or cannot be loaded, an nice error is produced instead of blowing up.
|
96
|
+
def safe_require(file)
|
97
|
+
begin
|
98
|
+
require file
|
99
|
+
rescue LoadError
|
100
|
+
raise "You are using a plugin for knife-spork that requires #{file}, but you have not installed it. Please either run \"gem install #{file}\", add #{file} to your Gemfile or remove the plugin from your configuration."
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|