chef-sugar-sre 5.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,151 @@
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 'mixlib/shellout'
18
+ require 'pathname'
19
+
20
+ class Chef
21
+ module Sugar
22
+ module Shell
23
+ extend self
24
+
25
+ #
26
+ # Finds a command in $PATH
27
+ #
28
+ # @param [String] cmd
29
+ # the command to find
30
+ #
31
+ # @return [String, nil]
32
+ #
33
+ def sugar_which(cmd)
34
+ if Pathname.new(cmd).absolute?
35
+ File.executable?(cmd) ? cmd : nil
36
+ else
37
+ paths = ENV['PATH'].split(::File::PATH_SEPARATOR) + %w(/bin /usr/bin /sbin /usr/sbin)
38
+
39
+ paths.each do |path|
40
+ possible = File.join(path, cmd)
41
+ return possible if File.executable?(possible)
42
+ end
43
+
44
+ nil
45
+ end
46
+ end
47
+
48
+ #
49
+ # The platform-specific output path to +/dev/null+.
50
+ #
51
+ # @return [String]
52
+ #
53
+ def dev_null(node)
54
+ if defined?(ChefUtils)
55
+ ChefUtils.windows?(node) ? 'NUL' : '/dev/null'
56
+ else
57
+ Chef::Sugar::PlatformFamily.windows?(node) ? 'NUL' : '/dev/null'
58
+ end
59
+ end
60
+
61
+ #
62
+ # Boolean method to check if a command line utility is installed.
63
+ #
64
+ # @param [String] cmd
65
+ # the command to find
66
+ #
67
+ # @return [Boolean]
68
+ # true if the command is found in the path, false otherwise
69
+ #
70
+ def installed?(cmd)
71
+ !sugar_which(cmd).nil?
72
+ end
73
+
74
+ #
75
+ # Checks if the given binary is installed and exists at the given
76
+ # version. Also see {version_for}.
77
+ #
78
+ # @param [String] cmd
79
+ # the command to check
80
+ # @param [String] expected_version
81
+ # the version to check
82
+ # @param [String] flag
83
+ # the flag to use to check the version of the binary
84
+ #
85
+ # @return [Boolean]
86
+ # true if the command exists and is at the given version, false
87
+ # otherwise
88
+ #
89
+ def installed_at_version?(cmd, expected_version, flag = '--version')
90
+ return false if !installed?(cmd)
91
+
92
+ version = version_for(cmd, flag)
93
+ return false if version.nil?
94
+
95
+ if expected_version.is_a?(Regexp)
96
+ !version.match(expected_version).nil?
97
+ else
98
+ version.include?(expected_version)
99
+ end
100
+ end
101
+
102
+ #
103
+ # The version for a given command. This method does NOT check if the
104
+ # command exists! It is assumed the command existence has been
105
+ # checked with +sugar_which+ or similar. To simply check if an installed
106
+ # version is acceptable, please see {installed_at_version}.
107
+ #
108
+ # Assumptions:
109
+ # 1. The command exists.
110
+ # 2. The command outputs version information to +$stdout+ or +$stderr+.
111
+ # Did you know that java outputs its version to $stderr?
112
+ #
113
+ #
114
+ # @param [String] cmd
115
+ # the command to find the version for
116
+ # @param [String] flag
117
+ # the flag to use to get the version
118
+ #
119
+ # @return [String]
120
+ # the entire output of the version command (stderr and stdout)
121
+ #
122
+ def version_for(cmd, flag = '--version')
123
+ cmd = Mixlib::ShellOut.new("#{cmd} #{flag}")
124
+ cmd.run_command
125
+ cmd.error!
126
+ [cmd.stdout.strip, cmd.stderr.strip].join("\n")
127
+ end
128
+ end
129
+
130
+ module DSL
131
+ # @see Chef::Sugar::Shell#sugar_which
132
+ def sugar_which(cmd); Chef::Sugar::Shell.sugar_which(cmd); end
133
+
134
+ # @see Chef::Sugar::Shell#dev_null
135
+ def dev_null; Chef::Sugar::Shell.dev_null(node); end
136
+
137
+ # @see Chef::Sugar::Shell#installed?
138
+ def installed?(cmd); Chef::Sugar::Shell.installed?(cmd); end
139
+
140
+ # @see Chef::Sugar::Shell#installed_at_version?
141
+ def installed_at_version?(cmd, version, flag = '--version')
142
+ Chef::Sugar::Shell.installed_at_version?(cmd, version, flag)
143
+ end
144
+
145
+ # @see Chef::Sugar::Shell#version_for
146
+ def version_for(cmd, flag = '--version')
147
+ Chef::Sugar::Shell.version_for(cmd, flag)
148
+ end
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,77 @@
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 Vagrant
20
+ extend self
21
+
22
+ #
23
+ # Determine if the current node is running in vagrant mode.
24
+ #
25
+ # @param [Chef::Node] node
26
+ #
27
+ # @return [Boolean]
28
+ # true if the machine is currently running vagrant, false
29
+ # otherwise
30
+ #
31
+ def vagrant?(node)
32
+ vagrant_key?(node) || vagrant_domain?(node) || vagrant_user?(node)
33
+ end
34
+
35
+ private
36
+
37
+ #
38
+ # Check if the +vagrant+ key exists on the +node+ object. This key is no
39
+ # longer populated by vagrant, but it is kept around for legacy purposes.
40
+ #
41
+ # @param (see vagrant?)
42
+ # @return (see vagrant?)
43
+ #
44
+ def vagrant_key?(node)
45
+ node.key?('vagrant')
46
+ end
47
+
48
+ #
49
+ # Check if "vagrantup.com" is included in the node's domain. Technically,
50
+ # this would make Chef Sugar falsely detect +vagrant?+ on any of
51
+ # Hashicorp's servers. But if that edge case becomes a serious problem,
52
+ # @mitchellh has my phone number.
53
+ #
54
+ # @param (see vagrant?)
55
+ # @return (see vagrant?)
56
+ #
57
+ def vagrant_domain?(node)
58
+ node.key?('domain') && !node['domain'].nil? && node['domain'].include?('vagrantup.com')
59
+ end
60
+
61
+ #
62
+ # Check if the system contains a +vagrant+ user.
63
+ #
64
+ # @param (see vagrant?)
65
+ # @return (see vagrant?)
66
+ #
67
+ def vagrant_user?(node)
68
+ node.key?('etc') && node['etc'].key?('passwd') && node['etc']['passwd'].key?('vagrant')
69
+ end
70
+ end
71
+
72
+ module DSL
73
+ # @see Chef::Sugar::Vagrant#vagrant?
74
+ def vagrant?; Chef::Sugar::Vagrant.vagrant?(node); end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,21 @@
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
+ VERSION = "5.1.13"
20
+ end
21
+ end
@@ -0,0 +1,151 @@
1
+ #
2
+ # Copyright 2014, Joseph J. Nuspl Jr. <nuspl@nvwls.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 Virtualization
20
+ extend self
21
+
22
+ #
23
+ # Determine if the current node is running under KVM.
24
+ #
25
+ # @param [Chef::Node] node
26
+ #
27
+ # @return [Boolean]
28
+ # true if the machine is currently running under KVM, false
29
+ # otherwise
30
+ #
31
+ def kvm?(node)
32
+ node.key?('virtualization') && node['virtualization']['system'] == 'kvm'
33
+ end
34
+
35
+ #
36
+ # Determine if the current node is running in a linux container.
37
+ #
38
+ # @param [Chef::Node] node
39
+ #
40
+ # @return [Boolean]
41
+ # true if the machine is currently running in a container, false
42
+ # otherwise
43
+ #
44
+ def lxc?(node)
45
+ node.key?('virtualization') && node['virtualization']['system'] == 'lxc'
46
+ end
47
+
48
+ #
49
+ # Determine if the current node is running under Parallels Desktop.
50
+ #
51
+ # @param [Chef::Node] node
52
+ #
53
+ # @return [Boolean]
54
+ # true if the machine is currently running under Parallels Desktop, false
55
+ # otherwise
56
+ #
57
+ def parallels?(node)
58
+ node.key?('virtualization') && node['virtualization']['system'] == 'parallels'
59
+ end
60
+
61
+ #
62
+ # Determine if the current node is running under VirtualBox.
63
+ #
64
+ # @param [Chef::Node] node
65
+ #
66
+ # @return [Boolean]
67
+ # true if the machine is currently running under VirtualBox, false
68
+ # otherwise
69
+ #
70
+ def virtualbox?(node)
71
+ node.key?('virtualization') && node['virtualization']['system'] == 'vbox'
72
+ end
73
+
74
+ #
75
+ # Determine if the current node is running under VMware.
76
+ #
77
+ # @param [Chef::Node] node
78
+ #
79
+ # @return [Boolean]
80
+ # true if the machine is currently running under VMware, false
81
+ # otherwise
82
+ #
83
+ def vmware?(node)
84
+ node.key?('virtualization') && node['virtualization']['system'] == 'vmware'
85
+ end
86
+
87
+ #
88
+ # Determine if the current node is running under openvz.
89
+ #
90
+ # @param [Chef::Node] node
91
+ #
92
+ # @return [Boolean]
93
+ # true if the machine is currently running under openvz, false
94
+ # otherwise
95
+ #
96
+ def openvz?(node)
97
+ node.key?('virtualization') && node['virtualization']['system'] == 'openvz'
98
+ end
99
+
100
+ def virtual?(node)
101
+ openvz?(node) || vmware?(node) || virtualbox?(node) || parallels?(node) || lxc?(node) || kvm?(node)
102
+ end
103
+
104
+ def physical?(node)
105
+ !virtual?(node)
106
+ end
107
+ end
108
+
109
+ module DSL
110
+ # @see Chef::Sugar::Virtualization#kvm?
111
+ def kvm?
112
+ Chef::Sugar::Virtualization.kvm?(node)
113
+ end
114
+
115
+ # @see Chef::Sugar::Virtualization#lxc?
116
+ def lxc?
117
+ Chef::Sugar::Virtualization.lxc?(node)
118
+ end
119
+
120
+ # @see Chef::Sugar::Virtualization#parallels?
121
+ def parallels?
122
+ Chef::Sugar::Virtualization.parallels?(node)
123
+ end
124
+
125
+ # @see Chef::Sugar::Virtualization#virtualbox?
126
+ def virtualbox?
127
+ Chef::Sugar::Virtualization.virtualbox?(node)
128
+ end
129
+
130
+ # @see Chef::Sugar::Virtualization#vmware?
131
+ def vmware?
132
+ Chef::Sugar::Virtualization.vmware?(node)
133
+ end
134
+
135
+ # @see Chef::Sugar::Virtualization#openvz?
136
+ def openvz?
137
+ Chef::Sugar::Virtualization.openvz?(node)
138
+ end
139
+
140
+ # @see Chef::Sugar::Virtualization#virtual?
141
+ def virtual?
142
+ Chef::Sugar::Virtualization.virtual?(node)
143
+ end
144
+
145
+ # @see Chef::Sugar::Virtualization#physical?
146
+ def physical?
147
+ Chef::Sugar::Virtualization.physical?(node)
148
+ end
149
+ end
150
+ end
151
+ 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)
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chef-sugar-sre
3
+ version: !ruby/object:Gem::Version
4
+ version: 5.1.13
5
+ platform: ruby
6
+ authors:
7
+ - Seth Vargo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A series of helpful sugar of the Chef core and other resources to make
14
+ a cleaner, more lean recipe DSL, enforce DRY principles, and make writing Chef recipes
15
+ an awesome experience! [Forked by Combell SRE for Chef 16]
16
+ email:
17
+ - sethvargo@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - LICENSE
23
+ - lib/chef/sugar.rb
24
+ - lib/chef/sugar/architecture.rb
25
+ - lib/chef/sugar/cloud.rb
26
+ - lib/chef/sugar/constraints.rb
27
+ - lib/chef/sugar/constraints_dsl.rb
28
+ - lib/chef/sugar/core_extensions.rb
29
+ - lib/chef/sugar/core_extensions/array.rb
30
+ - lib/chef/sugar/core_extensions/object.rb
31
+ - lib/chef/sugar/core_extensions/string.rb
32
+ - lib/chef/sugar/data_bag.rb
33
+ - lib/chef/sugar/deprecation.rb
34
+ - lib/chef/sugar/docker.rb
35
+ - lib/chef/sugar/filters.rb
36
+ - lib/chef/sugar/init.rb
37
+ - lib/chef/sugar/ip.rb
38
+ - lib/chef/sugar/kernel.rb
39
+ - lib/chef/sugar/kitchen.rb
40
+ - lib/chef/sugar/node.rb
41
+ - lib/chef/sugar/platform.rb
42
+ - lib/chef/sugar/platform_family.rb
43
+ - lib/chef/sugar/ruby.rb
44
+ - lib/chef/sugar/run_context.rb
45
+ - lib/chef/sugar/shell.rb
46
+ - lib/chef/sugar/vagrant.rb
47
+ - lib/chef/sugar/version.rb
48
+ - lib/chef/sugar/virtualization.rb
49
+ homepage: https://github.com/chef/chef-sugar
50
+ licenses:
51
+ - Apache-2.0
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '2.3'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.0.3
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: A collection of helper methods and modules that make working with Chef recipes
72
+ awesome.
73
+ test_files: []