class DopCommon::Hooks

Public Class Methods

new(hash) click to toggle source
# File lib/dop_common/hooks.rb, line 9
def initialize(hash)
  @hash = symbolize_keys(hash)
end

Public Instance Methods

post_create_vm() click to toggle source
# File lib/dop_common/hooks.rb, line 26
def post_create_vm
  @post_create_vm ||= post_create_vm_valid? ? @hash[:post_create_vm] : []
end
post_destroy_vm() click to toggle source
# File lib/dop_common/hooks.rb, line 42
def post_destroy_vm
  @post_destroy_vm ||= post_destroy_vm_valid? ? @hash[:post_destroy_vm] : []
end
post_update_vm() click to toggle source
# File lib/dop_common/hooks.rb, line 34
def post_update_vm
  @post_update_vm ||= post_update_vm_valid? ? @hash[:post_update_vm] : []
end
pre_create_vm() click to toggle source
# File lib/dop_common/hooks.rb, line 22
def pre_create_vm
  @pre_create_vm ||= pre_create_vm_valid? ? @hash[:pre_create_vm] : []
end
pre_destroy_vm() click to toggle source
# File lib/dop_common/hooks.rb, line 38
def pre_destroy_vm
  @pre_destroy_vm ||= pre_destroy_vm_valid? ? @hash[:pre_destroy_vm] : []
end
pre_update_vm() click to toggle source
# File lib/dop_common/hooks.rb, line 30
def pre_update_vm
  @pre_update_vm ||= pre_update_vm_valid? ? @hash[:pre_update_vm] : []
end
validate() click to toggle source
# File lib/dop_common/hooks.rb, line 13
def validate
  log_validation_method(:pre_create_vm_valid?)
  log_validation_method(:post_create_vm_valid?)
  log_validation_method(:pre_update_vm_valid?)
  log_validation_method(:post_update_vm_valid?)
  log_validation_method(:pre_destroy_vm_valid?)
  log_validation_method(:post_destroy_vm_valid?)
end

Private Instance Methods

hook_valid?(hook_name) click to toggle source
# File lib/dop_common/hooks.rb, line 48
def hook_valid?(hook_name)
  return false unless @hash.has_key?(hook_name)
  raise PlanParsingError, "Hook #{hook_name}: hooks must be a non-empty array of strings" if
    !@hash[hook_name].kind_of?(Array) || @hash[hook_name].empty? || !@hash[hook_name].all? { |h| h.kind_of?(String) }
  raise PlanParsingError, "Hook #{hook_name}: a hook must be an executable file" unless
    @hash[hook_name].all? { |h| File.file?(h) && File.executable?(h) }
  true
end
post_create_vm_valid?() click to toggle source
# File lib/dop_common/hooks.rb, line 61
def post_create_vm_valid?
  hook_valid?(:post_create_vm)
end
post_destroy_vm_valid?() click to toggle source
# File lib/dop_common/hooks.rb, line 77
def post_destroy_vm_valid?
  hook_valid?(:post_destroy_vm)
end
post_update_vm_valid?() click to toggle source
# File lib/dop_common/hooks.rb, line 69
def post_update_vm_valid?
  hook_valid?(:post_update_vm)
end
pre_create_vm_valid?() click to toggle source
# File lib/dop_common/hooks.rb, line 57
def pre_create_vm_valid?
  hook_valid?(:pre_create_vm)
end
pre_destroy_vm_valid?() click to toggle source
# File lib/dop_common/hooks.rb, line 73
def pre_destroy_vm_valid?
  hook_valid?(:pre_destroy_vm)
end
pre_update_vm_valid?() click to toggle source
# File lib/dop_common/hooks.rb, line 65
def pre_update_vm_valid?
  hook_valid?(:pre_update_vm)
end