chef-metal 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c05f6095c83aebd085f44c69d10452e2f728a8f
4
- data.tar.gz: 33ba5db04ce1618c3a7afd442c22a8274b99220c
3
+ metadata.gz: 793510893dd7adb4e0d2bfd54f22adab49e0fc15
4
+ data.tar.gz: 23cc9b99b247524ffb35769b1f4c107a0f9414d3
5
5
  SHA512:
6
- metadata.gz: bbee9f82bd18b9b9742b405ba71cf06cbae8460e43776af454116cfd108cb44d7282360617f0e0e6802e06ccb3bb7b90f5d982a16049e3f61bed99ddba46e25d
7
- data.tar.gz: 8f843e5e1c33c312e3e0d4131ea0d736846f5c7af18d766162521d7e106e2ead430e05b614d8ab7f71240580fc25dba2c4bbfe6ffae88472a7d13e325fb8ece2
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
@@ -3,6 +3,8 @@ require 'cheffish/cheffish_server_api'
3
3
 
4
4
  class Chef::Provider::MachineFile < Chef::Provider::LWRPBase
5
5
 
6
+ include ChefMetal::ProviderActionHandler
7
+
6
8
  use_inline_resources
7
9
 
8
10
  def whyrun_supported?
@@ -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
@@ -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
- channel.wait
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 = session.run_powershell_script(command) do |stdout, stderr|
19
- stream_chunk(execute_options, stdout, stderr)
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
@@ -1,3 +1,3 @@
1
1
  module ChefMetal
2
- VERSION = '0.8.1'
2
+ VERSION = '0.8.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-metal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Keiser