chef-utils 15.7.32 → 15.11.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,40 @@
1
+ #
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require_relative "../internal"
19
+
20
+ module ChefUtils
21
+ module DSL
22
+ module PlatformVersion
23
+ include Internal
24
+
25
+ # Return the platform_version for the node. Acts like a String
26
+ # but also provides a mechanism for checking version constraints.
27
+ #
28
+ # @param [Chef::Node] node the node to check
29
+ # @since 15.8
30
+ #
31
+ # @return [ChefUtils::VersionString]
32
+ #
33
+ def platform_version(node = __getnode)
34
+ ChefUtils::VersionString.new(node["platform_version"])
35
+ end
36
+
37
+ extend self
38
+ end
39
+ end
40
+ end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright 2018-2019, Chef Software Inc.
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,6 +28,8 @@ module ChefUtils
28
28
 
29
29
  # Returns if debian's old rc.d manager is installed (not necessarily the primary init system).
30
30
  #
31
+ # @since 15.5
32
+ #
31
33
  # @return [Boolean]
32
34
  #
33
35
  def debianrcd?
@@ -36,6 +38,8 @@ module ChefUtils
36
38
 
37
39
  # Returns if debian's old invoke rc.d manager is installed (not necessarily the primary init system).
38
40
  #
41
+ # @since 15.5
42
+ #
39
43
  # @return [Boolean]
40
44
  #
41
45
  def invokercd?
@@ -44,6 +48,8 @@ module ChefUtils
44
48
 
45
49
  # Returns if upstart is installed (not necessarily the primary init system).
46
50
  #
51
+ # @since 15.5
52
+ #
47
53
  # @return [Boolean]
48
54
  #
49
55
  def upstart?
@@ -52,6 +58,8 @@ module ChefUtils
52
58
 
53
59
  # Returns if insserv is installed (not necessarily the primary init system).
54
60
  #
61
+ # @since 15.5
62
+ #
55
63
  # @return [Boolean]
56
64
  #
57
65
  def insserv?
@@ -60,12 +68,23 @@ module ChefUtils
60
68
 
61
69
  # Returns if redhat's init system is installed (not necessarily the primary init system).
62
70
  #
71
+ # @since 15.5
72
+ #
63
73
  # @return [Boolean]
64
74
  #
65
75
  def redhatrcd?
66
76
  file_exist?("/sbin/chkconfig")
67
77
  end
68
78
 
79
+ #
80
+ # Returns if a particular service exists for a particular service init system. Init systems may be :initd, :upstart, :etc_rcd, :xinetd, and :systemd. Example: service_script_exist?(:systemd, 'ntpd')
81
+ #
82
+ # @param [Symbol] type The type of init system. :initd, :upstart, :xinetd, :etc_rcd, or :systemd
83
+ # @param [String] script The name of the service
84
+ # @since 15.5
85
+ #
86
+ # @return [Boolean]
87
+ #
69
88
  def service_script_exist?(type, script)
70
89
  case type
71
90
  when :initd
