spiceweasel 2.6.0 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +6 -14
  2. data/README.md +33 -9
  3. data/bin/spiceweasel +3 -3
  4. data/lib/spiceweasel.rb +3 -2
  5. data/lib/spiceweasel/berksfile.rb +6 -10
  6. data/lib/spiceweasel/cli.rb +174 -129
  7. data/lib/spiceweasel/clusters.rb +31 -23
  8. data/lib/spiceweasel/command.rb +23 -5
  9. data/lib/spiceweasel/command_helper.rb +36 -2
  10. data/lib/spiceweasel/config.rb +4 -3
  11. data/lib/spiceweasel/cookbooks.rb +76 -57
  12. data/lib/spiceweasel/data_bags.rb +100 -64
  13. data/lib/spiceweasel/environments.rb +78 -56
  14. data/lib/spiceweasel/execute.rb +6 -7
  15. data/lib/spiceweasel/extract_local.rb +59 -46
  16. data/lib/spiceweasel/knife.rb +21 -20
  17. data/lib/spiceweasel/log.rb +5 -5
  18. data/lib/spiceweasel/nodes.rb +261 -193
  19. data/lib/spiceweasel/roles.rb +107 -76
  20. data/lib/spiceweasel/version.rb +5 -3
  21. data/test/chef-repo/Berksfile +4 -0
  22. data/test/chef-repo/Berksfile.lock +10 -0
  23. data/test/chef-repo/PASSWORD +1 -0
  24. data/test/chef-repo/cookbooks/abc/CHANGELOG.md +13 -0
  25. data/test/chef-repo/cookbooks/abc/README.md +68 -0
  26. data/test/chef-repo/cookbooks/abc/metadata.rb +7 -0
  27. data/test/chef-repo/cookbooks/abc/recipes/default.rb +8 -0
  28. data/test/chef-repo/cookbooks/def/CHANGELOG.md +13 -0
  29. data/test/chef-repo/cookbooks/def/README.md +68 -0
  30. data/test/chef-repo/cookbooks/def/metadata.rb +7 -0
  31. data/test/chef-repo/cookbooks/def/recipes/default.rb +8 -0
  32. data/test/chef-repo/cookbooks/fail1/README.md +68 -0
  33. data/test/chef-repo/cookbooks/fail1/metadata.rb +9 -0
  34. data/test/chef-repo/cookbooks/fail2/README.md +68 -0
  35. data/test/chef-repo/cookbooks/fail2/metadata.rb +9 -0
  36. data/test/chef-repo/cookbooks/fail3/README.md +68 -0
  37. data/test/chef-repo/cookbooks/fail3/metadata.rb +9 -0
  38. data/test/chef-repo/cookbooks/ghi/CHANGELOG.md +13 -0
  39. data/test/chef-repo/cookbooks/ghi/README.md +68 -0
  40. data/test/chef-repo/cookbooks/ghi/metadata.rb +7 -0
  41. data/test/chef-repo/cookbooks/ghi/recipes/default.rb +8 -0
  42. data/test/chef-repo/cookbooks/jkl/CHANGELOG.md +13 -0
  43. data/test/chef-repo/cookbooks/jkl/README.md +68 -0
  44. data/test/chef-repo/cookbooks/jkl/metadata.rb +10 -0
  45. data/test/chef-repo/cookbooks/jkl/recipes/default.rb +8 -0
  46. data/test/chef-repo/cookbooks/mno/CHANGELOG.md +13 -0
  47. data/test/chef-repo/cookbooks/mno/README.md +68 -0
  48. data/test/chef-repo/cookbooks/mno/metadata.rb +9 -0
  49. data/test/chef-repo/cookbooks/mno/recipes/default.rb +8 -0
  50. data/test/chef-repo/data_bags/junk/README +1 -0
  51. data/test/chef-repo/data_bags/junk/abc.json +4 -0
  52. data/test/chef-repo/data_bags/junk/ade.json +4 -0
  53. data/test/chef-repo/data_bags/junk/afg.json +4 -0
  54. data/test/chef-repo/data_bags/junk/bcd.json +4 -0
  55. data/test/chef-repo/data_bags/junk/sub1/cde1.json +4 -0
  56. data/test/chef-repo/data_bags/junk/sub1/cde2.json +4 -0
  57. data/test/chef-repo/data_bags/junk/sub2/def1.json +4 -0
  58. data/test/chef-repo/data_bags/junk/sub2/def2.json +4 -0
  59. data/test/chef-repo/data_bags/users/README +1 -0
  60. data/test/chef-repo/data_bags/users/badjson.json +8 -0
  61. data/test/chef-repo/data_bags/users/failname.json +8 -0
  62. data/test/chef-repo/data_bags/users/mray.json +8 -0
  63. data/test/chef-repo/data_bags/users/ubuntu.json +8 -0
  64. data/test/chef-repo/environments/development.rb +2 -0
  65. data/test/chef-repo/environments/fail2.rb +8 -0
  66. data/test/chef-repo/environments/fail3.rb +2 -0
  67. data/test/chef-repo/environments/production-blue.json +177 -0
  68. data/test/chef-repo/environments/production-green.json +177 -0
  69. data/test/chef-repo/environments/production-red.json +177 -0
  70. data/test/chef-repo/environments/qa.rb +2 -0
  71. data/test/chef-repo/environments/sub/efg1.rb +2 -0
  72. data/test/chef-repo/environments/sub/efg2.json +177 -0
  73. data/test/chef-repo/fail-cookbook1.yml +19 -0
  74. data/test/chef-repo/fail-cookbook2.yml +21 -0
  75. data/test/chef-repo/fail-cookbook3.yml +37 -0
  76. data/test/chef-repo/fail-cookbook4.yml +37 -0
  77. data/test/chef-repo/fail-cookbook5.yml +10 -0
  78. data/test/chef-repo/fail-cookbook6.yml +9 -0
  79. data/test/chef-repo/fail-db1.yml +12 -0
  80. data/test/chef-repo/fail-db2.yml +10 -0
  81. data/test/chef-repo/fail-db3.yml +10 -0
  82. data/test/chef-repo/fail-db4.yml +10 -0
  83. data/test/chef-repo/fail-env1.yml +27 -0
  84. data/test/chef-repo/fail-env2.yml +27 -0
  85. data/test/chef-repo/fail-env3.yml +28 -0
  86. data/test/chef-repo/fail-env4.yml +28 -0
  87. data/test/chef-repo/fail-roles1.yml +22 -0
  88. data/test/chef-repo/fail-roles2.yml +21 -0
  89. data/test/chef-repo/fail-roles3.yml +23 -0
  90. data/test/chef-repo/fail-roles4.yml +23 -0
  91. data/test/chef-repo/fail-roles5.yml +23 -0
  92. data/test/chef-repo/infrastructure.yml +43 -0
  93. data/test/chef-repo/nodes/boxy.lab.atx.json +1756 -0
  94. data/test/chef-repo/nodes/guenter.home.atx.json +2503 -0
  95. data/test/chef-repo/roles/README +1 -0
  96. data/test/chef-repo/roles/base.rb +18 -0
  97. data/test/chef-repo/roles/base2.rb +16 -0
  98. data/test/chef-repo/roles/base3.rb +17 -0
  99. data/test/chef-repo/roles/base4.rb +15 -0
  100. data/test/chef-repo/roles/fail1.rb +8 -0
  101. data/test/chef-repo/roles/fail2.rb +5 -0
  102. data/test/chef-repo/roles/fail3.rb +5 -0
  103. data/test/chef-repo/roles/sub/bw2.json +21 -0
  104. data/test/chef-repo/roles/sub/bwi1.json +20 -0
  105. data/test/chef-repo/roles/tc.rb +13 -0
  106. data/test/examples/cluster-file-example.yml +14 -0
  107. data/test/examples/example-cluster.yml +8 -0
  108. data/test/examples/example.json +127 -0
  109. data/test/examples/example.rb +128 -0
  110. data/test/examples/example.yml +67 -0
  111. data/test/examples/google-example.yml +33 -0
  112. data/test/examples/joyent-vsphere-example.yml +15 -0
  113. data/test/examples/knife.yml +7 -0
  114. data/test/examples/kvm-example.yml +22 -0
  115. data/test/examples/node-example.yml +23 -0
  116. data/test/examples/php-quick-start.yml +83 -0
  117. data/test/extract-repo/Berksfile +4 -0
  118. data/test/extract-repo/Berksfile.lock +10 -0
  119. data/test/extract-repo/cookbooks/abc/CHANGELOG.md +13 -0
  120. data/test/extract-repo/cookbooks/abc/README.md +68 -0
  121. data/test/extract-repo/cookbooks/abc/metadata.rb +7 -0
  122. data/test/extract-repo/cookbooks/abc/recipes/default.rb +8 -0
  123. data/test/extract-repo/cookbooks/def/CHANGELOG.md +13 -0
  124. data/test/extract-repo/cookbooks/def/README.md +68 -0
  125. data/test/extract-repo/cookbooks/def/metadata.rb +7 -0
  126. data/test/extract-repo/cookbooks/def/recipes/default.rb +8 -0
  127. data/test/extract-repo/cookbooks/ghi/CHANGELOG.md +13 -0
  128. data/test/extract-repo/cookbooks/ghi/README.md +68 -0
  129. data/test/extract-repo/cookbooks/ghi/metadata.rb +7 -0
  130. data/test/extract-repo/cookbooks/ghi/recipes/default.rb +8 -0
  131. data/test/extract-repo/cookbooks/jkl/CHANGELOG.md +13 -0
  132. data/test/extract-repo/cookbooks/jkl/README.md +68 -0
  133. data/test/extract-repo/cookbooks/jkl/metadata.rb +10 -0
  134. data/test/extract-repo/cookbooks/jkl/recipes/default.rb +8 -0
  135. data/test/extract-repo/cookbooks/mno/CHANGELOG.md +13 -0
  136. data/test/extract-repo/cookbooks/mno/README.md +68 -0
  137. data/test/extract-repo/cookbooks/mno/metadata.rb +9 -0
  138. data/test/extract-repo/cookbooks/mno/recipes/default.rb +8 -0
  139. data/test/extract-repo/data_bags/junk/README +1 -0
  140. data/test/extract-repo/data_bags/junk/abc.json +4 -0
  141. data/test/extract-repo/data_bags/junk/ade.json +4 -0
  142. data/test/extract-repo/data_bags/junk/afg.json +4 -0
  143. data/test/extract-repo/data_bags/junk/bcd.json +4 -0
  144. data/test/extract-repo/data_bags/junk/sub1/cde1.json +4 -0
  145. data/test/extract-repo/data_bags/junk/sub1/cde2.json +4 -0
  146. data/test/extract-repo/data_bags/junk/sub2/def1.json +4 -0
  147. data/test/extract-repo/data_bags/junk/sub2/def2.json +4 -0
  148. data/test/extract-repo/data_bags/users/README +1 -0
  149. data/test/extract-repo/data_bags/users/mray.json +8 -0
  150. data/test/extract-repo/data_bags/users/ubuntu.json +8 -0
  151. data/test/extract-repo/environments/development.rb +2 -0
  152. data/test/extract-repo/environments/production-blue.json +177 -0
  153. data/test/extract-repo/environments/production-green.json +177 -0
  154. data/test/extract-repo/environments/production-red.json +177 -0
  155. data/test/extract-repo/environments/qa.rb +2 -0
  156. data/test/extract-repo/environments/sub/efg1.rb +2 -0
  157. data/test/extract-repo/environments/sub/efg2.json +177 -0
  158. data/test/extract-repo/nodes/boxy.lab.atx.json +1756 -0
  159. data/test/extract-repo/nodes/guenter.home.atx.json +2503 -0
  160. data/test/extract-repo/roles/README +1 -0
  161. data/test/extract-repo/roles/base.rb +18 -0
  162. data/test/extract-repo/roles/base2.rb +16 -0
  163. data/test/extract-repo/roles/base3.rb +17 -0
  164. data/test/extract-repo/roles/base4.rb +16 -0
  165. data/test/extract-repo/roles/sub/bw2.json +21 -0
  166. data/test/extract-repo/roles/sub/bwi1.json +20 -0
  167. data/test/extract-repo/roles/tc.rb +13 -0
  168. data/test/extract-repo2/cookbooks/README.md +1 -0
  169. data/test/extract-repo2/data_bags/README.md +1 -0
  170. data/test/extract-repo2/environments/README.md +1 -0
  171. data/test/extract-repo2/nodes/README.md +1 -0
  172. data/test/extract-repo2/roles/README.md +1 -0
  173. metadata +357 -67
  174. data/spec/bin/chef_client_spec.rb +0 -72
  175. data/spec/bin/google_spec.rb +0 -105
  176. data/spec/bin/joyent-vsphere_spec.rb +0 -25
  177. data/spec/bin/knife_spec.rb +0 -18
  178. data/spec/bin/kvm_spec.rb +0 -29
  179. data/spec/bin/node_spec.rb +0 -108
  180. data/spec/bin/spiceweasel_spec.rb +0 -136
