Class: Kitchen::Driver::Base
- Inherits:
-
Object
- Object
- Kitchen::Driver::Base
- Defined in:
- lib/kitchen/driver/base.rb
Overview
Base class for a driver.
Class Attribute Summary collapse
-
.serial_actions ⇒ Object
readonly
Returns the value of attribute serial_actions.
Instance Attribute Summary collapse
-
#instance ⇒ Object
Returns the value of attribute instance.
Class Method Summary collapse
- .default_config(attr, value = nil, &block) ⇒ Object
- .defaults ⇒ Object
- .no_parallel_for(*methods) ⇒ Object
- .required_config(attr, &block) ⇒ Object
- .super_defaults ⇒ Object
- .validations ⇒ Object
Instance Method Summary collapse
-
#[](attr) ⇒ Object
Provides hash-like access to configuration keys.
-
#config_keys ⇒ Array
Returns an array of configuration keys.
-
#converge(state) ⇒ Object
Converges a running instance.
-
#create(state) ⇒ Object
Creates an instance.
-
#destroy(state) ⇒ Object
Destroys an instance.
-
#diagnose ⇒ Hash
Returns a Hash of configuration and other useful diagnostic information.
-
#initialize(config = {}) ⇒ Base
constructor
A new instance of Base.
-
#login_command(state) ⇒ LoginCommand
Returns the shell command that will log into an instance.
-
#name ⇒ String
Returns the name of this driver, suitable for display in a CLI.
-
#setup(state) ⇒ Object
Sets up an instance.
- #validate_config! ⇒ Object
-
#verify(state) ⇒ Object
Verifies a converged instance.
-
#verify_dependencies ⇒ Object
Performs whatever tests that may be required to ensure that this driver will be able to function in the current environment.
Constructor Details
#initialize(config = {}) ⇒ Base
Returns a new instance of Base.
41 42 43 44 45 46 |
# File 'lib/kitchen/driver/base.rb', line 41 def initialize(config = {}) @config = LazyHash.new(config, self) self.class.defaults.each do |attr, value| @config[attr] = value unless @config.has_key?(attr) end end |
Class Attribute Details
.serial_actions ⇒ Object (readonly)
Returns the value of attribute serial_actions.
38 39 40 |
# File 'lib/kitchen/driver/base.rb', line 38 def serial_actions @serial_actions end |
Instance Attribute Details
#instance ⇒ Object
Returns the value of attribute instance.
35 36 37 |
# File 'lib/kitchen/driver/base.rb', line 35 def instance @instance end |
Class Method Details
.default_config(attr, value = nil, &block) ⇒ Object
194 195 196 |
# File 'lib/kitchen/driver/base.rb', line 194 def self.default_config(attr, value = nil, &block) defaults[attr] = block_given? ? block : value end |
.defaults ⇒ Object
180 181 182 |
# File 'lib/kitchen/driver/base.rb', line 180 def self.defaults @defaults ||= Hash.new.merge(super_defaults) end |
.no_parallel_for(*methods) ⇒ Object
216 217 218 219 220 221 222 223 224 225 |
# File 'lib/kitchen/driver/base.rb', line 216 def self.no_parallel_for(*methods) Array(methods).each do |meth| if ! ACTION_METHODS.include?(meth) raise ClientError, "##{meth} is not a valid no_parallel_for method" end end @serial_actions ||= [] @serial_actions += methods end |
.required_config(attr, &block) ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/kitchen/driver/base.rb', line 202 def self.required_config(attr, &block) @validations = [] if @validations.nil? if ! block_given? klass = self block = lambda do |attr, value, driver| if value.nil? || value.to_s.empty? attribute = "#{klass}#{driver.instance.to_str}#config[:#{attr}]" raise UserError, "#{attribute} cannot be blank" end end end @validations << [attr, block] end |
.super_defaults ⇒ Object
184 185 186 187 188 189 190 191 192 |
# File 'lib/kitchen/driver/base.rb', line 184 def self.super_defaults klass = self.superclass if klass.respond_to?(:defaults) klass.defaults else Hash.new end end |
.validations ⇒ Object
198 199 200 |
# File 'lib/kitchen/driver/base.rb', line 198 def self.validations @validations end |
Instance Method Details
#[](attr) ⇒ Object
Provides hash-like access to configuration keys.
65 66 67 |
# File 'lib/kitchen/driver/base.rb', line 65 def [](attr) config[attr] end |
#config_keys ⇒ Array
Returns an array of configuration keys.
72 73 74 |
# File 'lib/kitchen/driver/base.rb', line 72 def config_keys config.keys end |
#converge(state) ⇒ Object
Converges a running instance.
86 |
# File 'lib/kitchen/driver/base.rb', line 86 def converge(state) ; end |
#create(state) ⇒ Object
Creates an instance.
80 |
# File 'lib/kitchen/driver/base.rb', line 80 def create(state) ; end |
#destroy(state) ⇒ Object
Destroys an instance.
104 |
# File 'lib/kitchen/driver/base.rb', line 104 def destroy(state) ; end |
#diagnose ⇒ Hash
Returns a Hash of configuration and other useful diagnostic information.
128 129 130 131 132 |
# File 'lib/kitchen/driver/base.rb', line 128 def diagnose result = Hash.new config_keys.sort.each { |k| result[k] = config[k] } result end |
#login_command(state) ⇒ LoginCommand
Returns the shell command that will log into an instance.
112 113 114 |
# File 'lib/kitchen/driver/base.rb', line 112 def login_command(state) raise ActionFailed, "Remote login is not supported in this driver." end |
#name ⇒ String
Returns the name of this driver, suitable for display in a CLI.
57 58 59 |
# File 'lib/kitchen/driver/base.rb', line 57 def name self.class.name.split('::').last end |
#setup(state) ⇒ Object
Sets up an instance.
92 |
# File 'lib/kitchen/driver/base.rb', line 92 def setup(state) ; end |
#validate_config! ⇒ Object
48 49 50 51 52 |
# File 'lib/kitchen/driver/base.rb', line 48 def validate_config! Array(self.class.validations).each do |tuple| tuple.last.call(tuple.first, config[tuple.first], self) end end |
#verify(state) ⇒ Object
Verifies a converged instance.
98 |
# File 'lib/kitchen/driver/base.rb', line 98 def verify(state) ; end |
#verify_dependencies ⇒ Object
Performs whatever tests that may be required to ensure that this driver will be able to function in the current environment. This may involve checking for the presence of certain directories, software installed, etc.
123 |
# File 'lib/kitchen/driver/base.rb', line 123 def verify_dependencies ; end |