knife-spork 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/CHANGELOG.md +18 -0
  2. data/LICENSE +1 -1
  3. data/README.md +131 -5
  4. data/knife-spork.gemspec +3 -2
  5. data/lib/chef/knife/spork-check.rb +13 -1
  6. data/lib/chef/knife/spork-databag-create.rb +53 -0
  7. data/lib/chef/knife/spork-databag-delete.rb +51 -0
  8. data/lib/chef/knife/spork-databag-edit.rb +54 -0
  9. data/lib/chef/knife/spork-databag-fromfile.rb +82 -0
  10. data/lib/chef/knife/spork-node-create.rb +38 -0
  11. data/lib/chef/knife/spork-node-delete.rb +38 -0
  12. data/lib/chef/knife/spork-node-edit.rb +45 -0
  13. data/lib/chef/knife/spork-node-fromfile.rb +43 -0
  14. data/lib/chef/knife/spork-node-runlistadd.rb +48 -0
  15. data/lib/chef/knife/spork-node-runlistremove.rb +42 -0
  16. data/lib/chef/knife/spork-node-runlistset.rb +42 -0
  17. data/lib/chef/knife/spork-omni.rb +107 -0
  18. data/lib/chef/knife/spork-promote.rb +2 -6
  19. data/lib/chef/knife/spork-role-create.rb +43 -0
  20. data/lib/chef/knife/spork-role-delete.rb +36 -0
  21. data/lib/chef/knife/spork-role-edit.rb +37 -0
  22. data/lib/chef/knife/spork-role-fromfile.rb +42 -0
  23. data/lib/knife-spork/plugins/campfire.rb +128 -0
  24. data/lib/knife-spork/plugins/eventinator.rb +199 -0
  25. data/lib/knife-spork/plugins/foodcritic.rb +8 -3
  26. data/lib/knife-spork/plugins/grove.rb +96 -0
  27. data/lib/knife-spork/plugins/hipchat.rb +65 -0
  28. data/lib/knife-spork/plugins/irccat.rb +190 -3
  29. data/lib/knife-spork/plugins/jabber.rb +64 -0
  30. data/lib/knife-spork/plugins/plugin.rb +12 -0
  31. data/lib/knife-spork/plugins/statusnet.rb +64 -0
  32. data/lib/knife-spork/plugins.rb +3 -0
  33. data/lib/knife-spork/runner.rb +51 -4
  34. data/plugins/Foodcritic.md +1 -1
  35. metadata +36 -4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## 1.3.0 (23rd October, 2013)
