chef-utils 18.0.172 → 18.0.185

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +201 -201
  3. data/Rakefile +15 -15
  4. data/chef-utils.gemspec +50 -50
  5. data/lib/chef-utils/dist.rb +154 -154
  6. data/lib/chef-utils/dsl/architecture.rb +150 -150
  7. data/lib/chef-utils/dsl/cloud.rb +155 -155
  8. data/lib/chef-utils/dsl/default_paths.rb +60 -60
  9. data/lib/chef-utils/dsl/introspection.rb +134 -134
  10. data/lib/chef-utils/dsl/os.rb +58 -58
  11. data/lib/chef-utils/dsl/path_sanity.rb +39 -39
  12. data/lib/chef-utils/dsl/platform.rb +387 -387
  13. data/lib/chef-utils/dsl/platform_family.rb +360 -360
  14. data/lib/chef-utils/dsl/platform_version.rb +41 -41
  15. data/lib/chef-utils/dsl/service.rb +112 -112
  16. data/lib/chef-utils/dsl/train_helpers.rb +87 -87
  17. data/lib/chef-utils/dsl/virtualization.rb +272 -272
  18. data/lib/chef-utils/dsl/which.rb +123 -123
  19. data/lib/chef-utils/dsl/windows.rb +86 -86
  20. data/lib/chef-utils/internal.rb +114 -114
  21. data/lib/chef-utils/mash.rb +263 -263
  22. data/lib/chef-utils/parallel_map.rb +131 -131
  23. data/lib/chef-utils/version.rb +20 -20
  24. data/lib/chef-utils/version_string.rb +160 -160
  25. data/lib/chef-utils.rb +53 -53
  26. data/spec/spec_helper.rb +100 -100
  27. data/spec/unit/dsl/architecture_spec.rb +151 -151
  28. data/spec/unit/dsl/cloud_spec.rb +93 -93
  29. data/spec/unit/dsl/dsl_spec.rb +34 -34
  30. data/spec/unit/dsl/introspection_spec.rb +201 -201
  31. data/spec/unit/dsl/os_spec.rb +175 -175
  32. data/spec/unit/dsl/path_sanity_spec.rb +86 -86
  33. data/spec/unit/dsl/platform_family_spec.rb +235 -235
  34. data/spec/unit/dsl/platform_spec.rb +252 -252
  35. data/spec/unit/dsl/service_spec.rb +117 -117
  36. data/spec/unit/dsl/virtualization_spec.rb +75 -75
  37. data/spec/unit/dsl/which_spec.rb +171 -171
  38. data/spec/unit/dsl/windows_spec.rb +84 -84
  39. data/spec/unit/mash_spec.rb +51 -51
  40. data/spec/unit/parallel_map_spec.rb +156 -156
  41. metadata +7 -7
