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
@@ -0,0 +1,48 @@
1
+ require 'chef/knife'
2
+ require 'knife-spork/runner'
3
+
4
+ module KnifeSpork
5
+ class SporkNodeRunListAdd < Chef::Knife
6
+ include KnifeSpork::Runner
7
+
8
+ banner 'knife spork node run_list add [NODE] [ENTRY[,ENTRY]] (options)'
9
+
10
+
11
+ option :after,
12
+ :short => "-a ITEM",
13
+ :long => "--after ITEM",
14
+ :description => "Place the ENTRY in the run list after ITEM"
15
+
16
+ def run
17
+ self.config = Chef::Config.merge!(config)
18
+
19
+ if @name_args.empty?
20
+ show_usage
21
+ ui.error("You must specify a node name and item to add")
22
+ exit 1
23
+ end
24
+
25
+ @object_name = @name_args.first
26
+
27
+ @object_secondary_name = @name_args[1..-1].map do |entry|
28
+ entry.split(',').map { |e| e.strip }
29
+ end.flatten.to_s
30
+
31
+ run_plugins(:before_noderunlistadd)
32
+ pre_node = load_node(@object_name)
33
+ node_runlistadd
34
+ post_node = load_node(@object_name)
35
+ @object_difference = json_diff(pre_node,post_node).to_s
36
+ run_plugins(:after_noderunlistadd)
37
+ end
38
+
39
+ private
40
+ def node_runlistadd
41
+ nrla = Chef::Knife::NodeRunListAdd.new
42
+ nrla.name_args = @name_args
43
+ nrla.config[:editor] = config[:editor]
44
+ nrla.config[:after] = config[:after]
45
+ nrla.run
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,42 @@
1
+ require 'chef/knife'
2
+ require 'knife-spork/runner'
3
+
4
+ module KnifeSpork
5
+ class SporkNodeRunListRemove < Chef::Knife
6
+ include KnifeSpork::Runner
7
+
8
+ banner 'knife spork node run_list add [NODE] [ENTRY[,ENTRY]] (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 and item to remove")
17
+ exit 1
18
+ end
19
+
20
+ @object_name = @name_args.first
21
+
22
+ @object_secondary_name = @name_args[1..-1].map do |entry|
23
+ entry.split(',').map { |e| e.strip }
24
+ end.flatten.to_s
25
+
26
+ run_plugins(:before_noderunlistremove)
27
+ pre_node = load_node(@object_name)
28
+ node_runlistremove
29
+ post_node = load_node(@object_name)
30
+ @object_difference = json_diff(pre_node,post_node).to_s
31
+ run_plugins(:after_noderunlistremove)
32
+ end
33
+
34
+ private
35
+ def node_runlistremove
36
+ nrla = Chef::Knife::NodeRunListRemove.new
37
+ nrla.name_args = @name_args
38
+ nrla.config[:editor] = config[:editor]
39
+ nrla.run
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,42 @@
1
+ require 'chef/knife'
2
+ require 'knife-spork/runner'
3
+
4
+ module KnifeSpork
5
+ class SporkNodeRunListSet < Chef::Knife
6
+ include KnifeSpork::Runner
7
+
8
+ banner 'knife spork node run_list set NODE ENTRIES (options)'
9
+
10
+
11
+ def run
12
+ self.config = Chef::Config.merge!(config)
13
+
14
+ if @name_args.size < 2
15
+ ui.error "You must supply both a node name and a run list."
16
+ show_usage
17
+ exit 1
18
+ end
19
+
20
+ @object_name = @name_args.first
21
+
22
+ @object_secondary_name = @name_args[1..-1].map do |entry|
23
+ entry.split(',').map { |e| e.strip }
24
+ end.flatten.to_s
25
+
26
+ run_plugins(:before_noderunlistset)
27
+ pre_node = load_node(@object_name)
28
+ node_runlistset
29
+ post_node = load_node(@object_name)
30
+ @object_difference = json_diff(pre_node,post_node).to_s
31
+ run_plugins(:after_noderunlistset)
32
+ end
33
+
34
+ private
35
+ def node_runlistset
36
+ nrla = Chef::Knife::NodeRunListSet.new
37
+ nrla.name_args = @name_args
38
+ nrla.config[:editor] = config[:editor]
39
+ nrla.run
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,107 @@
1
+ require 'chef/knife'
2
+ require 'knife-spork/runner'
3
+
4
+ begin
5
+ require 'berkshelf'
6
+ rescue LoadError; end
7
+
8
+ module KnifeSpork
9
+ class SporkOmni < Chef::Knife
10
+ include KnifeSpork::Runner
11
+
12
+ banner 'knife spork omni COOKBOOK (options)'
13
+
14
+ option :cookbook_path,
15
+ :short => '-o PATH:PATH',
16
+ :long => '--cookbook-path PATH:PATH',
17
+ :description => 'A colon-separated path to look for cookbooks in',
18
+ :proc => lambda { |o| o.split(':') }
19
+
20
+ option :depends,
21
+ :short => '-D',
22
+ :long => '--include-dependencies',
23
+ :description => 'Also upload cookbook dependencies during the upload step'
24
+
25
+ option :bump_level,
26
+ :short => '-l',
27
+ :long => '--bump-level [major|minor|patch]',
28
+ :description => 'Version level to bump the cookbook (defaults to patch)',
29
+ :default => nil
30
+
31
+ option :omni_environment,
32
+ :short => '-e',
33
+ :long => '--environment ENVIRONMENT',
34
+ :description => 'Environment to promote the cookbook to',
35
+ :default => nil
36
+
37
+ option :remote,
38
+ :long => '--remote',
39
+ :description => 'Make omni finish with promote --remote instead of a local promote',
40
+ :default => nil
41
+
42
+ if defined?(::Berkshelf)
43
+ option :berksfile,
44
+ :short => '-b',
45
+ :long => '--berksfile BERKSFILE',
46
+ :description => 'Path to a Berksfile to operate from',
47
+ :default => File.join(Dir.pwd, ::Berkshelf::DEFAULT_FILENAME)
48
+ end
49
+
50
+ def run
51
+ self.config = Chef::Config.merge!(config)
52
+
53
+ if name_args.empty?
54
+ ui.fatal 'You must specify a cookbook name!'
55
+ show_usage
56
+ exit(1)
57
+ end
58
+
59
+ cookbook = name_args.first
60
+
61
+ run_plugins(:before_omni)
62
+ omni(cookbook)
63
+ run_plugins(:after_omni)
64
+ end
65
+
66
+ private
67
+
68
+ def bump(cookbook)
69
+ ui.msg "OMNI: Bumping #{cookbook}"
70
+ bump = SporkBump.new
71
+ bump.name_args = [cookbook,config[:bump_level]]
72
+ bump.run
73
+ end
74
+
75
+ def upload(cookbook)
76
+ ui.msg "OMNI: Uploading #{cookbook}"
77
+ upload = SporkUpload.new
78
+ upload.name_args = [cookbook]
79
+ upload.config[:cookbook_path] = config[:cookbook_path]
80
+ upload.config[:depends] = config[:depends]
81
+ upload.run
82
+ end
83
+
84
+ def promote(cookbook)
85
+ ui.msg "OMNI: Promoting #{cookbook}"
86
+ promote = SporkPromote.new
87
+ if config[:omni_environment]
88
+ promote.name_args = [config[:omni_environment],cookbook]
89
+ else
90
+ promote.name_args = [cookbook]
91
+ end
92
+ promote.config[:remote] = config[:remote]
93
+ if defined?(::Berkshelf)
94
+ promote.config[:berksfile] = config[:berksfile]
95
+ end
96
+ promote.run
97
+ end
98
+
99
+ def omni(cookbook)
100
+ bump(cookbook)
101
+ ui.msg ""
102
+ upload(cookbook)
103
+ ui.msg ""
104
+ promote(cookbook)
105
+ end
106
+ end
107
+ end
@@ -53,12 +53,8 @@ module KnifeSpork
53
53
  @environments.each do |e|