@@ -1,5 +1,5 @@
1
- #--
2
- # Copyright:: Copyright 2019-2019, Chef Software Inc.
1
+ #
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -0,0 +1,249 @@
1
+ #
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require_relative "../internal"
19
+
20
+ module ChefUtils
21
+ module DSL
22
+ module Virtualization
23
+ include Internal
24
+
25
+ # Determine if the current node is a KVM guest.
26
+ #
27
+ # @param [Chef::Node] node
28
+ # @since 15.8
29
+ #
30
+ # @return [Boolean]
31
+ #
32
+ def kvm?(node = __getnode)
33
+ node.dig("virtualization", "system") == "kvm" && node.dig("virtualization", "role") == "guest"
34
+ end
35
+
36
+ # Determine if the current node is a KVM host.
37
+ #
38
+ # @param [Chef::Node] node
39
+ # @since 15.8
40
+ #
41
+ # @return [Boolean]
42
+ #
43
+ def kvm_host?(node = __getnode)
44
+ node.dig("virtualization", "system") == "kvm" && node.dig("virtualization", "role") == "host"
45
+ end
46
+
47
+ # Determine if the current node is running in a linux container.
48
+ #
49
+ # @param [Chef::Node] node
50
+ # @since 15.8
51
+ #
52
+ # @return [Boolean]
53
+ #
54
+ def lxc?(node = __getnode)
55
+ node.dig("virtualization", "system") == "lxc" && node.dig("virtualization", "role") == "guest"
56
+ end
57
+
58
+ # Determine if the current node is a linux container host.
59
+ #
60
+ # @param [Chef::Node] node
61
+ # @since 15.8
62
+ #
63
+ # @return [Boolean]
64
+ #
65
+ def lxc_host?(node = __getnode)
66
+ node.dig("virtualization", "system") == "lxc" && node.dig("virtualization", "role") == "host"
67
+ end
68
+
69
+ # Determine if the current node is running under Parallels Desktop.
70
+ #
71
+ # @param [Chef::Node] node
72
+ # @since 15.8
73
+ #
74
+ # @return [Boolean]
75
+ # true if the machine is currently running under Parallels Desktop, false
76
+ # otherwise
77
+ #
78
+ def parallels?(node = __getnode)
79
+ node.dig("virtualization", "system") == "parallels" && node.dig("virtualization", "role") == "guest"
80
+ end
81
+
82
+ # Determine if the current node is a Parallels Desktop host.
83
+ #
84
+ # @param [Chef::Node] node
85
+ # @since 15.8
86
+ #
87
+ # @return [Boolean]
88
+ # true if the machine is currently running under Parallels Desktop, false
89
+ # otherwise
90
+ #
91
+ def parallels_host?(node = __getnode)
92
+ node.dig("virtualization", "system") == "parallels" && node.dig("virtualization", "role") == "host"
93
+ end
94
+
95
+ # Determine if the current node is a VirtualBox guest.
96
+ #
97
+ # @param [Chef::Node] node
98
+ # @since 15.8
99
+ #
100
+ # @return [Boolean]
101
+ #
102
+ def vbox?(node = __getnode)
103
+ node.dig("virtualization", "system") == "vbox" && node.dig("virtualization", "role") == "guest"
104
+ end
105
+
106
+ # Determine if the current node is a VirtualBox host.
107
+ #
108
+ # @param [Chef::Node] node
109
+ # @since 15.8
110
+ #
111
+ # @return [Boolean]
112
+ #
113
+ def vbox_host?(node = __getnode)
114
+ node.dig("virtualization", "system") == "vbox" && node.dig("virtualization", "role") == "host"
115
+ end
116
+
117
+ # chef-sugar backcompat method
118
+ alias_method :virtualbox?, :vbox?
119
+
120
+ # Determine if the current node is a VMWare guest.
121
+ #
122
+ # @param [Chef::Node] node
123
+ # @since 15.8
124
+ #
125
+ # @return [Boolean]
126
+ #
127
+ def vmware?(node = __getnode)
128
+ node.dig("virtualization", "system") == "vmware" && node.dig("virtualization", "role") == "guest"
129
+ end
130
+
131
+ # Determine if the current node is VMware host.
132
+ #
133
+ # @param [Chef::Node] node
134
+ # @since 15.8
135
+ #
136
+ # @return [Boolean]
137
+ #
138
+ def vmware_host?(node = __getnode)
139
+ node.dig("virtualization", "system") == "vmware" && node.dig("virtualization", "role") == "host"
140
+ end
141
+
142
+ # Determine if the current node is an openvz guest.
143
+ #
144
+ # @param [Chef::Node] node
145
+ # @since 15.8
146
+ #
147
+ # @return [Boolean]
148
+ #
149
+ def openvz?(node = __getnode)
150
+ node.dig("virtualization", "system") == "openvz" && node.dig("virtualization", "role") == "guest"
151
+ end
152
+
153
+ # Determine if the current node is an openvz host.
154
+ #
155
+ # @param [Chef::Node] node
156
+ # @since 15.8
157
+ #
158
+ # @return [Boolean]
159
+ #
160
+ def openvz_host?(node = __getnode)
161
+ node.dig("virtualization", "system") == "openvz" && node.dig("virtualization", "role") == "host"
162
+ end
163
+
164
+ # Determine if the current node is running under any virutalization environment
165
+ #
166
+ # @param [Chef::Node] node
167
+ # @since 15.8
168
+ #
169
+ # @return [Boolean]
170
+ #
171
+ def guest?(node = __getnode)
172
+ node.dig("virtualization", "role") == "guest"
173
+ end
174
+
175
+ # chef-sugar backcompat method
176
+ alias_method :virtual?, :guest?
177
+
178
+ # Determine if the current node supports running guests under any virtualization environment
179
+ #
180
+ # @param [Chef::Node] node
181
+ # @since 15.8
182
+ #
183
+ # @return [Boolean]
184
+ #
185
+ def hypervisor?(node = __getnode)
186
+ node.dig("virtualization", "role") == "host"
187
+ end
188
+
189
+ # Determine if the current node is NOT running under any virtualization environment (bare-metal or hypervisor on metal)
190
+ #
191
+ # @param [Chef::Node] node
192
+ # @since 15.8
193
+ #
194
+ # @return [Boolean]
195
+ #
196
+ def physical?(node = __getnode)
197
+ !virtual?(node)
198
+ end
199
+
200
+ # Determine if the current node is running as a vagrant guest.
201
+ #
202
+ # Note that this API is equivalent to just looking for the vagrant user or the
203
+ # vagrantup.com domain in the hostname, which is the best API we have.
204
+ #
205
+ # @param [Chef::Node] node
206
+ # @since 15.8
207
+ #
208
+ # @return [Boolean]
209
+ # true if the machine is currently running vagrant, false
210
+ # otherwise
211
+ #
212
+ def vagrant?(node = __getnode)
213
+ vagrant_key?(node) || vagrant_domain?(node) || vagrant_user?(node)
214
+ end
215
+
216
+ private
217
+
218
+ # Check if the +vagrant+ key exists on the +node+ object. This key is no
219
+ # longer populated by vagrant, but it is kept around for legacy purposes.
220
+ #
221
+ # @param (see vagrant?)
222
+ # @return (see vagrant?)
223
+ #
224
+ def vagrant_key?(node = __getnode)
225
+ node.key?("vagrant")
226
+ end
227
+
228
+ # Check if "vagrantup.com" is included in the node's domain.
229
+ #
230
+ # @param (see vagrant?)
231
+ # @return (see vagrant?)
232
+ #
233
+ def vagrant_domain?(node = __getnode)
234
+ node.key?("domain") && !node["domain"].nil? && node["domain"].include?("vagrantup.com")
235
+ end
236
+
237
+ # Check if the system contains a +vagrant+ user.
238
+ #
239
+ # @param (see vagrant?)
240
+ # @return (see vagrant?)
241
+ #
242
+ def vagrant_user?(node = __getnode)
243
+ !!(Etc.getpwnam("vagrant") rescue nil)
244
+ end
245
+
246
+ extend self
247
+ end
248
+ end
249
+ end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright 2018-2019, Chef Software Inc.
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright 2020, Chef Software Inc.
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,11 +20,14 @@ require_relative "../internal"
20
20
  module ChefUtils