@@ -1,7 +1,8 @@
1
+ # encoding: UTF-8
1
2
  #
2
- # Author:: Matt Ray (<matt@opscode.com>)
3
+ # Author:: Matt Ray (<matt@getchef.com>)
3
4
  #
4
- # Copyright:: 2011-2013, Opscode, Inc <legal@opscode.com>
5
+ # Copyright:: 2011-2014, Chef Software, Inc <legal@getchef.com>
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
7
8
  # you may not use this file except in compliance with the License.
@@ -16,90 +17,111 @@
16
17
  # limitations under the License.
17
18
  #
18
19
 
19
- require 'yajl/json_gem'
20
+ require 'ffi_yajl'
21
+ require 'spiceweasel/command_helper'
20
22
 
21
23
  module Spiceweasel
24
+ # manages parsing of Environments
22
25
  class Environments
23
-
24
26
  include CommandHelper
25
27
 
26
28
  attr_reader :environment_list, :create, :delete
27
29
 
28
- def initialize(environments = [], cookbooks = {})
29
- @create = Array.new
30
- @delete = Array.new
31
- @environment_list = Array.new
32
- if environments
33
- Spiceweasel::Log.debug("environments: #{environments}")
34
- flatenvs = environments.collect {|x| x.keys}.flatten
35
- envfiles = []
36
- flatenvs.each do |env|
37
- Spiceweasel::Log.debug("environment: #{env}")
38
- if File.directory?("environments")
39
- #expand wildcards and push into environments
40
- if env =~ /\*/ #wildcard support
41
- wildenvs = Dir.glob("environments/#{env}")
42
- #remove anything not ending in .json or .rb
43
- wildenvs.delete_if {|x| !x.end_with?(".rb", ".json")}
44
- Spiceweasel::Log.debug("found environments '#{wildenvs}' for wildcard: #{env}")
45
- flatenvs.concat(wildenvs.collect {|x| x[x.rindex('/')+1..x.rindex('.')-1]})
46
- next
47
- end
48
- validate(env, cookbooks) unless Spiceweasel::Config[:novalidation]
49
- elsif !Spiceweasel::Config[:novalidation]
50
- STDERR.puts "'environments' directory not found, unable to validate or load environments"
51
- exit(-1)
52
- end
53
- if File.exists?("environments/#{env}.json")
54
- envfiles.push("#{env}.json")
55
- else #assume no .json means they want .rb and catchall for misssing dir
56
- envfiles.push("#{env}.rb")
30
+ def initialize(environments = [], cookbooks = {}) # rubocop:disable CyclomaticComplexity
31
+ @create = []
32
+ @delete = []
33
+ @environment_list = []
34
+
35
+ return unless environments
36
+
37
+ Spiceweasel::Log.debug("environments: #{environments}")
38
+ envfiles = do_flattened_environments(cookbooks, environments)
39
+ create_command("knife environment#{Spiceweasel::Config[:knife_options]} from file #{envfiles.uniq.sort.join(' ')}")
40
+ end
41
+
42
+ def do_flattened_environments(cookbooks, environments)
43
+ flatenvs = environments.map(&:keys).flatten
44
+ envfiles = []
45
+ flatenvs.each do |env|
46
+ Spiceweasel::Log.debug("environment: #{env}")
47
+ if File.directory?('environments')
48
+ # expand wildcards and push into environments
49
+ if env =~ /\*/ # wildcard support
50
+ wildenvs = Dir.glob("environments/#{env}")
51
+ # remove anything not ending in .json or .rb
52
+ wildenvs.delete_if { |x| !x.end_with?('.rb', '.json') }
53
+ Spiceweasel::Log.debug("found environments '#{wildenvs}' for wildcard: #{env}")
54
+ flatenvs.concat(wildenvs.map { |x| x[x.rindex('/') + 1..x.rindex('.') - 1] })
55
+ next
57
56
  end