54
54
  environment = load_environment(e)
55
55
 
56
- if @cookbook == 'all'
57
- ui.msg "Promoting ALL cookbooks to environment #{environment}"
58
- promote(environment, all_cookbooks)
59
- else
60
- promote(environment, @cookbook)
61
- end
56
+
57
+ promote(environment, @cookbook)
62
58
 
63
59
  ui.msg "Saving changes to #{e}.json"
64
60
 
@@ -0,0 +1,43 @@
1
+ require 'chef/knife'
2
+ require 'knife-spork/runner'
3
+
4
+ module KnifeSpork
5
+ class SporkRoleCreate < Chef::Knife
6
+ include KnifeSpork::Runner
7
+
8
+ banner 'knife spork role create ROLE (options)'
9
+
10
+ option :description,
11
+ :short => "-d DESC",
12
+ :long => "--description DESC",
13
+ :description => "The role description"
14
+
15
+ def run
16
+ self.config = Chef::Config.merge!(config)
17
+
18
+ if @name_args.empty?
19
+ show_usage
20
+ ui.error("You must specify a role name")
21
+ exit 1
22
+ end
23
+
24
+ @object_name = @name_args.first
25
+
26
+ run_plugins(:before_rolecreate)
27
+ pre_role = {}
28
+ role_create
29
+ post_role = load_role(@object_name)
30
+ @object_difference = json_diff(pre_role,post_role).to_s
31
+ run_plugins(:after_rolecreate)
32
+ end
33
+
34
+ private
35
+ def role_create
36
+ rc = Chef::Knife::RoleCreate.new
37
+ rc.name_args = @name_args
38
+ rc.config[:editor] = config[:editor]
39
+ rc.config[:description] = config[:description]
40
+ rc.run
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,36 @@
1
+ require 'chef/knife'
2
+ require 'knife-spork/runner'
3
+
4
+ module KnifeSpork
5
+ class SporkRoleDelete < Chef::Knife
6
+ include KnifeSpork::Runner
7
+
8
+ banner 'knife spork role delete ROLENAME'
9
+
10
+ def run
11
+ self.config = Chef::Config.merge!(config)
12
+
13
+ if @name_args.empty?
14
+ show_usage
15
+ ui.error("You must specify a role name")
16
+ exit 1
17
+ end
18
+
19
+ @object_name = @name_args.first
20
+
21
+ run_plugins(:before_roledelete)
22
+ pre_role = load_role(@object_name)
23
+ role_delete
24
+ post_role = {}
25
+ @object_difference = json_diff(pre_role,post_role).to_s
26
+ run_plugins(:after_roledelete)
27
+ end
28
+
29
+ private
30
+ def role_delete
31
+ rd = Chef::Knife::RoleDelete.new
32
+ rd.name_args = @name_args
33
+ rd.run
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ require 'chef/knife'
2
+ require 'knife-spork/runner'
3
+
4
+ module KnifeSpork
5
+ class SporkRoleEdit < Chef::Knife
6
+ include KnifeSpork::Runner
7
+
8
+ banner 'knife spork role edit ROLENAME'
9
+
10
+ def run
11
+ self.config = Chef::Config.merge!(config)
12
+
13
+ if @name_args.empty?
14
+ show_usage
15
+ ui.error("You must specify a role name")
16
+ exit 1
17
+ end
18
+
19
+ @object_name = @name_args.first
20
+
21
+ run_plugins(:before_roleedit)
22
+ pre_role = load_role(@object_name)
23
+ role_edit
24
+ post_role = load_role(@object_name)
25
+ @object_difference = json_diff(pre_role,post_role).to_s
26
+ run_plugins(:after_roleedit)
27
+ end
28
+
29
+ private
30
+ def role_edit
31
+ re = Chef::Knife::RoleEdit.new
32
+ re.name_args = @name_args
33
+ re.config[:editor] = config[:editor]
34
+ re.run
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,42 @@
1
+ require 'chef/knife'
2
+ require 'knife-spork/runner'
3
+ require 'json'
4
+
5
+ module KnifeSpork
6
+ class SporkRoleFromFile < Chef::Knife
7
+ include KnifeSpork::Runner
8
+
9
+ deps do
10
+ require 'chef/knife/role_from_file'
11
+ end
12
+
13
+ banner 'knife spork role from file FILENAME'
14
+
15
+ def run
16
+ self.config = Chef::Config.merge!(config)
17
+
18
+ if @name_args.empty?
19
+ show_usage
20
+ ui.error("You must specify a role name")
21
+ exit 1
22
+ end
23
+
24
+ @name_args.each do |arg|
25
+ @object_name = arg.split("/").last
26
+ run_plugins(:before_rolefromfile)
27
+ pre_role = load_role(@object_name.gsub(".json","").gsub(".rb",""))
28
+ role_from_file
29
+ post_role = load_role(@object_name.gsub(".json","").gsub(".rb",""))
30
+ @object_difference = json_diff(pre_role,post_role).to_s
31
+ run_plugins(:after_rolefromfile)
32
+ end
33
+ end
34
+
35
+ private
36
+ def role_from_file
37
+ rff = Chef::Knife::RoleFromFile.new
38
+ rff.name_args = @name_args
39
+ rff.run
40
+ end
41
+ end
42
+ end
@@ -30,6 +30,134 @@ EOH
30
30
  end