21
21
  module DSL
22
22
  module Windows
23
+ require "chef-utils/version_string"
24
+
23
25
  include Internal
24
26
 
25
27
  # Determine if the current node is Windows Server Core.
26
28
  #
27
- # @param [Chef::Node] node
29
+ # @param [Chef::Node] node the node to check
30
+ # @since 15.7
28
31
  #
29
32
  # @return [Boolean]
30
33
  #
@@ -32,9 +35,10 @@ module ChefUtils
32
35
  node["kernel"]["server_core"] == true
33
36
  end
34
37
 
35
- # Determine if the current node is Windows Workstation
38
+ # Determine if the current node is Windows Workstation.
36
39
  #
37
- # @param [Chef::Node] node
40
+ # @param [Chef::Node] node the node to check
41
+ # @since 15.7
38
42
  #
39
43
  # @return [Boolean]
40
44
  #
@@ -42,9 +46,10 @@ module ChefUtils
42
46
  node["kernel"]["product_type"] == "Workstation"
43
47
  end
44
48
 
45
- # Determine if the current node is Windows Server
49
+ # Determine if the current node is Windows Server.
46
50
  #
47
- # @param [Chef::Node] node
51
+ # @param [Chef::Node] node the node to check
52
+ # @since 15.7
48
53
  #
49
54
  # @return [Boolean]
50
55
  #
@@ -52,6 +57,28 @@ module ChefUtils
52
57
  node["kernel"]["product_type"] == "Server"
53
58
  end
54
59
 
60
+ # Determine the current Windows NT version. The NT version often differs from the marketing version, but offers a good way to find desktop and server releases that are based on the same codebase. IE: NT 6.3 is Windows 8.1 and Windows 2012 R2.
61
+ #
62
+ # @param [Chef::Node] node the node to check
63
+ # @since 15.8
64
+ #
65
+ # @return [ChefUtils::VersionString]
66
+ #
67
+ def windows_nt_version(node = __getnode)
68
+ ChefUtils::VersionString.new(node["os_version"])
69
+ end
70
+
71
+ # Determine the installed version of PowerShell.
72
+ #
73
+ # @param [Chef::Node] node the node to check
74
+ # @since 15.8
75
+ #
76
+ # @return [ChefUtils::VersionString]
77
+ #
78
+ def powershell_version(node = __getnode)
79
+ ChefUtils::VersionString.new(node["languages"]["powershell"]["version"])
80
+ end
81
+
55
82
  extend self
56
83
  end
57
84
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright 2018-2019, Chef Software Inc.
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");