Sha256: bcc49ea4c40ea1037f0191de27e06a567d05b90f31cfd285ebc3e119d65c1240

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

require 'chef/provisioning/transport'
require 'chef/mixin/shell_out'
require 'chef/log'

class Chef
module Provisioning
  class Transport
    class Local < Chef::Provisioning::Transport
      include Chef::Mixin::ShellOut

      #
      # Create a new local transport.
      #
      # == Arguments
      #
      # - options: a hash of options for the transport itself, including:
      #   - :prefix: a prefix to send before each command (e.g. "sudo ")
      # - global_config: an options hash that looks suspiciously similar to
      #   Chef::Config, containing at least the key :log_level.
      #
      # The options are used in
      #   Net::SSH.start(host, username, ssh_options)

      def initialize(options, global_config)
        @options = options
        @config = global_config
      end

      attr_reader :options
      attr_reader :config

      def execute(command, execute_options = {})
        Chef::Log.info("Executing #{options[:prefix]}#{command} locally")
        result = shell_out!(command, execute_options)
        Chef::Log.info("Completed #{command} on #{username}@#{host}: exit status #{exitstatus}")
        Chef::Log.debug("Stdout was:\n#{stdout}") if stdout != '' && !options[:stream] && !options[:stream_stdout] && config[:log_level] != :debug
        Chef::Log.info("Stderr was:\n#{stderr}") if stderr != '' && !options[:stream] && !options[:stream_stderr] && config[:log_level] != :debug
        result
      end

      def read_file(path)
        IO.read(path)
      end

      def write_file(path, content)
        IO.write(path, content)
      end

      # TODO do we need to bind_to?  Probably.
      def make_url_available_to_remote(local_url, **options)
        local_url
      end

      def disconnect
      end

      def available?
        true
      end
    end
  end
end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
chef-provisioning-1.0.0.rc.1 lib/chef/provisioning/transport/local.rb