31
31
  end
32
32
 
33
+ def after_rolefromfile
34
+ campfire do |rooms|
35
+ rooms.paste <<-EOH
36
+ #{organization}#{current_user} uploaded role #{object_name}
37
+ EOH
38
+ end
39
+ end
40
+
41
+ def after_roleedit
42
+ campfire do |rooms|
43
+ rooms.paste <<-EOH
44
+ #{organization}#{current_user} edited role #{object_name}
45
+ EOH
46
+ end
47
+ end
48
+
49
+ def after_rolecreate
50
+ campfire do |rooms|
51
+ rooms.paste <<-EOH
52
+ #{organization}#{current_user} created role #{object_name}
53
+ EOH
54
+ end
55
+ end
56
+
57
+ def after_roledelete
58
+ campfire do |rooms|
59
+ rooms.paste <<-EOH
60
+ #{organization}#{current_user} deleted role #{object_name}
61
+ EOH
62
+ end
63
+ end
64
+
65
+ def after_databagedit
66
+ campfire do |rooms|
67
+ rooms.paste <<-EOH
68
+ #{organization}#{current_user} edited data bag item #{object_name}:#{object_secondary_name}
69
+ EOH
70
+ end
71
+ end
72
+
73
+ def after_databagdelete
74
+ campfire do |rooms|
75
+ rooms.paste <<-EOH
76
+ #{organization}#{current_user} deleted data bag #{object_name}}
77
+ EOH
78
+ end
79
+ end
80
+
81
+ def after_databagitemdelete
82
+ campfire do |rooms|
83
+ rooms.paste <<-EOH
84
+ #{organization}#{current_user} deleted data bag item #{object_name}:#{object_secondary_name}
85
+ EOH
86
+ end
87
+ end
88
+
89
+ def after_databagcreate
90
+ campfire do |rooms|
91
+ rooms.paste <<-EOH
92
+ #{organization}#{current_user} created data bag #{object_name}
93
+ EOH
94
+ end
95
+ end
96
+
97
+ def after_databagfromfile
98
+ campfire do |rooms|
99
+ rooms.paste <<-EOH
100
+ #{organization}#{current_user} uploaded data bag item #{object_name}:#{object_secondary_name}
101
+ EOH
102
+ end
103
+ end
104
+
105
+ def after_nodeedit
106
+ campfire do |rooms|
107
+ rooms.paste <<-EOH
108
+ #{organization}#{current_user} edited node #{object_name}
109
+ EOH
110
+ end
111
+ end
112
+
113
+ def after_nodedelete
114
+ campfire do |rooms|
115
+ rooms.paste <<-EOH
116
+ #{organization}#{current_user} deleted node #{object_name}
117
+ EOH
118
+ end
119
+ end
120
+
121
+ def after_nodecreate
122
+ campfire do |rooms|
123
+ rooms.paste <<-EOH
124
+ #{organization}#{current_user} created node #{object_name}
125
+ EOH
126
+ end
127
+ end
128
+
129
+ def after_nodefromfile
130
+ campfire do |rooms|
131
+ rooms.paste <<-EOH
132
+ #{organization}#{current_user} uploaded node #{object_name}
133
+ EOH
134
+ end
135
+ end
136
+
137
+ def after_noderunlistadd
138
+ campfire do |rooms|
139
+ rooms.paste <<-EOH
140
+ #{organization}#{current_user} added run_list items to #{object_name}: #{object_secondary_name}
141
+ EOH
142
+ end
143
+ end
144
+
145
+ def after_noderunlistremove
146
+ campfire do |rooms|
147
+ rooms.paste <<-EOH
148
+ #{organization}#{current_user} removed run_list items from #{object_name}: #{object_secondary_name}
149
+ EOH
150
+ end
151
+ end
152
+
153
+ def after_noderunlistset
154
+ campfire do |rooms|
155
+ rooms.paste <<-EOH
156
+ #{organization}#{current_user} set the run_list for #{object_name} to #{object_secondary_name}
157
+ EOH
158
+ end
159
+ end
160
+
33
161
  private
34
162
  def campfire(&block)
35
163
  safe_require 'campy'