58
- delete_command("knife environment#{Spiceweasel::Config[:knife_options]} delete #{env} -y")
59
- @environment_list.push(env)
57
+ validate(env, cookbooks) unless Spiceweasel::Config[:novalidation]
58
+ elsif !Spiceweasel::Config[:novalidation]
59
+ STDERR.puts "'environments' directory not found, unable to validate or load environments"
60
+ exit(-1)
61
+ end
62
+ if File.exist?("environments/#{env}.json")
63
+ envfiles.push("#{env}.json")
64
+ else # assume no .json means they want .rb and catchall for misssing dir
65
+ envfiles.push("#{env}.rb")
60
66
  end
61
- create_command("knife environment#{Spiceweasel::Config[:knife_options]} from file #{envfiles.uniq.sort.join(' ')}")
67
+ delete_command("knife environment#{Spiceweasel::Config[:knife_options]} delete #{env} -y")
68
+ @environment_list.push(env)
62
69
  end
70
+ envfiles
63
71
  end
64
72
 
65
- #validate the content of the environment file
66
- def validate(environment, cookbooks)
67
- file = %W(environments/#{environment}.rb environments/#{environment}.json).detect{|f| File.exists?(f)}
68
- if environment =~ /\// #pull out directories
69
- environment = environment.split('/').last
70
- end
73
+ # validate the content of the environment file
74
+ def validate(environment, cookbooks) # rubocop:disable CyclomaticComplexity
75
+ env = nil
76
+ file = %W(environments/#{environment}.rb environments/#{environment}.json).find { |f| File.exist?(f) }
77
+ environment = environment.split('/').last if environment =~ /\// # pull out directories
71
78
  if file
72
79
  case file
73
80
  when /\.json$/
74
81
  env = Chef::JSONCompat.from_json(IO.read(file))
75
82
  when /\.rb$/
76
- if (Chef::VERSION.split('.')[0].to_i < 11)
77
- env = Chef::Environment.new(false)
78
- else
79
- env = Chef::Environment.new
80
- end
81
- env.from_file(file)
83
+ env = do_ruby_environment_file(file)
82
84
  end
83
- if(env.name != environment)
85
+ if env.name != environment
84
86
  STDERR.puts "ERROR: Environment '#{environment}' listed in the manifest does not match the name '#{env.name}' within the #{file} file."
85
87
  exit(-1)
86
88
  end
87
89
  env.cookbook_versions.keys.each do |dep|
88
- Spiceweasel::Log.debug("environment: '#{environment}' cookbook: '#{dep}'")
89
- unless cookbooks.member?(dep)
90
- STDERR.puts "ERROR: Cookbook dependency '#{dep}' from environment '#{environment}' is missing from the list of cookbooks in the manifest."
91
- exit(-1)
92
- end
90
+ do_cookbook_version(cookbooks, dep, environment)
93
91
  end
94
- else #environment is not here
92
+ else # environment is not here
95
93
  STDERR.puts "ERROR: Invalid Environment '#{environment}' listed in the manifest but not found in the environments directory."
96
94
  exit(-1)
97
95
  end
98
96
  end
99
97
 
98
+ def do_cookbook_version(cookbooks, dep, environment)
99
+ Spiceweasel::Log.debug("environment: '#{environment}' cookbook: '#{dep}'")
100
+
101
+ return if cookbooks.member?(dep)
102
+
103
+ STDERR.puts "ERROR: Cookbook dependency '#{dep}' from environment '#{environment}' is missing from the list of cookbooks in the manifest."
104
+ exit(-1)
105
+ end
106
+
107
+ def do_ruby_environment_file(file)
108
+ if Chef::VERSION.split('.')[0].to_i < 11
109
+ env = Chef::Environment.new(false)
110
+ else
111
+ env = Chef::Environment.new
112
+ end
113
+ begin
114
+ env.from_file(file)
115
+ rescue SyntaxError => e
116
+ STDERR.puts "ERROR: Environment '#{file}' has syntax errors."
117
+ STDERR.puts e.message
118
+ exit(-1)
119
+ end
120
+ env
121
+ end
122
+
100
123
  def member?(environment)
101
124
  environment_list.include?(environment)
102
125
  end
103
-
104
126
  end
105
127
  end
@@ -1,7 +1,8 @@
1
+ # encoding: UTF-8
1
2
  #
2
- # Author:: Matt Ray (<matt@opscode.com>)
3
+ # Author:: Matt Ray (<matt@getchef.com>)
3
4
  #
4
- # Copyright:: 2012-2013, Opscode, Inc <legal@opscode.com>
5
+ # Copyright:: 2012-2014, Chef Software, Inc <legal@getchef.com>
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
7
8
  # you may not use this file except in compliance with the License.
@@ -19,24 +20,22 @@
19
20
  require 'mixlib/shellout'
20
21
 
21
22
  module Spiceweasel
23
+ # executes the knife commands from parsing manifests
22
24
  class Execute
23
-
24
25
  # run the commands passed in
25
26
  def initialize(commands)
26
27
  # for now we're shelling out
27
28
  commands.each do | cmd |
28
29
  Spiceweasel::Log.debug("Command will timeout after #{Spiceweasel::Config[:cmd_timeout]} seconds.")
29
- knife = Mixlib::ShellOut.new(cmd.command, cmd.shellout_opts.merge(:live_stream => STDOUT, :timeout => Spiceweasel::Config[:timeout].to_i))
30
+ knife = Mixlib::ShellOut.new(cmd.command, cmd.shellout_opts.merge(live_stream: STDOUT, timeout: Spiceweasel::Config[:timeout].to_i))
30
31
  # check for parallel? and eventually use threads
31
32
  knife.run_command
32
33
  puts knife.stderr
33
34
  Spiceweasel::Log.debug(cmd)
34
35
  Spiceweasel::Log.debug(knife.stdout)
35
- Spiceweasel::Log.fatal(knife.stderr) if !knife.stderr.empty?
36
+ Spiceweasel::Log.fatal(knife.stderr) unless knife.stderr.empty?
36
37
  find.error! unless cmd.allow_failure?
37
38
  end
38
39
  end
39
-
40
40
  end
41
41
  end
42
-
@@ -1,8 +1,9 @@
1
+ # encoding: UTF-8
1
2
  #
2
3
  # Author:: Geoff Meakin
3
- # Author:: Matt Ray (<matt@opscode.com>)
4
+ # Author:: Matt Ray (<matt@getchef.com>)
4
5
  #
5
- # Copyright:: 2012-2013, Opscode, Inc <legal@opscode.com>
6
+ # Copyright:: 2012-2014, Chef Software, Inc <legal@getchef.com>
6
7
  #
7
8
  # Licensed under the Apache License, Version 2.0 (the "License");
8
9
  # you may not use this file except in compliance with the License.
@@ -20,53 +21,33 @@
20
21
  require 'chef'
21
22
 
22
23
  module Spiceweasel
24
+ # models the existing Chef repository as a manifest
23
25
  class ExtractLocal
24
-
25
- def self.parse_objects
26
+ def self.parse_objects # rubocop:disable CyclomaticComplexity
26
27
  objects = {}
27
28
 
28
29
  # BERKSHELF
29
- if File.file?('./Berksfile')
30
- objects['berksfile'] = nil
31
- berksfile = Berksfile.new(objects['berksfile'])
32
- end
30
+ berksfile = parse_berkshelf(objects)
33
31
 
34
32
  # COOKBOOKS
35
- cookbooks = berksfile ? self.resolve_cookbooks(berksfile.cookbook_list) : self.resolve_cookbooks
36
-
37
- objects['cookbooks'] = cookbooks unless cookbooks.empty?
33
+ cookbooks = berksfile ? resolve_cookbooks(berksfile.cookbook_list) : resolve_cookbooks
34
+ objects['cookbooks'] = cookbooks.sort_by { |c| [c.keys[0]] } unless cookbooks.empty?
38
35
 
39
36
  # ROLES
40
- roles = []
41
- Dir.glob("roles/*.{rb,json}").each do |role_full_path|
42
- role = self.grab_name_from_path(role_full_path)
43
- Spiceweasel::Log.debug("dir_ext: role: '#{role}'")
44
- roles << {role => nil}
45
- end
46
- objects['roles'] = roles unless roles.nil?
37
+ parse_roles(objects)
47
38
 
48
39
  # ENVIRONMENTS
49
40
  environments = []
50
- Dir.glob("environments/*.{rb,json}").each do |environment_full_path|
51
- environment = self.grab_name_from_path(environment_full_path)
41
+ Dir.glob('environments/*.{rb,json}').each do |environment_full_path|
42
+ environment = grab_name_from_path(environment_full_path)
52
43
  Spiceweasel::Log.debug("dir_ext: environment: '#{environment}'")
53
- environments << {environment => nil}
44
+ environments << { environment => nil }
54
45
  end
55
- objects['environments'] = environments unless environments.empty?
46
+ objects['environments'] = environments.sort_by { |e| [e.keys[0]] } unless environments.empty?
56
47
 
57
48
  # DATA BAGS
58
- data_bags = []
59
- Dir.glob('data_bags/*').each do |data_bag_full_path|
60
- data_bag = data_bag_full_path.split('/').last
61
- Spiceweasel::Log.debug("dir_ext: data_bag: '#{data_bag}'")
62
- data_bag_items = []
63
- Dir.glob("#{data_bag_full_path}/*.{rb,json}").each do |data_bag_item_full_path|
64
- Spiceweasel::Log.debug("dir_ext: data_bag: '#{data_bag}':'#{data_bag_item_full_path}'")
65
- data_bag_items << self.grab_name_from_path(data_bag_item_full_path)
66
- end if File.directory?(data_bag_full_path)
67
- data_bags << {data_bag => {'items' => data_bag_items}}
68
- end
69
- objects['data bags'] = data_bags unless data_bags.empty?
49
+ data_bags = parse_data_bags
50
+ objects['data bags'] = data_bags.sort_by { |d| [d.keys[0]] } unless data_bags.empty?
70
51
 
71
52
  # NODES
72
53
  # TODO: Cant use this yet as node_list.rb doesnt support node from file syntax but expects the node info to be part of the objects passed in
@@ -79,11 +60,43 @@ module Spiceweasel
79
60
  objects
80
61
  end
81
62
 
63
+ def self.parse_data_bags
64
+ data_bags = []
65
+ Dir.glob('data_bags/*').each do |data_bag_full_path|
66
+ next unless File.directory?(data_bag_full_path)
67
+ data_bag = data_bag_full_path.split('/').last
68
+ Spiceweasel::Log.debug("dir_ext: data_bag: '#{data_bag}'")
69
+ data_bag_items = []
70
+ Dir.glob("#{data_bag_full_path}/*.{rb,json}").each do |data_bag_item_full_path|
71
+ Spiceweasel::Log.debug("dir_ext: data_bag: '#{data_bag}':'#{data_bag_item_full_path}'")
72
+ data_bag_items << grab_name_from_path(data_bag_item_full_path)
73
+ end if File.directory?(data_bag_full_path)
74
+ data_bags << { data_bag => { 'items' => data_bag_items.sort } }
75
+ end
76
+ data_bags
77
+ end
78
+
79
+ def self.parse_roles(objects)
80
+ roles = []
81
+ Dir.glob('roles/*.{rb,json}').each do |role_full_path|
82
+ role = grab_name_from_path(role_full_path)
83
+ Spiceweasel::Log.debug("dir_ext: role: '#{role}'")
84
+ roles << { role => nil }
85
+ end
86
+ objects['roles'] = roles.sort_by { |r| [r.keys[0]] } unless roles.nil? || roles.empty?
87
+ end
88
+
89
+ def self.parse_berkshelf(objects)
90
+ if File.file?('./Berksfile')
91
+ objects['berksfile'] = nil
92
+ berksfile = Berksfile.new(objects['berksfile'])
93
+ end
94
+ berksfile
95
+ end
96
+
82
97
  def self.grab_name_from_path(path)
83
98
  name = path.split('/').last.split('.')
84
- if name.length > 1
85
- name.pop
86
- end
99
+ name.pop if name.length > 1
87
100
  name.join('.')
88
101
  end
89
102
 
@@ -94,29 +107,29 @@ module Spiceweasel
94
107
  books = loader.cookbooks_by_name
95
108
  graph = Solve::Graph.new
96
109
  cblist = []
97
- #push in the berkshelf cookbooks to cover any other deps
110
+ # push in the berkshelf cookbooks to cover any other deps
98
111
  berkshelf_cookbooks.each do |name, version|
99
112
  Spiceweasel::Log.debug("dir_ext:berks: #{name} #{version}")
100
- graph.artifacts(name, version)
113
+ graph.artifact(name, version)
101
114
  end
102
115
  books.each do |name, cb|
103
116
  Spiceweasel::Log.debug("dir_ext: #{name} #{cb.version}")
104
- artifact = graph.artifacts(name, cb.version)
117
+ artifact = graph.artifact(name, cb.version)
105
118
  cblist.push([name, cb.version])
106
119
  cb.metadata.dependencies.each do |dep_name, dep_version|
107
120
  artifact.depends(dep_name, dep_version)
108
121
  end
109
122
  end
110
- #get the cookbooks and their versions, map to cookbook hash format
123
+ # get the cookbooks and their versions, map to cookbook hash format
111
124
  begin
112
125
  cookbooks = []
113
- Solve.it!(graph, cblist).each {|k,v| cookbooks.push({k => {'version' => v}})}
114
- rescue Solve::Errors::NoSolutionError => e
115
- STDERR.puts "ERROR: There are missing cookbook dependencies, please check your metadata.rb files."
126
+ Solve.it!(graph, cblist).each { |k, v| cookbooks.push(k => { 'version' => v }) }
127
+ rescue Solve::Errors::NoSolutionError
128
+ STDERR.puts 'ERROR: There are missing cookbook dependencies, please check your metadata.rb files.'
116
129
  exit(-1)
117
130
  end
118
- #remove any cookbooks managed by berkshelf
119
- cookbooks.delete_if {|x| berkshelf_cookbooks.keys.member?(x.keys[0])}
131
+ # remove any cookbooks managed by berkshelf
132
+ cookbooks.delete_if { |x| berkshelf_cookbooks.keys.member?(x.keys[0]) }
120
133
  end
121
134
  end
122
135
  end
@@ -1,7 +1,8 @@
1
+ # encoding: UTF-8
1
2
  #
2
- # Author:: Matt Ray (<matt@opscode.com>)
3
+ # Author:: Matt Ray (<matt@getchef.com>)
3
4
  #
4
- # Copyright:: 2013, Opscode, Inc <legal@opscode.com>
5
+ # Copyright:: 2013-2014, Chef Software, Inc <legal@getchef.com>
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
7
8
  # you may not use this file except in compliance with the License.
@@ -17,26 +18,27 @@
17
18
  #
18
19
 
19
20
  module Spiceweasel
21
+ # create knife commands from the manifest
20
22
  class Knife
21
-
22
23
  include CommandHelper
23
24
 
24
25
  attr_reader :knife_list, :create
25
26
 
26
27
  def initialize(knives = {}, allknifes = [])
27
- @create = Array.new
28
- if knives
29
- knives.each do |knife|
30
- Spiceweasel::Log.debug("knife: #{knife}")
31
- knife.keys.each do |knf|
32
- validate(knf, allknifes) unless Spiceweasel::Config[:novalidation]
33
- if knife[knf]
34
- knife[knf].each do |options|
35
- create_command("knife #{knf} #{options}")
36
- end
37
- else
38
- create_command("knife #{knf}")
28
+ @create = []
29
+
30
+ return unless knives
31
+
32
+ knives.each do |knife|
33
+ Spiceweasel::Log.debug("knife: #{knife}")
34
+ knife.keys.each do |knf|
35
+ validate(knf, allknifes) unless Spiceweasel::Config[:novalidation]
36
+ if knife[knf]
37
+ knife[knf].each do |options|
38
+ create_command("knife #{knf} #{options}")
39
39
  end
40
+ else
41
+ create_command("knife #{knf}")
40
42
  end
41
43
  end
42
44
  end
@@ -44,11 +46,10 @@ module Spiceweasel
44
46
 
45
47
  # test that the knife command exists
46
48
  def validate(command, allknifes)
47
- unless allknifes.index {|x| x.start_with?("knife #{command}")}
48
- STDERR.puts "ERROR: 'knife #{command}' is not a currently supported command for knife."
49
- exit(-1)
50
- end
51
- end
49
+ return if allknifes.index { |x| x.start_with?("knife #{command}") }
52
50
 
51
+ STDERR.puts "ERROR: 'knife #{command}' is not a currently supported command for knife."
52
+ exit(-1)
53
+ end
53
54
  end
54
55
  end
@@ -1,7 +1,8 @@
1
+ # encoding: UTF-8
1
2
  #
2
- # Author:: Matt Ray (<matt@opscode.com>)
3
+ # Author:: Matt Ray (<matt@getchef.com>)
3
4
  #
4
- # Copyright:: 2012, Opscode, Inc <legal@opscode.com>
5
+ # Copyright:: 2012-2014, Chef Software, Inc <legal@getchef.com>
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
7
8
  # you may not use this file except in compliance with the License.
@@ -19,12 +20,11 @@
19
20
  require 'mixlib/log'
20
21
 
21
22
  module Spiceweasel
23
+ # configure logging
22
24
  class Log
23
25
  extend Mixlib::Log
24
26
 
25
- #not quite ready for timestamps
27
+ # not quite ready for timestamps
26
28
  Mixlib::Log::Formatter.show_time = false
27
-
28
29
  end
29
30
  end
30
-