chef-sugar-ng 4.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.github/lock.yml +3 -0
  3. data/.github/reaction.yml +1 -0
  4. data/.gitignore +26 -0
  5. data/.kitchen.yml +16 -0
  6. data/.travis.yml +17 -0
  7. data/CHANGELOG.md +261 -0
  8. data/CONTRIBUTING.md +20 -0
  9. data/Gemfile +2 -0
  10. data/LICENSE +201 -0
  11. data/README.md +540 -0
  12. data/Rakefile +11 -0
  13. data/chef-sugar-ng.gemspec +33 -0
  14. data/lib/chef/sugar.rb +51 -0
  15. data/lib/chef/sugar/architecture.rb +171 -0
  16. data/lib/chef/sugar/cloud.rb +192 -0
  17. data/lib/chef/sugar/constraints.rb +108 -0
  18. data/lib/chef/sugar/constraints_dsl.rb +83 -0
  19. data/lib/chef/sugar/core_extensions.rb +19 -0
  20. data/lib/chef/sugar/core_extensions/array.rb +34 -0
  21. data/lib/chef/sugar/core_extensions/object.rb +27 -0
  22. data/lib/chef/sugar/core_extensions/string.rb +66 -0
  23. data/lib/chef/sugar/data_bag.rb +146 -0
  24. data/lib/chef/sugar/docker.rb +40 -0
  25. data/lib/chef/sugar/filters.rb +227 -0
  26. data/lib/chef/sugar/init.rb +62 -0
  27. data/lib/chef/sugar/ip.rb +48 -0
  28. data/lib/chef/sugar/kernel.rb +49 -0
  29. data/lib/chef/sugar/kitchen.rb +40 -0
  30. data/lib/chef/sugar/node.rb +213 -0
  31. data/lib/chef/sugar/platform.rb +327 -0
  32. data/lib/chef/sugar/platform_family.rb +179 -0
  33. data/lib/chef/sugar/ruby.rb +51 -0
  34. data/lib/chef/sugar/run_context.rb +41 -0
  35. data/lib/chef/sugar/shell.rb +147 -0
  36. data/lib/chef/sugar/vagrant.rb +77 -0
  37. data/lib/chef/sugar/version.rb +21 -0
  38. data/lib/chef/sugar/virtualization.rb +151 -0
  39. data/libraries/chef-sugar.rb +1 -0
  40. data/metadata.rb +24 -0
  41. data/recipes/default.rb +20 -0
  42. data/spec/spec_helper.rb +25 -0
  43. data/spec/support/shared_examples.rb +20 -0
  44. data/spec/unit/chef/sugar/architecture_spec.rb +129 -0
  45. data/spec/unit/chef/sugar/cloud_spec.rb +149 -0
  46. data/spec/unit/chef/sugar/constraints_spec.rb +45 -0
  47. data/spec/unit/chef/sugar/core_extensions/array_spec.rb +10 -0
  48. data/spec/unit/chef/sugar/core_extensions/object_spec.rb +62 -0
  49. data/spec/unit/chef/sugar/core_extensions/string_spec.rb +48 -0
  50. data/spec/unit/chef/sugar/data_bag_spec.rb +118 -0
  51. data/spec/unit/chef/sugar/docker_spec.rb +39 -0
  52. data/spec/unit/chef/sugar/init_spec.rb +74 -0
  53. data/spec/unit/chef/sugar/ip_spec.rb +53 -0
  54. data/spec/unit/chef/sugar/kernel_spec.rb +16 -0
  55. data/spec/unit/chef/sugar/kitchen_spec.rb +18 -0
  56. data/spec/unit/chef/sugar/node_spec.rb +172 -0
  57. data/spec/unit/chef/sugar/platform_family_spec.rb +166 -0
  58. data/spec/unit/chef/sugar/platform_spec.rb +342 -0
  59. data/spec/unit/chef/sugar/ruby_spec.rb +39 -0
  60. data/spec/unit/chef/sugar/run_context_spec.rb +19 -0
  61. data/spec/unit/chef/sugar/shell_spec.rb +104 -0
  62. data/spec/unit/chef/sugar/vagrant_spec.rb +37 -0
  63. data/spec/unit/chef/sugar/virtualization_spec.rb +135 -0
  64. data/spec/unit/recipes/default_spec.rb +9 -0
  65. metadata +202 -0
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new do |t|
5
+ t.rspec_opts = [
6
+ '--color',
7
+ '--format progress',
8
+ ].join(' ')
9
+ end
10
+
11
+ task default: :spec
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'chef/sugar/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'chef-sugar-ng'
8
+ spec.version = Chef::Sugar::VERSION
9
+ spec.authors = ['Seth Vargo']
10
+ spec.email = ['sethvargo@gmail.com']
11
+ spec.description = 'A series of helpful sugar of the Chef core and ' \
12
+ 'other resources to make a cleaner, more lean recipe ' \
13
+ 'DSL, enforce DRY principles, and make writing Chef ' \
14
+ 'recipes an awesome experience!'
15
+ spec.summary = 'A collection of helper methods and modules that ' \
16
+ 'make working with Chef recipes awesome.'
17
+ spec.homepage = 'https://github.com/chef/chef-sugar'
18
+ spec.license = 'Apache 2.0'
19
+
20
+ spec.required_ruby_version = '>= 2.2.2'
21
+
22
+ spec.files = `git ls-files`.split($/)
23
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
24
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.3'
28
+ spec.add_development_dependency 'rake'
29
+
30
+ spec.add_development_dependency 'chefspec'
31
+ spec.add_development_dependency 'test-kitchen'
32
+ spec.add_development_dependency 'kitchen-vagrant'
33
+ end
data/lib/chef/sugar.rb ADDED
@@ -0,0 +1,51 @@
1
+ #
2
+ # Copyright 2013-2015, Seth Vargo <sethvargo@gmail.com>
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'chef/recipe'
18
+ require 'chef/resource'
19
+ require 'chef/provider'
20
+
21
+ class Chef
22
+ module Sugar
23
+ require_relative 'sugar/architecture'
24
+ require_relative 'sugar/cloud'
25
+ require_relative 'sugar/constraints'
26
+ require_relative 'sugar/constraints_dsl'
27
+ require_relative 'sugar/data_bag'
28
+ require_relative 'sugar/docker'
29
+ require_relative 'sugar/filters'
30
+ require_relative 'sugar/init'
31
+ require_relative 'sugar/ip'
32
+ require_relative 'sugar/kernel'
33
+ require_relative 'sugar/kitchen'
34
+ require_relative 'sugar/node'
35
+ require_relative 'sugar/platform'
36
+ require_relative 'sugar/platform_family'
37
+ require_relative 'sugar/ruby'
38
+ require_relative 'sugar/run_context'
39
+ require_relative 'sugar/shell'
40
+ require_relative 'sugar/vagrant'
41
+ require_relative 'sugar/version'
42
+ require_relative 'sugar/virtualization'
43
+ end
44
+ end
45
+
46
+ Chef::Recipe.send(:include, Chef::Sugar::DSL)
47
+ Chef::Recipe.send(:include, Chef::Sugar::RecipeDSL) # TODO: this is a hack
48
+ Chef::Resource.send(:include, Chef::Sugar::DSL)
49
+ Chef::Provider.send(:include, Chef::Sugar::DSL)
50
+
51
+ Object.send(:include, Chef::Sugar::Kernel)
@@ -0,0 +1,171 @@
1
+ #
2
+ # Copyright 2013-2015, Seth Vargo <sethvargo@gmail.com>
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ class Chef
18
+ module Sugar
19
+ module Architecture
20
+ extend self
21
+
22
+ #
23
+ # Determine if the current architecture is 64-bit
24
+ #
25
+ # @return [Boolean]
26
+ #
27
+ def _64_bit?(node)
28
+ %w(amd64 x86_64 ppc64 ppc64le s390x ia64 sparc64 aarch64 arch64 arm64 sun4v sun4u s390x)
29
+ .include?(node['kernel']['machine']) || ( node['kernel']['bits'] == '64' )
30
+ end
31
+
32
+ #
33
+ # Determine if the current architecture is 32-bit
34
+ #
35
+ # @todo Make this more than "not 64-bit"
36
+ #
37
+ # @return [Boolean]
38
+ #
39
+ def _32_bit?(node)
40
+ !_64_bit?(node)
41
+ end
42
+
43
+ #
44
+ # Determine if the current architecture is i386
45
+ #
46
+ # @return [Boolean]
47
+ #
48
+ def i386?(node)
49
+ _32_bit?(node) && intel?(node)
50
+ end
51
+
52
+ #
53
+ # Determine if the current architecture is Intel.
54
+ #
55
+ # @return [Boolean]
56
+ #
57
+ def intel?(node)
58
+ %w(i86pc i386 x86_64 amd64 i686)
59
+ .include?(node['kernel']['machine'])
60
+ end
61
+
62
+ #
63
+ # Determine if the current architecture is SPARC.
64
+ #
65
+ # @return [Boolean]
66
+ #
67
+ def sparc?(node)
68
+ %w(sun4u sun4v)
69
+ .include?(node['kernel']['machine'])
70
+ end
71
+
72
+ #
73
+ # Determine if the current architecture is Powerpc64 Big Endian
74
+ #
75
+ # @return [Boolean]
76
+ #
77
+ def ppc64?(node)
78
+ %w(ppc64)
79
+ .include?(node['kernel']['machine'])
80
+ end
81
+
82
+ #
83
+ # Determine if the current architecture is Powerpc64 Little Endian
84
+ #
85
+ # @return [Boolean]
86
+ #
87
+ def ppc64le?(node)
88
+ %w(ppc64le)
89
+ .include?(node['kernel']['machine'])
90
+ end
91
+
92
+ #
93
+ # Determine if the current architecture is PowerPC
94
+ #
95
+ # @return [Boolean]
96
+ #
97
+ def powerpc?(node)
98
+ %w(powerpc)
99
+ .include?(node['kernel']['machine'])
100
+ end
101
+
102
+ #
103
+ # Determine if the current architecture is ARM with Hard Float
104
+ #
105
+ # @return [Boolean]
106
+ #
107
+ def armhf?(node)
108
+ # Add more arm variants as needed here
109
+ %w(armv6l armv7l)
110
+ .include?(node['kernel']['machine'])
111
+ end
112
+
113
+ #
114
+ # Determine if the current architecture is AArch64
115
+ #
116
+ # @return [Boolean]
117
+ #
118
+ def aarch64?(node)
119
+ # Add more arm variants as needed here
120
+ %w(aarch64)
121
+ .include?(node['kernel']['machine'])
122
+ end
123
+
124
+ #
125
+ # Determine if the current architecture is s390x
126
+ #
127
+ # @return [Boolean]
128
+ #
129
+ def s390x?(node)
130
+ %w(s390x)
131
+ .include?(node['kernel']['machine'])
132
+ end
133
+ end
134
+
135
+ module DSL
136
+ # @see Chef::Sugar::Architecture#_64_bit?
137
+ def _64_bit?; Chef::Sugar::Architecture._64_bit?(node); end
138
+
139
+ # @see Chef::Sugar::Architecture#_32_bit?
140
+ def _32_bit?; Chef::Sugar::Architecture._32_bit?(node); end
141
+
142
+ # @see Chef::Sugar::Architecture#intel?
143
+ def i386?; Chef::Sugar::Architecture.i386?(node); end
144
+
145
+ # @see Chef::Sugar::Architecture#intel?
146
+ def intel?; Chef::Sugar::Architecture.intel?(node); end
147
+
148
+ # @see Chef::Sugar::Architecture#sparc?
149
+ def sparc?; Chef::Sugar::Architecture.sparc?(node); end
150
+
151
+ # @see Chef::Sugar::Architecture#ppc64?
152
+ def ppc64?; Chef::Sugar::Architecture.ppc64?(node); end
153
+
154
+ # @see Chef::Sugar::Architecture#ppc64le?
155
+ def ppc64le?; Chef::Sugar::Architecture.ppc64le?(node); end
156
+
157
+ # @see Chef::Sugar::Architecture#powerpc?
158
+ def powerpc?; Chef::Sugar::Architecture.powerpc?(node); end
159
+
160
+ # @see Chef::Sugar::Architecture#arm?
161
+ def armhf?; Chef::Sugar::Architecture.armhf?(node); end
162
+
163
+ # @see Chef::Sugar::Architecture#aarch64?
164
+ def aarch64?; Chef::Sugar::Architecture.aarch64?(node); end
165
+
166
+ # @see Chef::Sugar::Architecture#s390x?
167
+ def s390x?; Chef::Sugar::Architecture.s390x?(node); end
168
+
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,192 @@
1
+ #
2
+ # Copyright 2013-2015, Seth Vargo <sethvargo@gmail.com>
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ class Chef
18
+ module Sugar
19
+ module Cloud
20
+ extend self
21
+
22
+ #
23
+ # Return true if the current current node is in "the cloud".
24
+ #
25
+ # @param [Chef::Node] node
26
+ # the node to check
27
+ #
28
+ # @return [Boolean]
29
+ #
30
+ def cloud?(node)
31
+ node.key?('cloud')
32
+ end
33
+
34
+ #
35
+ # Return true if the current current node is in EC2
36
+ #
37
+ # @param [Chef::Node] node
38
+ # the node to check
39
+ #
40
+ # @return [Boolean]
41
+ #
42
+ def ec2?(node)
43
+ node.key?('ec2')
44
+ end
45
+
46
+ #
47
+ # Return true if the current current node is in GCE
48
+ #
49
+ # @param [Chef::Node] node
50
+ # the node to check
51
+ #
52
+ # @return [Boolean]
53
+ #
54
+ def gce?(node)
55
+ node.key?('gce')
56
+ end
57
+
58
+ #
59
+ # Return true if the current current node is in Rackspace
60
+ #
61
+ # @param [Chef::Node] node
62
+ # the node to check
63
+ #
64
+ # @return [Boolean]
65
+ #
66
+ def rackspace?(node)
67
+ node.key?('rackspace')
68
+ end
69
+
70
+ #
71
+ # Return true if the current current node is in Eucalyptus
72
+ #
73
+ # @param [Chef::Node] node
74
+ # the node to check
75
+ #
76
+ # @return [Boolean]
77
+ #
78
+ def eucalyptus?(node)
79
+ node.key?('eucalyptus')
80
+ end
81
+ alias_method :euca?, :eucalyptus?
82
+
83
+ #
84
+ # Return true if the current current node is in Linode
85
+ #
86
+ # @param [Chef::Node] node
87
+ # the node to check
88
+ #
89
+ # @return [Boolean]
90
+ #
91
+ def linode?(node)
92
+ node.key?('linode')
93
+ end
94
+
95
+ #
96
+ # Return true if the current current node is in Openstack
97
+ #
98
+ # @param [Chef::Node] node
99
+ # the node to check
100
+ #
101
+ # @return [Boolean]
102
+ #
103
+ def openstack?(node)
104
+ node.key?('openstack')
105
+ end
106
+
107
+ #
108
+ # Return true if the current current node is in Cloudstack
109
+ #
110
+ # @param [Chef::Node] node
111
+ # the node to check
112
+ #
113
+ # @return [Boolean]
114
+ #
115
+ def cloudstack?(node)
116
+ node.key?('cloudstack')
117
+ end
118
+
119
+ #
120
+ # Return true if the current current node is in Azure
121
+ #
122
+ # @param [Chef::Node] node
123
+ # the node to check
124
+ #
125
+ # @return [Boolean]
126
+ #
127
+ def azure?(node)
128
+ node.key?('azure')
129
+ end
130
+
131
+ #
132
+ # Return true if the current current node is in DigitalOcean
133
+ #
134
+ # @param [Chef::Node] node
135
+ # the node to check
136
+ #
137
+ # @return [Boolean]
138
+ #
139
+ def digitalocean?(node)
140
+ node.key?('digital_ocean')
141
+ end
142
+
143
+ #
144
+ # Return true if the current current node is in SoftLayer
145
+ #
146
+ # @param [Chef::Node] node
147
+ # the node to check
148
+ #
149
+ # @return [Boolean]
150
+ #
151
+ def softlayer?(node)
152
+ node.key?('softlayer')
153
+ end
154
+ end
155
+
156
+ module DSL
157
+ # @see Chef::Sugar::Cloud#cloud?
158
+ def cloud?; Chef::Sugar::Cloud.cloud?(node); end
159
+
160
+ # @see Chef::Sugar::Cloud#ec2?
161
+ def ec2?; Chef::Sugar::Cloud.ec2?(node); end
162
+
163
+ # @see Chef::Sugar::Cloud#gce?
164
+ def gce?; Chef::Sugar::Cloud.gce?(node); end
165
+
166
+ # @see Chef::Sugar::Cloud#rackspace?
167
+ def rackspace?; Chef::Sugar::Cloud.rackspace?(node); end
168
+
169
+ # @see Chef::Sugar::Cloud#eucalyptus?
170
+ def eucalyptus?; Chef::Sugar::Cloud.eucalyptus?(node); end
171
+ alias_method :euca?, :eucalyptus?
172
+
173
+ # @see Chef::Sugar::Cloud#linode?
174
+ def linode?; Chef::Sugar::Cloud.linode?(node); end
175
+
176
+ # @see Chef::Sugar::Cloud#openstack?
177
+ def openstack?; Chef::Sugar::Cloud.openstack?(node); end
178
+
179
+ # @see Chef::Sugar::Cloud#cloudstack?
180
+ def cloudstack?; Chef::Sugar::Cloud.cloudstack?(node); end
181
+
182
+ # @see Chef::Sugar::Cloud#azure?
183
+ def azure?; Chef::Sugar::Cloud.azure?(node); end
184
+
185
+ # @see Chef::Sugar::Cloud#digitalocean?
186
+ def digitalocean?; Chef::Sugar::Cloud.digitalocean?(node); end
187
+
188
+ # @see Chef::Sugar::Cloud#softlayer?
189
+ def softlayer?; Chef::Sugar::Cloud.softlayer?(node); end
190
+ end
191
+ end
192
+ end