Class: Kitchen::Provisioner::Base

Inherits:
Object
  • Object
show all
Includes:
Configurable, Logging
Defined in:
lib/kitchen/provisioner/base.rb

Overview

Base class for a provisioner.

Author:

Direct Known Subclasses

ChefBase, Dummy, Shell

Instance Attribute Summary

Attributes included from Configurable

#instance

Instance Method Summary collapse

Methods included from Logging

#banner, #debug, #error, #fatal, #info, #warn

Methods included from Configurable

#[], #calculate_path, #config_keys, #diagnose, included

Constructor Details

#initialize(config = {}) ⇒ Base

Constructs a new provisioner by providing a configuration hash.

Parameters:

  • config (Hash) (defaults to: {})

    initial provided configuration



39
40
41
# File 'lib/kitchen/provisioner/base.rb', line 39

def initialize(config = {})
  init_config(config)
end

Instance Method Details

#cleanup_sandboxObject

Deletes the sandbox path. Without calling this method, the sandbox path will persist after the process terminates. In other words, cleanup is explicit. This method is safe to call multiple times.



139
140
141
142
143
144
# File 'lib/kitchen/provisioner/base.rb', line 139

def cleanup_sandbox
  return if sandbox_path.nil?

  debug("Cleaning up local sandbox in #{sandbox_path}")
  FileUtils.rmtree(sandbox_path)
end

#create_sandboxObject

Creates a temporary directory on the local workstation into which provisioner related files and directories can be copied or created. The contents of this directory will be copied over to the instance before invoking the provisioner's run command. After this method completes, it is expected that the contents of the sandbox is complete and ready for copy to the remote instance.

Note: any subclasses would be well advised to call super first when overriding this method, for example:

Examples:

overriding #create_sandbox


class MyProvisioner < Kitchen::Provisioner::Base
  def create_sandbox
    super
    # any further file copies, preparations, etc.
  end
end


117
118
119
120
121
122
# File 'lib/kitchen/provisioner/base.rb', line 117

def create_sandbox
  @sandbox_path = Dir.mktmpdir("#{instance.name}-sandbox-")
  File.chmod(0755, sandbox_path)
  info("Preparing files for transfer")
  debug("Creating local sandbox in #{sandbox_path}")
end

#finalize_config!(instance) ⇒ self

Performs any final configuration required for the provisioner to do its work. A reference to an Instance is required as configuration dependant data may need access through an Instance. This also acts as a hook point where the object may wish to perform other last minute checks, valiations, or configuration expansions.

Parameters:

  • instance (Instance)

    an associated instance

Returns:

  • (self)

    itself, used for chaining

Raises:



52
53
54
55
56
# File 'lib/kitchen/provisioner/base.rb', line 52

def finalize_config!(instance)
  super
  load_needed_dependencies!
  self
end

#init_commandString

Generates a command string which will perform any data initialization or configuration required after the provisioner software is installed but before the sandbox has been transferred to the instance. If no work is required, then nil will be returned.

Returns:

  • (String)

    a command string



79
80
# File 'lib/kitchen/provisioner/base.rb', line 79

def init_command
end

#install_commandString

Generates a command string which will install and configure the provisioner software on an instance. If no work is required, then nil will be returned.

Returns:

  • (String)

    a command string



70
71
# File 'lib/kitchen/provisioner/base.rb', line 70

def install_command
end

#nameString

Returns the name of this driver, suitable for display in a CLI.

Returns:

  • (String)

    name of this driver



61
62
63
# File 'lib/kitchen/provisioner/base.rb', line 61

def name
  self.class.name.split("::").last
end

#prepare_commandString

Generates a command string which will perform any commands or configuration required just before the main provisioner run command but after the sandbox has been transferred to the instance. If no work is required, then nil will be returned.

Returns:

  • (String)

    a command string



88
89
# File 'lib/kitchen/provisioner/base.rb', line 88

def prepare_command
end

#run_commandString

Generates a command string which will invoke the main provisioner command on the prepared instance. If no work is required, then nil will be returned.

Returns:

  • (String)

    a command string



96
97
# File 'lib/kitchen/provisioner/base.rb', line 96

def run_command
end

#sandbox_pathString

Returns the absolute path to the sandbox directory or raises an exception if #create_sandbox has not yet been called.

Returns:

  • (String)

    the absolute path to the sandbox directory

Raises:

  • (ClientError)

    if the sandbox directory has no yet been created by calling #create_sandbox



130
131
132
133
134
# File 'lib/kitchen/provisioner/base.rb', line 130

def sandbox_path
  @sandbox_path || (raise ClientError, "Sandbox directory has not yet " \
    "been created. Please run #{self.class}#create_sandox before " \
    "trying to access the path.")
end