Class: Kitchen::Provisioner::Base
- Inherits:
-
Object
- Object
- Kitchen::Provisioner::Base
- Includes:
- Configurable, Logging
- Defined in:
- lib/kitchen/provisioner/base.rb
Overview
Base class for a provisioner.
Instance Attribute Summary
Attributes included from Configurable
Instance Method Summary collapse
-
#cleanup_sandbox ⇒ Object
Deletes the sandbox path.
-
#create_sandbox ⇒ Object
Creates a temporary directory on the local workstation into which provisioner related files and directories can be copied or created.
-
#finalize_config!(instance) ⇒ self
Performs any final configuration required for the provisioner to do its work.
-
#init_command ⇒ String
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.
-
#initialize(config = {}) ⇒ Base
constructor
Constructs a new provisioner by providing a configuration hash.
-
#install_command ⇒ String
Generates a command string which will install and configure the provisioner software on an instance.
-
#name ⇒ String
Returns the name of this driver, suitable for display in a CLI.
-
#prepare_command ⇒ String
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.
-
#run_command ⇒ String
Generates a command string which will invoke the main provisioner command on the prepared instance.
-
#sandbox_path ⇒ String
Returns the absolute path to the sandbox directory or raises an exception if
#create_sandbox
has not yet been called.
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.
39 40 41 |
# File 'lib/kitchen/provisioner/base.rb', line 39 def initialize(config = {}) init_config(config) end |
Instance Method Details
#cleanup_sandbox ⇒ Object
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_sandbox ⇒ Object
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:
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.
52 53 54 55 56 |
# File 'lib/kitchen/provisioner/base.rb', line 52 def finalize_config!(instance) super load_needed_dependencies! self end |
#init_command ⇒ String
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.
79 80 |
# File 'lib/kitchen/provisioner/base.rb', line 79 def init_command end |
#install_command ⇒ String
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.
70 71 |
# File 'lib/kitchen/provisioner/base.rb', line 70 def install_command end |
#name ⇒ String
Returns the name of this driver, suitable for display in a CLI.
61 62 63 |
# File 'lib/kitchen/provisioner/base.rb', line 61 def name self.class.name.split("::").last end |
#prepare_command ⇒ String
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.
88 89 |
# File 'lib/kitchen/provisioner/base.rb', line 88 def prepare_command end |
#run_command ⇒ String
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.
96 97 |
# File 'lib/kitchen/provisioner/base.rb', line 96 def run_command end |
#sandbox_path ⇒ String
Returns the absolute path to the sandbox directory or raises an
exception if #create_sandbox
has not yet been called.
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 |