@@ -1,272 +1,272 @@
1
- # frozen_string_literal: true
2
- #
3
- # Copyright:: Copyright (c) Chef Software Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require_relative "../internal"
20
-
21
- module ChefUtils
22
- module DSL
23
- module Virtualization
24
- include Internal
25
-
26
- # Determine if the current node is a KVM guest.
27
- #
28
- # @param [Chef::Node] node
29
- # @since 15.8
30
- #
31
- # @return [Boolean]
32
- #
33
- def kvm?(node = __getnode)
34
- node.dig("virtualization", "system") == "kvm" && node.dig("virtualization", "role") == "guest"
35
- end
36
-
37
- # Determine if the current node is a KVM host.
38
- #
39
- # @param [Chef::Node] node
40
- # @since 15.8
41
- #
42
- # @return [Boolean]
43
- #
44
- def kvm_host?(node = __getnode)
45
- node.dig("virtualization", "system") == "kvm" && node.dig("virtualization", "role") == "host"
46
- end
47
-
48
- # Determine if the current node is running in a linux container.
49
- #
50
- # @param [Chef::Node] node
51
- # @since 15.8
52
- #
53
- # @return [Boolean]
54
- #
55
- def lxc?(node = __getnode)
56
- node.dig("virtualization", "system") == "lxc" && node.dig("virtualization", "role") == "guest"
57
- end
58
-
59
- # Determine if the current node is a linux container host.
60
- #
61
- # @param [Chef::Node] node
62
- # @since 15.8
63
- #
64
- # @return [Boolean]
65
- #
66
- def lxc_host?(node = __getnode)
67
- node.dig("virtualization", "system") == "lxc" && node.dig("virtualization", "role") == "host"
68
- end
69
-
70
- # Determine if the current node is running under Parallels Desktop.
71
- #
72
- # @param [Chef::Node] node
73
- # @since 15.8
74
- #
75
- # @return [Boolean]
76
- # true if the machine is currently running under Parallels Desktop, false
77
- # otherwise
78
- #
79
- def parallels?(node = __getnode)
80
- node.dig("virtualization", "system") == "parallels" && node.dig("virtualization", "role") == "guest"
81
- end
82
-
83
- # Determine if the current node is a Parallels Desktop host.
84
- #
85
- # @param [Chef::Node] node
86
- # @since 15.8
87
- #
88
- # @return [Boolean]
89
- # true if the machine is currently running under Parallels Desktop, false
90
- # otherwise
91
- #
92
- def parallels_host?(node = __getnode)
93
- node.dig("virtualization", "system") == "parallels" && node.dig("virtualization", "role") == "host"
94
- end
95
-
96
- # Determine if the current node is a VirtualBox guest.
97
- #
98
- # @param [Chef::Node] node
99
- # @since 15.8
100
- #
101
- # @return [Boolean]
102
- #
103
- def vbox?(node = __getnode)
104
- node.dig("virtualization", "system") == "vbox" && node.dig("virtualization", "role") == "guest"
105
- end
106
-
107
- # Determine if the current node is a VirtualBox host.
108
- #
109
- # @param [Chef::Node] node
110
- # @since 15.8
111
- #
112
- # @return [Boolean]
113
- #
114
- def vbox_host?(node = __getnode)
115
- node.dig("virtualization", "system") == "vbox" && node.dig("virtualization", "role") == "host"
116
- end
117
-
118
- # chef-sugar backcompat method
119
- alias_method :virtualbox?, :vbox?
120
-
121
- # Determine if the current node is a VMWare guest.
122
- #
123
- # @param [Chef::Node] node
124
- # @since 15.8
125
- #
126
- # @return [Boolean]
127
- #
128
- def vmware?(node = __getnode)
129
- node.dig("virtualization", "system") == "vmware" && node.dig("virtualization", "role") == "guest"
130
- end
131
-
132
- # Determine if the current node is VMware host.
133
- #
134
- # @param [Chef::Node] node
135
- # @since 15.8
136
- #
137
- # @return [Boolean]
138
- #
139
- def vmware_host?(node = __getnode)
140
- node.dig("virtualization", "system") == "vmware" && node.dig("virtualization", "role") == "host"
141
- end
142
-
143
- # Determine if the current node is virtualized on VMware Desktop (Fusion/Player/Workstation).
144
- #
145
- # @param [Chef::Node] node
146
- # @since 17.9
147
- #
148
- # @return [Boolean]
149
- #
150
- def vmware_desktop?(node = __getnode)
151
- node.dig("virtualization", "system") == "vmware" && node.dig("vmware", "host", "type") == "vmware_desktop"
152
- end
153
-
154
- # Determine if the current node is virtualized on VMware vSphere (ESX).
155
- #
156
- # @param [Chef::Node] node
157
- # @since 17.9
158
- #
159
- # @return [Boolean]
160
- #
161
- def vmware_vsphere?(node = __getnode)
162
- node.dig("virtualization", "system") == "vmware" && node.dig("vmware", "host", "type") == "vmware_vsphere"
163
- end
164
-
165
- # Determine if the current node is an openvz guest.
166
- #
167
- # @param [Chef::Node] node
168
- # @since 15.8
169
- #
170
- # @return [Boolean]
171
- #
172
- def openvz?(node = __getnode)
173
- node.dig("virtualization", "system") == "openvz" && node.dig("virtualization", "role") == "guest"
174
- end
175
-
176
- # Determine if the current node is an openvz host.
177
- #
178
- # @param [Chef::Node] node
179
- # @since 15.8
180
- #
181
- # @return [Boolean]
182
- #
183
- def openvz_host?(node = __getnode)
184
- node.dig("virtualization", "system") == "openvz" && node.dig("virtualization", "role") == "host"
185
- end
186
-
187
- # Determine if the current node is running under any virtualization environment
188
- #
189
- # @param [Chef::Node] node
190
- # @since 15.8
191
- #
192
- # @return [Boolean]
193
- #
194
- def guest?(node = __getnode)
195
- node.dig("virtualization", "role") == "guest"
196
- end
197
-
198
- # chef-sugar backcompat method
199
- alias_method :virtual?, :guest?
200
-
201
- # Determine if the current node supports running guests under any virtualization environment
202
- #
203
- # @param [Chef::Node] node
204
- # @since 15.8
205
- #
206
- # @return [Boolean]
207
- #
208
- def hypervisor?(node = __getnode)
209
- node.dig("virtualization", "role") == "host"
210
- end
211
-
212
- # Determine if the current node is NOT running under any virtualization environment (bare-metal or hypervisor on metal)
213
- #
214
- # @param [Chef::Node] node
215
- # @since 15.8
216
- #
217
- # @return [Boolean]
218
- #
219
- def physical?(node = __getnode)
220
- !virtual?(node)
221
- end
222
-
223
- # Determine if the current node is running as a vagrant guest.
224
- #
225
- # Note that this API is equivalent to just looking for the vagrant user or the
226
- # vagrantup.com domain in the hostname, which is the best API we have.
227
- #
228
- # @param [Chef::Node] node
229
- # @since 15.8
230
- #
231
- # @return [Boolean]
232
- # true if the machine is currently running vagrant, false
233
- # otherwise
234
- #
235
- def vagrant?(node = __getnode)
236
- vagrant_key?(node) || vagrant_domain?(node) || vagrant_user?(node)
237
- end
238
-
239
- private
240
-
241
- # Check if the +vagrant+ key exists on the +node+ object. This key is no
242
- # longer populated by vagrant, but it is kept around for legacy purposes.
243
- #
244
- # @param (see vagrant?)
245
- # @return (see vagrant?)
246
- #
247
- def vagrant_key?(node = __getnode)
248
- node.key?("vagrant")
249
- end
250
-
251
- # Check if "vagrantup.com" is included in the node's domain.
252
- #
253
- # @param (see vagrant?)
254
- # @return (see vagrant?)
255
- #
256
- def vagrant_domain?(node = __getnode)
257
- node.key?("domain") && !node["domain"].nil? && node["domain"].include?("vagrantup.com")
258
- end
259
-
260
- # Check if the system contains a +vagrant+ user.
261
- #
262
- # @param (see vagrant?)
263
- # @return (see vagrant?)
264
- #
265
- def vagrant_user?(node = __getnode)
266
- !!(Etc.getpwnam("vagrant") rescue nil)
267
- end
268
-
269
- extend self
270
- end
271
- end
272
- end
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: Copyright (c) Chef Software Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require_relative "../internal"
20
+
21
+ module ChefUtils
22
+ module DSL
23
+ module Virtualization
24
+ include Internal
25
+
26
+ # Determine if the current node is a KVM guest.
27
+ #
28
+ # @param [Chef::Node] node
29
+ # @since 15.8
30
+ #
31
+ # @return [Boolean]
32
+ #
33
+ def kvm?(node = __getnode)
34
+ node.dig("virtualization", "system") == "kvm" && node.dig("virtualization", "role") == "guest"
35
+ end
36
+
37
+ # Determine if the current node is a KVM host.
38
+ #
39
+ # @param [Chef::Node] node
40
+ # @since 15.8
41
+ #
42
+ # @return [Boolean]
43
+ #
44
+ def kvm_host?(node = __getnode)
45
+ node.dig("virtualization", "system") == "kvm" && node.dig("virtualization", "role") == "host"
46
+ end
47
+
48
+ # Determine if the current node is running in a linux container.
49
+ #
50
+ # @param [Chef::Node] node
51
+ # @since 15.8
52
+ #
53
+ # @return [Boolean]
54
+ #
55
+ def lxc?(node = __getnode)
56
+ node.dig("virtualization", "system") == "lxc" && node.dig("virtualization", "role") == "guest"
57
+ end
58
+
59
+ # Determine if the current node is a linux container host.
60
+ #
61
+ # @param [Chef::Node] node
62
+ # @since 15.8
63
+ #
64
+ # @return [Boolean]
65
+ #
66
+ def lxc_host?(node = __getnode)
67
+ node.dig("virtualization", "system") == "lxc" && node.dig("virtualization", "role") == "host"
68
+ end
69
+
70
+ # Determine if the current node is running under Parallels Desktop.
71
+ #
72
+ # @param [Chef::Node] node
73
+ # @since 15.8
74
+ #
75
+ # @return [Boolean]
76
+ # true if the machine is currently running under Parallels Desktop, false
77
+ # otherwise
78
+ #
79
+ def parallels?(node = __getnode)
80
+ node.dig("virtualization", "system") == "parallels" && node.dig("virtualization", "role") == "guest"
81
+ end
82
+
83
+ # Determine if the current node is a Parallels Desktop host.
84
+ #
85
+ # @param [Chef::Node] node
86
+ # @since 15.8
87
+ #
88
+ # @return [Boolean]
89
+ # true if the machine is currently running under Parallels Desktop, false
90
+ # otherwise
91
+ #
92
+ def parallels_host?(node = __getnode)
93
+ node.dig("virtualization", "system") == "parallels" && node.dig("virtualization", "role") == "host"
94
+ end
95
+
96
+ # Determine if the current node is a VirtualBox guest.
97
+ #
98
+ # @param [Chef::Node] node
99
+ # @since 15.8
100
+ #
101
+ # @return [Boolean]
102
+ #
103
+ def vbox?(node = __getnode)
104
+ node.dig("virtualization", "system") == "vbox" && node.dig("virtualization", "role") == "guest"
105
+ end
106
+
107
+ # Determine if the current node is a VirtualBox host.
108
+ #
109
+ # @param [Chef::Node] node
110
+ # @since 15.8
111
+ #
112
+ # @return [Boolean]
113
+ #
114
+ def vbox_host?(node = __getnode)
115
+ node.dig("virtualization", "system") == "vbox" && node.dig("virtualization", "role") == "host"
116
+ end
117
+
118
+ # chef-sugar backcompat method
119
+ alias_method :virtualbox?, :vbox?
120
+
121
+ # Determine if the current node is a VMWare guest.
122
+ #
123
+ # @param [Chef::Node] node
124
+ # @since 15.8
125
+ #
126
+ # @return [Boolean]
127
+ #
128
+ def vmware?(node = __getnode)
129
+ node.dig("virtualization", "system") == "vmware" && node.dig("virtualization", "role") == "guest"
130
+ end
131
+
132
+ # Determine if the current node is VMware host.
133
+ #
134
+ # @param [Chef::Node] node
135
+ # @since 15.8
136
+ #
137
+ # @return [Boolean]
138
+ #
139
+ def vmware_host?(node = __getnode)
140
+ node.dig("virtualization", "system") == "vmware" && node.dig("virtualization", "role") == "host"
141
+ end
142
+
143
+ # Determine if the current node is virtualized on VMware Desktop (Fusion/Player/Workstation).
144
+ #
145
+ # @param [Chef::Node] node
146
+ # @since 17.9
147
+ #
148
+ # @return [Boolean]
149
+ #
150
+ def vmware_desktop?(node = __getnode)
151
+ node.dig("virtualization", "system") == "vmware" && node.dig("vmware", "host", "type") == "vmware_desktop"
152
+ end
153
+
154
+ # Determine if the current node is virtualized on VMware vSphere (ESX).
155
+ #
156
+ # @param [Chef::Node] node
157
+ # @since 17.9
158
+ #
159
+ # @return [Boolean]
160
+ #
161
+ def vmware_vsphere?(node = __getnode)
162
+ node.dig("virtualization", "system") == "vmware" && node.dig("vmware", "host", "type") == "vmware_vsphere"
163
+ end
164
+
165
+ # Determine if the current node is an openvz guest.
166
+ #
167
+ # @param [Chef::Node] node
168
+ # @since 15.8
169
+ #
170
+ # @return [Boolean]
171
+ #
172
+ def openvz?(node = __getnode)
173
+ node.dig("virtualization", "system") == "openvz" && node.dig("virtualization", "role") == "guest"
174
+ end
175
+
176
+ # Determine if the current node is an openvz host.
177
+ #
178
+ # @param [Chef::Node] node
179
+ # @since 15.8
180
+ #
181
+ # @return [Boolean]
182
+ #
183
+ def openvz_host?(node = __getnode)
184
+ node.dig("virtualization", "system") == "openvz" && node.dig("virtualization", "role") == "host"
185
+ end
186
+
187
+ # Determine if the current node is running under any virtualization environment
188
+ #
189
+ # @param [Chef::Node] node
190
+ # @since 15.8
191
+ #
192
+ # @return [Boolean]
193
+ #
194
+ def guest?(node = __getnode)
195
+ node.dig("virtualization", "role") == "guest"
196
+ end
197
+
198
+ # chef-sugar backcompat method
199
+ alias_method :virtual?, :guest?
200
+
201
+ # Determine if the current node supports running guests under any virtualization environment
202
+ #
203
+ # @param [Chef::Node] node
204
+ # @since 15.8
205
+ #
206
+ # @return [Boolean]
207
+ #
208
+ def hypervisor?(node = __getnode)
209
+ node.dig("virtualization", "role") == "host"
210
+ end
211
+
212
+ # Determine if the current node is NOT running under any virtualization environment (bare-metal or hypervisor on metal)
213
+ #
214
+ # @param [Chef::Node] node
215
+ # @since 15.8
216
+ #
217
+ # @return [Boolean]
218
+ #
219
+ def physical?(node = __getnode)
220
+ !virtual?(node)
221
+ end
222
+
223
+ # Determine if the current node is running as a vagrant guest.
224
+ #
225
+ # Note that this API is equivalent to just looking for the vagrant user or the
226
+ # vagrantup.com domain in the hostname, which is the best API we have.
227
+ #
228
+ # @param [Chef::Node] node
229
+ # @since 15.8
230
+ #
231
+ # @return [Boolean]
232
+ # true if the machine is currently running vagrant, false
233
+ # otherwise
234
+ #
235
+ def vagrant?(node = __getnode)
236
+ vagrant_key?(node) || vagrant_domain?(node) || vagrant_user?(node)
237
+ end
238
+
239
+ private
240
+
241
+ # Check if the +vagrant+ key exists on the +node+ object. This key is no
242
+ # longer populated by vagrant, but it is kept around for legacy purposes.
243
+ #
244
+ # @param (see vagrant?)
245
+ # @return (see vagrant?)
246
+ #
247
+ def vagrant_key?(node = __getnode)
248
+ node.key?("vagrant")
249
+ end
250
+
251
+ # Check if "vagrantup.com" is included in the node's domain.
252
+ #
253
+ # @param (see vagrant?)
254
+ # @return (see vagrant?)
255
+ #
256
+ def vagrant_domain?(node = __getnode)
257
+ node.key?("domain") && !node["domain"].nil? && node["domain"].include?("vagrantup.com")
258
+ end
259
+
260
+ # Check if the system contains a +vagrant+ user.
261
+ #
262
+ # @param (see vagrant?)
263
+ # @return (see vagrant?)
264
+ #
265
+ def vagrant_user?(node = __getnode)
266
+ !!(Etc.getpwnam("vagrant") rescue nil)
267
+ end
268
+
269
+ extend self
270
+ end
271
+ end
272
+ end