2
+
3
+ Features:
4
+
5
+ - Allow a custom plugin path to be specified in config to load additional plugins from (https://github.com/jonlives/knife-spork/issues/59)
6
+ - Spork check will prompt for a bump if one is needed (https://github.com/jonlives/knife-spork/issues/82)
7
+ - Spork omni command added to perform bump, upload and promote in a single step (https://github.com/jonlives/knife-spork/issues/49)
8
+ - Spork role, data bag and node commands added (https://github.com/jonlives/knife-spork/issues/81)
9
+
10
+ Bugfixes:
11
+
12
+ - Remove legacy code referring to "promote all cookbooks" (https://github.com/jonlives/knife-spork/issues/76)
13
+ - Fix incorrect cookbook version numbers in plugin output when -v used with promote (https://github.com/jonlives/knife-spork/issues/64)
14
+ - Replaced monkeypatched Hash#diff with an hash_diff method to fix clashes with ActiveSupport deprecation warnings. (Thanks to @RSO: https://github.com/jonlives/knife-spork/pull/84)
15
+ - Various fixes for Berkshelf issues (Thanks to @RSO and @sethvargo: https://github.com/jonlives/knife-spork/issues/73)
16
+ - Fix load_from_berkshelf method to return a CookbookVersion object (Thanks to @hanskrueger https://github.com/jonlives/knife-spork/pull/90)
17
+ - Fix foodcritic plugin to work properly with foodcritic > 3.0.0 (Thanks to @juliandunn https://github.com/jonlives/knife-spork/pull/94)
18
+
1
19
  ## 1.2.2 (10th Sept, 2013)
2
20
 
3
21
  Bugfixes:
data/LICENSE CHANGED
@@ -12,7 +12,7 @@ License:: GPL
12
12
 
13
13
  Other
14
14
  -----
15
- Based on the knife-cookbook-bump plugin by:
15
+ spork bump is based on the knife-cookbook-bump plugin by:
16
16
  Alalanta (no license specified)
17
17
 
18
18
  With snippets from:
data/README.md CHANGED
@@ -4,7 +4,8 @@ KnifeSpork is a workflow plugin for `Chef::Knife` which helps multiple developer
4
4
 
5
5
  Installation
6
6
  ------------
7
- ### Gem Install (recommended)
7
+
8
+ ### Gem Install
8
9
  `knife-spork` is available on rubygems. Add the following to your `Gemfile`:
9
10
 
10
11
  ```ruby
@@ -17,9 +18,7 @@ or install the gem manually:
17
18
  gem install knife-spork
18
19
  ```
19
20
 
20
- ### Plugin Install
21
- Copy spork-* script from lib/chef/knife/spork-*.rb to your ~/.chef/plugins/knife directory.
22
-
21
+ **Please note**: As of version 1.3.0, knife-spork depends on version 11.0.0 or greater of the chef gem. If you're still using Chef 10, please continue to use knife-spork 1.2.x
23
22
  Spork Configuration
24
23
  -------------------
25
24
  Out of the box, knife spork will work with no configuration. However, you can optionally enable several features to enhance its functionality.
@@ -47,10 +46,14 @@ environment_groups:
47
46
  - acceptance_testing
48
47
  version_change_threshold: 2
49
48
  environment_path: "/home/me/environments"
49
+ role_path: "/home/me/roles"
50
+ custom_plugin_path: "/home/me/spork-plugins"
50
51
  plugins:
51
52
  campfire:
52
53
  account: myaccount
53
54
  token: a1b2c3d4...
55
+ foodcritic:
56
+ tags: ['any']
54
57
  hipchat:
55
58
  api_token: ABC123
56
59
  rooms:
@@ -93,6 +96,13 @@ The `version_change_threshold` directive allows you to customise the threshold u
93
96
  #### Environment Path
94
97
  The `environment_path` allows you to specify the path to where you store your chef environment json files. If this parameter is not specified, spork will default to using the first element of your cookbook_path, replacing the word "cookbooks" with "environments"
95
98
 
99
+ #### Role Path
100
+ The `role_path` allows you to specify the path to where you store your chef role json files. If this parameter is not specified, spork will default to using the first element of your cookbook_path, replacing the word "cookbooks" with "roles"
101
+
102
+ #### Custom Plugin Path
103
+ The `custom_plugin_path` allows you to specify an additional directory from which to load knife-spork plugins. If this parameter is not specified or the path set does not exist, only the default plugins shipped with knife-spork will be loaded (if enabled in config)
104
+
105
+
96
106
  #### Plugins
97
107
  Knife spork supports plugins to allow users to hook it into existing systems such as source control, monitoring and chat systems. Plugins are enabled / disabled by adding / removing their config block from the plugin section of the config file. Any of the default plugins shown above can be disabled by removing their section.
98
108
 
@@ -198,7 +208,7 @@ This function lets you easily version your cookbooks without having to manually
198
208
 
199
209
  #### Usage
200
210
  ```bash
201
- knife spork bump COOKBOOK [MAJOR | MINOR | PATCH | MANUAL x.x.x]
211
+ knife spork bump COOKBOOK [major | minor | patch | manual x.x.x]
202
212
  ````
203
213
 
204
214
  #### Example (No patch level specified - defaulting to patch)
@@ -263,3 +273,119 @@ Adding version constraint apache2 = 2.0.2
263
273
  Saving changes to my_environment.json
264
274
  Promotion complete. Don't forget to upload your changed my_environment to Chef Server
265
275
  ```
276
+
277
+ Spork Omni
278
+ -------------
279
+ Omni lets you combine one of the most common combinations of spork commands (bump, upload & promote or promote --remote) - into one handy shortcut.
280
+
281
+ As omni is designed for use only in those cases where you want to perform all three of bump, upload and promote at the same time it supports a limited subset of the command line options supported by the individual bump, upload and promote commands.
282
+
283
+ If you run omni with no extra options, it will default to performing a ```patch``` level bump, and promote locally to the environments listed in the ```default_environments``` variable in your spork configuration file.
284
+
285
+ Alternatively, you can specify any of the following options:
286
+
287
+ ```--cookbook-path PATH:PATH```: A colon-separated path to look for cookbooks in
288
+
289
+ ```--include-dependencies```: Also upload cookbook dependencies during the upload step
290
+
291
+ ```--bump-level [major|minor|patch]```: Version level to bump the cookbook (defaults to patch)
292
+
293
+ ```--environment ENVIRONMENT```: Environment to promote the cookbook to',
294
+
295
+ ```--remote```: Make omni perform a promote --remote instead of a local promote',
296
+
297
+ #### Usage
298
+
299
+ ```bash
300
+ knife spork omni COOKBOOK [--bump-level, --cookbook-path, --include-dependencies, --environment, --remote]
301
+ ```
302
+
303
+ #### Example (default options, default_environments set to development and production)
304
+
305
+ ```text
306
+ $ knife spork omni apache2
307
+ OMNI: Bumping apache2
308
+ Successfully bumped apache2 to v0.3.99!
309
+
310
+ OMNI: Uploading apache2
311
+ Freezing apache2 at 0.3.99...
312
+ Successfully uploaded apache2@0.3.99!
313
+
314
+ OMNI: Promoting apache2
315
+ Adding version constraint apache2 = 0.3.99
316
+ Saving changes to development.json
317
+ Promotion complete. Don't forget to upload your changed development.json to Chef Server
318
+ Adding version constraint apache2 = 0.3.99
319
+ Saving changes to production.json
320
+ Promotion complete. Don't forget to upload your changed production.json to Chef Server
321
+ ```
322
+
323
+ #### Example (default options, default_environments set to development and production, promote --remote)
324
+
325
+ ```text
326
+ $ knife spork omni apache2 --remote
327
+ OMNI: Bumping apache2
328
+ Successfully bumped apache2 to v0.3.99!
329
+
330
+ OMNI: Uploading apache2
331
+ Freezing apache2 at 0.3.99...
332
+ Successfully uploaded apache2@0.3.99!
333
+
334
+ OMNI: Promoting apache2
335
+ Adding version constraint apache2 = 0.3.99
336
+ Saving changes to development.json
337
+ Uploading development.json to Chef Server
338
+ Promotion complete at 2013-08-08 11:43:12 +0100!
339
+ Adding version constraint apache2 = 0.3.99
340
+ Saving changes to production.json
341
+ Uploading production.json to Chef Server
342
+ Promotion complete at 2013-08-08 11:43:12 +0100!
343
+ ```
344
+
345
+ #### Example (Specifying patch level and environment)
346
+ ```text
347
+ $ knife spork omni apache2 -l minor -e development
348
+ OMNI: Bumping apache2
349
+ Successfully bumped apache2 to v0.4.0!
350
+
351
+ OMNI: Uploading apache2
352
+ Freezing apache2 at 0.4.0...
353
+ Successfully uploaded apache2@0.4.0!
354
+
355
+ OMNI: Promoting apache2
356
+ Adding version constraint apache2 = 0.4.0
357
+ Saving changes to development.json
358
+ Promotion complete. Don't forget to upload your changed development.json to Chef Server
359
+ ```
360
+
361
+ Spork Node / Role / Databag Commands
362
+ -------------
363
+
364
+ Knife spork contains "wrappers" around several stock knife commands for changing nodes, roles, and databags. These commands work exactly as in the original knife, with the addition of being wrapped in Spork's plugin API. This means that for example, when you upload a role using spork you will see an IRC message containing details, and a gist of the role change.
365
+
366
+ The following ```data bag``` commands are provided in knife-spork:
367
+ ```
368
+ knife spork data bag create
369
+ knife spork data bag delete
370
+ knife spork data bag edit
371
+ knife spork data bag from file
372
+ ```
373
+
374
+ The following ```node``` commands are provided in knife-spork:
375
+ ```
376
+ knife spork node create
377
+ knife spork node delete
378
+ knife spork node edit
379
+ knife spork node from file
380
+ knife spork node run_list add
381
+ knife spork node run_list remove
382
+ knife spork node run_list set
383
+ ```
384
+
385
+ The following ```role``` commands are provided in knife-spork:
386
+ ```
387
+ knife spork role create
388
+ knife spork role delete
389
+ knife spork role edit
390
+ knife spork role from file
391
+ ```
data/knife-spork.gemspec CHANGED
@@ -2,7 +2,7 @@ $:.push File.expand_path('../lib', __FILE__)
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'knife-spork'
5
- gem.version = '1.2.2'
5
+ gem.version = '1.3.0'
6
6
  gem.authors = ["Jon Cowie"]
7
7
  gem.email = 'jonlives@gmail.com'
8
8
  gem.homepage = 'https://github.com/jonlives/knife-spork'
@@ -15,7 +15,8 @@ Gem::Specification.new do |gem|
15
15
  gem.name = "knife-spork"
16
16
  gem.require_paths = ["lib"]
17
17
 
18
- gem.add_runtime_dependency 'chef', '>= 0.10.4'
18
+ gem.add_runtime_dependency 'chef', '>= 11.0.0'
19
19
  gem.add_runtime_dependency 'git', '>= 1.2.5'
20
20
  gem.add_runtime_dependency 'app_conf', '>= 0.4.0'
21
+ gem.add_runtime_dependency 'diffy', '>= 3.0.1'
21
22
  end
@@ -58,7 +58,19 @@ module KnifeSpork
58
58
  if remote_version == local_version
59
59
  if frozen?(remote_version)
60
60
  message = "Your local version (#{local_version}) is frozen on the remote server. You'll need to bump before you can upload."
61
- config[:fail] ? fail_and_exit("#{message}") : ui.warn("#{message}")
61
+ if config[:fail]
62
+ fail_and_exit("#{message}")
63
+ else
64
+ ui.warn("#{message}")
65
+ answer = ui.ask("Would you like to perform a patch-level bump on the #{@cookbook.name} cookbook now? (Y/N)")
66
+ if answer == "Y" or answer == "y"
67
+ bump = SporkBump.new
68
+ bump.name_args = [@cookbook.name]
69
+ bump.run
70
+ else
71
+ ui.info "Skipping bump..."
72
+ end
73
+ end
62
74
  else
63
75
  message = "The version #{local_version} exists on the server and is not frozen. Uploading will overwrite!"
64
76
  config[:fail] ? fail_and_exit("#{message}") : ui.error("#{message}")
@@ -0,0 +1,53 @@
1
+ require 'chef/knife'
2
+ require 'knife-spork/runner'
3
+ require 'json'
4
+
5
+ module KnifeSpork
6
+ class SporkDataBagCreate < Chef::Knife
7
+ include KnifeSpork::Runner
8
+
9
+ deps do
10
+ require 'chef/knife/data_bag_create'
11
+ end
12
+
13
+ banner 'knife data bag create BAG [ITEM] (options)'
14
+
15
+ option :secret,
16
+ :short => "-s SECRET",
17
+ :long => "--secret ",
18
+ :description => "The secret key to use to encrypt data bag item values"
19
+
20
+ option :secret_file,
21
+ :long => "--secret-file SECRET_FILE",
22
+ :description => "A file containing the secret key to use to encrypt data bag item values"
23
+
24
+ def run
25
+ self.config = Chef::Config.merge!(config)
26
+
27
+ if @name_args.nil?
28
+ ui.error "You must specify a data bag name"
29
+ ui.error opt_parser
30
+ exit 1
31
+ end
32
+
33
+ @object_name = @name_args.first
34
+
35
+ run_plugins(:before_databagcreate)
36
+ pre_databag = {}
37
+ databag_create
38
+ post_databag = load_databag(@object_name)
39
+ @object_difference = json_diff(pre_databag,post_databag).to_s
40
+ run_plugins(:after_databagcreate)
41
+ end
42
+
43
+ private
44
+ def databag_create
45
+ dbc = Chef::Knife::DataBagCreate.new
46
+ dbc.name_args = @name_args
47
+ dbc.config[:editor] = config[:editor]
48
+ dbc.config[:secret] = config[:secret]
49
+ dbc.config[:secret_file] = config[:secret_file]
50
+ dbc.run
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,51 @@
1
+ require 'chef/knife'
2
+ require 'knife-spork/runner'
3
+ require 'json'
4
+
5
+ module KnifeSpork
6
+ class SporkDataBagDelete < Chef::Knife
7
+ include KnifeSpork::Runner
8
+
9
+ deps do
10
+ require 'chef/knife/data_bag_delete'
11
+ end
12
+
13
+ banner 'knife data bag delete BAG [ITEM] (options)'
14
+
15
+
16
+ def run
17
+ self.config = Chef::Config.merge!(config)
18
+
19
+ if @name_args.length == 2
20
+ @object_name = @name_args.first
21
+ @object_secondary_name = @name_args.last
22
+ run_plugins(:before_databagitemdelete)
23
+ pre_databag = load_databag_item(@object_name,@object_secondary_name)
24
+ databag_delete
25
+ post_databag = {}
26
+ @object_difference = json_diff(pre_databag,post_databag).to_s
27
+ run_plugins(:after_databagitemdelete)
28
+ elsif @name_args.length == 1
29
+ @object_name = @name_args.first
30
+ run_plugins(:before_databagdelete)
31
+ pre_databag = load_databag(@object_name)
32
+ databag_delete
33
+ post_databag = {}
34
+ @object_difference = json_diff(pre_databag,post_databag).to_s
35
+ run_plugins(:after_databagdelete)
36
+ else
37
+ show_usage
38
+ ui.fatal("You must specify at least a data bag name")
39
+ exit 1
40
+ end
41
+ end
42
+
43
+ private
44
+ def databag_delete
45
+ dbd = Chef::Knife::DataBagDelete.new
46
+ dbd.name_args = @name_args
47
+ dbd.config[:editor] = config[:editor]
48
+ dbd.run
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,54 @@
1
+ require 'chef/knife'
2
+ require 'knife-spork/runner'
3
+ require 'json'
4
+
5
+ module KnifeSpork
6
+ class SporkDataBagEdit < Chef::Knife
7
+ include KnifeSpork::Runner
8
+
9
+ deps do
10
+ require 'chef/knife/data_bag_edit'
11
+ end
12
+
13
+ banner 'knife spork data bag edit BAG ITEM (options)'
14
+
15
+ option :secret,
16
+ :short => "-s SECRET",
17
+ :long => "--secret ",
18
+ :description => "The secret key to use to encrypt data bag item values"
19
+
20
+ option :secret_file,
21
+ :long => "--secret-file SECRET_FILE",
22
+ :description => "A file containing the secret key to use to encrypt data bag item values"
23
+
24
+ def run
25
+ self.config = Chef::Config.merge!(config)
26
+
27
+ if @name_args.length != 2
28
+ ui.error "You must supply the data bag and an item to edit!"
29
+ ui.error opt_parser
30
+ exit 1
31
+ end
32
+
33
+ @object_name = @name_args.first
34
+ @object_secondary_name = @name_args.last
35
+
36
+ run_plugins(:before_databagedit)
37
+ pre_databag = load_databag_item(@object_name, @object_secondary_name)
38
+ databag_edit
39
+ post_databag = load_databag_item(@object_name, @object_secondary_name)
40
+ @object_difference = json_diff(pre_databag,post_databag).to_s
41
+ run_plugins(:after_databagedit)
42
+ end
43
+
44
+ private
45
+ def databag_edit
46
+ dbe = Chef::Knife::DataBagEdit.new
47
+ dbe.name_args = @name_args
48
+ dbe.config[:editor] = config[:editor]
49
+ dbe.config[:secret] = config[:secret]
50
+ dbe.config[:secret_file] = config[:secret_file]
51
+ dbe.run
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,82 @@
1
+ require 'chef/knife'
2
+ require 'knife-spork/runner'
3
+ require 'json'
4
+
5
+ module KnifeSpork
6
+ class SporkDataBagFromFile < Chef::Knife
7
+ include KnifeSpork::Runner
8
+
9
+ deps do
10
+ require 'chef/knife/data_bag_from_file'
11
+ end
12
+
13
+ banner 'knife data bag from file BAG FILE|FOLDER [FILE|FOLDER..] (options)'
14
+
15
+ option :secret,
16
+ :short => "-s SECRET",
17
+ :long => "--secret ",
18
+ :description => "The secret key to use to encrypt data bag item values"
19
+
20
+ option :secret_file,
21
+ :long => "--secret-file SECRET_FILE",
22
+ :description => "A file containing the secret key to use to encrypt data bag item values"
23
+
24
+ option :all,
25
+ :short => "-a",
26
+ :long => "--all",
27
+ :description => "Upload all data bags"
28
+
29
+ def run
30
+ self.config = Chef::Config.merge!(config)
31
+
32
+ @object_name = @name_args.first
33
+
34
+ if config[:all] == true
35
+ test = Chef::Knife::DataBagFromFile.new
36
+ test.config[:verbosity] = 3
37
+ databags = test.send(:find_all_data_bags)
38
+ databags.each do |bag|
39
+ test.send(:find_all_data_bag_items,bag).each do |item|
40
+ @object_name = bag
41
+ @object_secondary_name = item.split("/").last
42
+ run_plugins(:before_databagfromfile)
43
+ begin
44
+ pre_databag = load_databag_item(@object_name, @object_secondary_name.gsub(".json",""))
45
+ rescue
46
+ pre_databag = {}
47
+ end
48
+ databag_from_file([@object_name,@object_secondary_name])
49
+ post_databag = load_databag_item(@object_name, @object_secondary_name.gsub(".json",""))
50
+ @object_difference = json_diff(pre_databag,post_databag).to_s
51
+ run_plugins(:after_databagfromfile)
52
+ end
53
+ end
54
+
55
+ else
56
+ @name_args[1..-1].each do |arg|
57
+ @object_secondary_name = arg
58
+ run_plugins(:before_databagfromfile)
59
+ begin
60
+ pre_databag = load_databag_item(@object_name, @object_secondary_name.gsub(".json",""))
61
+ rescue
62
+ pre_databag = {}
63
+ end
64
+ databag_from_file
65
+ post_databag = load_databag_item(@object_name, @object_secondary_name.gsub(".json",""))
66
+ @object_difference = json_diff(pre_databag,post_databag).to_s
67
+ run_plugins(:after_databagfromfile)
68
+ end
69
+ end
70
+ end
71
+
72
+ private
73
+ def databag_from_file(data_bag_names=nil)
74
+ dbff = Chef::Knife::DataBagFromFile.new
75
+ dbff.name_args = data_bag_names || @name_args
76
+ dbff.config[:editor] = config[:editor]
77
+ dbff.config[:secret] = config[:secret]
78
+ dbff.config[:secret_file] = config[:secret_file]
79
+ dbff.run
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,38 @@
1
+ require 'chef/knife'
2
+ require 'knife-spork/runner'
3
+
4
+ module KnifeSpork
5
+ class SporkNodeCreate < Chef::Knife
6
+ include KnifeSpork::Runner
7
+
8
+ banner 'knife spork node create NODE (options)'
9
+
10
+
11
+ def run
12
+ self.config = Chef::Config.merge!(config)
13
+
14
+ if @name_args.empty?
15
+ show_usage
16
+ ui.error("You must specify a node name")
17
+ exit 1
18
+ end
19
+
20
+ @object_name = @name_args.first
21
+
22
+ run_plugins(:before_nodecreate)
23
+ pre_node = {}
24
+ node_create
25
+ post_node = load_node(@object_name)
26
+ @object_difference = json_diff(pre_node,post_node).to_s
27
+ run_plugins(:after_nodecreate)
28
+ end
29
+
30
+ private
31
+ def node_create
32
+ ne = Chef::Knife::NodeCreate.new
33
+ ne.name_args = @name_args
34
+ ne.config[:editor] = config[:editor]
35
+ ne.run
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ require 'chef/knife'
2
+ require 'knife-spork/runner'
3
+
4
+ module KnifeSpork
5
+ class SporkNodeDelete < Chef::Knife
6
+ include KnifeSpork::Runner
7
+
8
+ banner 'knife spork node delete NODE (options)'
9
+
10
+
11
+ def run
12
+ self.config = Chef::Config.merge!(config)
13
+
14
+ if @name_args.empty?
15
+ show_usage
16
+ ui.error("You must specify a node name")
17
+ exit 1
18
+ end
19
+
20
+ @object_name = @name_args.first
21
+
22
+ run_plugins(:before_nodedelete)
23
+ pre_node = load_node(@object_name)
24
+ node_delete
25
+ post_node = {}
26
+ @object_difference = json_diff(pre_node,post_node).to_s
27
+ run_plugins(:after_nodedelete)
28
+ end
29
+
30
+ private
31
+ def node_delete
32
+ ne = Chef::Knife::NodeDelete.new
33
+ ne.name_args = @name_args
34
+ ne.config[:editor] = config[:editor]
35
+ ne.run
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,45 @@
1
+ require 'chef/knife'
2
+ require 'chef/knife/core/node_editor'
3
+ require 'knife-spork/runner'
4
+
5
+ module KnifeSpork
6
+ class SporkNodeEdit < Chef::Knife
7
+ include KnifeSpork::Runner
8
+
9
+ banner 'knife spork node edit NODE (options)'
10
+
11
+ option :all_attributes,
12
+ :short => "-a",
13
+ :long => "--all",
14
+ :boolean => true,
15
+ :description => "Display all attributes when editing"
16
+
17
+ def run
18
+ self.config = Chef::Config.merge!(config)
19
+
20
+ if @name_args.empty?
21
+ show_usage
22
+ ui.error("You must specify a node name")
23
+ exit 1
24
+ end
25
+
26
+ @object_name = @name_args.first
27
+
28
+ run_plugins(:before_nodeedit)
29
+ pre_node = load_node(@object_name)
30
+ node_edit
31
+ post_node = load_node(@object_name)
32
+ @object_difference = json_diff(pre_node,post_node).to_s
33
+ run_plugins(:after_nodeedit)
34
+ end
35
+
36
+ private
37
+ def node_edit
38
+ ne = Chef::Knife::NodeEdit.new
39
+ ne.name_args = @name_args
40
+ ne.config[:editor] = config[:editor]
41
+ ne.config[:all] = config[:all]
42
+ ne.run
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,43 @@
1
+ require 'chef/knife'
2
+ require 'knife-spork/runner'
3
+
4
+ module KnifeSpork
5
+ class SporkNodeFromFile < Chef::Knife
6
+ include KnifeSpork::Runner
7
+
8
+ banner 'knife spork node from file FILE (options)'
9
+
10
+
11
+ def run
12
+ self.config = Chef::Config.merge!(config)
13
+
14
+ if @name_args.empty?
15
+ show_usage
16
+ ui.error("You must specify a filename")
17
+ exit 1
18
+ end
19
+
20
+ @object_name = JSON.parse(File.read(@name_args.first))["name"]
21
+ ui.info @object_name
22
+
23
+ run_plugins(:before_nodefromfile)
24
+ begin
25
+ pre_node = load_node(@object_name.gsub(".json",""))
26
+ rescue
27
+ pre_node = {}
28
+ end
29
+ node_fromfile
30
+ post_node = load_node(@object_name.gsub(".json",""))
31
+ @object_difference = json_diff(pre_node,post_node).to_s
32
+ run_plugins(:after_nodefromfile)
33
+ end
34
+
35
+ private
36
+ def node_fromfile
37
+ nff = Chef::Knife::NodeFromFile.new
38
+ nff.name_args = @name_args
39
+ nff.config[:editor] = config[:editor]
40
+ nff.run
41
+ end
42
+ end
43
+ end