chef-metal 0.8.1 → 0.8.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/bin/metal +6 -1
- data/lib/chef/provider/machine_file.rb +2 -0
- data/lib/chef/resource/machine.rb +4 -0
- data/lib/chef_metal/convergence_strategy/precreate_chef_objects.rb +14 -0
- data/lib/chef_metal/machine/unix_machine.rb +1 -1
- data/lib/chef_metal/transport.rb +23 -0
- data/lib/chef_metal/transport/ssh.rb +6 -4
- data/lib/chef_metal/transport/winrm.rb +5 -2
- data/lib/chef_metal/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 793510893dd7adb4e0d2bfd54f22adab49e0fc15
|
4
|
+
data.tar.gz: 23cc9b99b247524ffb35769b1f4c107a0f9414d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6738450b250a9ec88c298d12166f7069fc79e4eea8bcab8c5a5d7a6f98ab77bfad43bc0ba85a57e8a8524f6a1bb26585c03dac2279d0d0d48a11f68b83f72aa0
|
7
|
+
data.tar.gz: 33f56df60eed263b8c49edbbeea700a551c219c11469eac9cb3c22405c004e6a1433a8793017a4b4381d313d15b15cd963c70c7e127ff9aaf84eeb682cd17187
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Chef Metal Changelog
|
2
2
|
|
3
|
+
## 0.8.2 (4/9/2014)
|
4
|
+
|
5
|
+
- Add timeout support to execute
|
6
|
+
- Fix machine_file resource
|
7
|
+
- Add ohai_hints DSL to machine resource (@xorl)
|
8
|
+
|
3
9
|
## 0.8.1 (4/9/2014)
|
4
10
|
|
5
11
|
- Bug: error! was not raising an error in the SSH and WinRM transports
|
data/bin/metal
CHANGED
@@ -71,6 +71,11 @@ class ChefMetal::Application < Chef::Application
|
|
71
71
|
:boolean => true,
|
72
72
|
:description => "Whether to stream output from the machine (default: true)"
|
73
73
|
|
74
|
+
option :timeout,
|
75
|
+
:long => "--timeout",
|
76
|
+
:default => 15*60,
|
77
|
+
:description => "Time to wait for program to execute, or 0 for no timeout (default: 15 minutes)"
|
78
|
+
|
74
79
|
def reconfigure
|
75
80
|
super
|
76
81
|
|
@@ -117,7 +122,7 @@ class ChefMetal::Application < Chef::Application
|
|
117
122
|
when 'execute'
|
118
123
|
each_machine(cli_arguments.shift) do |machine, provisioner|
|
119
124
|
puts "[#{machine.node['name']}] running '#{cli_arguments.join(' ')}'"
|
120
|
-
result = machine.execute(action_handler, cli_arguments.join(' '), :read_only => config[:read_only], :stream => config[:stream])
|
125
|
+
result = machine.execute(action_handler, cli_arguments.join(' '), :read_only => config[:read_only], :stream => config[:stream], :timeout => config[:timeout])
|
121
126
|
puts result.stdout if result.stdout != '' && !config[:stream] && Chef::Config.log_level != :debug
|
122
127
|
STDERR.puts result.stderr if result.stderr != '' && !config[:stream] && Chef::Config.log_level != :debug
|
123
128
|
exit_code = result.exitstatus if result.exitstatus != 0
|
@@ -45,6 +45,10 @@ class Chef::Resource::Machine < Chef::Resource::LWRPBase
|
|
45
45
|
attribute :admin, :kind_of => [TrueClass, FalseClass]
|
46
46
|
attribute :validator, :kind_of => [TrueClass, FalseClass]
|
47
47
|
|
48
|
+
# Client Ohai hints, allows machine to enable hints
|
49
|
+
# e.g. ohai_hint 'ec2' => { 'a' => 'b' } creates file ec2.json with json contents { 'a': 'b' }
|
50
|
+
attribute :ohai_hints, :kind_of => Hash
|
51
|
+
|
48
52
|
# Allows you to turn convergence off in the :create action by writing "converge false"
|
49
53
|
# or force it with "true"
|
50
54
|
attribute :converge, :kind_of => [TrueClass, FalseClass]
|
@@ -24,6 +24,9 @@ module ChefMetal
|
|
24
24
|
chef_server_url = machine_resource.chef_server[:chef_server_url]
|
25
25
|
chef_server_url = machine.make_url_available_to_remote(chef_server_url)
|
26
26
|
|
27
|
+
#Support for multiple ohai hints, required on some platforms
|
28
|
+
create_ohai_files(action_handler, machine, machine_resource)
|
29
|
+
|
27
30
|
# Create client.rb and client.pem on machine
|
28
31
|
content = client_rb_content(chef_server_url, machine.node['name'])
|
29
32
|
machine.write_file(action_handler, client_rb_path, content, :ensure_dir => true)
|
@@ -103,6 +106,17 @@ module ChefMetal
|
|
103
106
|
end
|
104
107
|
end
|
105
108
|
|
109
|
+
# Create the ohai file(s)
|
110
|
+
def create_ohai_files(action_handler, machine, machine_resource)
|
111
|
+
if machine_resource.ohai_hints
|
112
|
+
machine_resource.ohai_hints.each_pair do |hint, data|
|
113
|
+
# The location of the ohai hint
|
114
|
+
ohai_hint = "/etc/chef/ohai/hints/#{hint}.json"
|
115
|
+
machine.write_file(action_handler, ohai_hint, data.to_json, :ensure_dir => true)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
106
120
|
def create_chef_objects(action_handler, machine, machine_resource, public_key)
|
107
121
|
# Save the node and create the client keys and client.
|
108
122
|
ChefMetal.inline_resource(action_handler) do
|
@@ -56,7 +56,7 @@ module ChefMetal
|
|
56
56
|
def create_dir(action_handler, path)
|
57
57
|
if !file_exists?(path)
|
58
58
|
action_handler.perform_action "create directory #{path} on #{node['name']}" do
|
59
|
-
transport.execute("mkdir #{path}").error!
|
59
|
+
transport.execute("mkdir -p #{path}").error!
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
data/lib/chef_metal/transport.rb
CHANGED
@@ -1,5 +1,20 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
|
1
3
|
module ChefMetal
|
2
4
|
class Transport
|
5
|
+
DEFAULT_TIMEOUT = 15*60
|
6
|
+
|
7
|
+
# Execute a program on the remote host.
|
8
|
+
#
|
9
|
+
# == Arguments
|
10
|
+
# command: command to run. May be a shell-escaped string or a pre-split array containing [PROGRAM, ARG1, ARG2, ...].
|
11
|
+
# options: hash of options, including but not limited to:
|
12
|
+
# :timeout => NUM_SECONDS - time to wait before program finishes (throws an exception otherwise). Set to nil or 0 to run with no timeout. Defaults to 15 minutes.
|
13
|
+
# :stream => BOOLEAN - true to stream stdout and stderr to the console.
|
14
|
+
# :stream => BLOCK - block to stream stdout and stderr to (block.call(stdout_chunk, stderr_chunk))
|
15
|
+
# :stream_stdout => FD - FD to stream stdout to (defaults to IO.stdout)
|
16
|
+
# :stream_stderr => FD - FD to stream stderr to (defaults to IO.stderr)
|
17
|
+
# :read_only => BOOLEAN - true if command is guaranteed not to change system state (useful for Docker)
|
3
18
|
def execute(command, options = {})
|
4
19
|
raise "execute not overridden on #{self.class}"
|
5
20
|
end
|
@@ -55,5 +70,13 @@ module ChefMetal
|
|
55
70
|
end
|
56
71
|
end
|
57
72
|
end
|
73
|
+
|
74
|
+
def with_execute_timeout(options, &block)
|
75
|
+
Timeout::timeout(execute_timeout(options), &block)
|
76
|
+
end
|
77
|
+
|
78
|
+
def execute_timeout(options)
|
79
|
+
options.has_key?(:timeout) ? options[:timeout] : DEFAULT_TIMEOUT
|
80
|
+
end
|
58
81
|
end
|
59
82
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'chef_metal/transport'
|
2
2
|
require 'uri'
|
3
3
|
require 'socket'
|
4
|
+
require 'timeout'
|
4
5
|
|
5
6
|
module ChefMetal
|
6
7
|
class Transport
|
@@ -32,7 +33,6 @@ module ChefMetal
|
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
|
-
|
36
36
|
channel.exec("#{options[:prefix]}#{command}") do |ch, success|
|
37
37
|
raise "could not execute command: #{command.inspect}" unless success
|
38
38
|
|
@@ -52,11 +52,13 @@ module ChefMetal
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
|
55
|
+
with_execute_timeout(execute_options) do
|
56
|
+
channel.wait
|
57
|
+
end
|
56
58
|
|
57
59
|
Chef::Log.info("Completed #{command} on #{username}@#{host}: exit status #{exitstatus}")
|
58
|
-
Chef::Log.debug("Stdout was:\n#{stdout}") if stdout != '' && !options[:stream] && !options[:stream_stdout]
|
59
|
-
Chef::Log.info("Stderr was:\n#{stderr}") if stderr != '' && !options[:stream] && !options[:stream_stderr]
|
60
|
+
Chef::Log.debug("Stdout was:\n#{stdout}") if stdout != '' && !options[:stream] && !options[:stream_stdout] && Chef::Config.log_level != :debug
|
61
|
+
Chef::Log.info("Stderr was:\n#{stderr}") if stderr != '' && !options[:stream] && !options[:stream_stderr] && Chef::Config.log_level != :debug
|
60
62
|
SSHResult.new(command, execute_options, stdout, stderr, exitstatus)
|
61
63
|
end
|
62
64
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'chef_metal/transport'
|
2
2
|
require 'base64'
|
3
|
+
require 'timeout'
|
3
4
|
|
4
5
|
module ChefMetal
|
5
6
|
class Transport
|
@@ -15,8 +16,10 @@ module ChefMetal
|
|
15
16
|
attr_reader :options
|
16
17
|
|
17
18
|
def execute(command, execute_options = {})
|
18
|
-
output =
|
19
|
-
|
19
|
+
output = with_execute_timeout(execute_options) do
|
20
|
+
session.run_powershell_script(command) do |stdout, stderr|
|
21
|
+
stream_chunk(execute_options, stdout, stderr)
|
22
|
+
end
|
20
23
|
end
|
21
24
|
WinRMResult.new(command, execute_options, output)
|
22
25
|
end
|
data/lib/chef_metal/version.rb
CHANGED