Module: Chef::Knife::Cloud::Helpers

Included in:
BootstrapCommand, BootstrapProtocol, Command, Service
Defined in:
lib/chef/knife/cloud/helpers.rb

Instance Method Summary collapse

Instance Method Details

#after_exec_commandObject



46
# File 'lib/chef/knife/cloud/helpers.rb', line 46

def after_exec_command; end

#before_exec_commandObject

Derived classes can override before_exec_command and after_exec_command



44
# File 'lib/chef/knife/cloud/helpers.rb', line 44

def before_exec_command; end

#create_service_instanceObject

Raises:

  • (Chef::Exceptions::Override)


35
36
37
# File 'lib/chef/knife/cloud/helpers.rb', line 35

def create_service_instance
  raise Chef::Exceptions::Override, "You must override create_service_instance in #{self} to create cloud specific service"
end

#execute_commandObject

Raises:

  • (Chef::Exceptions::Override)


39
40
41
# File 'lib/chef/knife/cloud/helpers.rb', line 39

def execute_command
  raise Chef::Exceptions::Override, "You must override execute_command in #{self}"
end

#locate_config_value(key) ⇒ Object



30
31
32
33
# File 'lib/chef/knife/cloud/helpers.rb', line 30

def locate_config_value(key)
  key = key.to_sym
  config[key] || Chef::Config[:knife][key]
end

#msg_pair(label, value, color = :cyan) ⇒ Object

Additional helpers



24
25
26
27
28
# File 'lib/chef/knife/cloud/helpers.rb', line 24

def msg_pair(label, value, color = :cyan)
  if value && !value.to_s.empty?
    puts "#{ui.color(label, color)}: #{value}"
  end
end

#pretty_key(key) ⇒ Object



63
64
65
# File 'lib/chef/knife/cloud/helpers.rb', line 63

def pretty_key(key)
  key.to_s.tr("_", " ").gsub(/\w+/) { |w| (w =~ /(ssh)|(aws)/i) ? w.upcase : w.capitalize }
end

#set_default_configObject



48
# File 'lib/chef/knife/cloud/helpers.rb', line 48

def set_default_config; end

#validate!(*keys) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/chef/knife/cloud/helpers.rb', line 50

def validate!(*keys)
  # validates necessary options/params to carry out the command.
  # subclasses to implement this.
  errors = []
  keys.each do |k|
    errors << "You did not provide a valid '#{pretty_key(k)}' value." if locate_config_value(k).nil?
  end
  error_message = ""
  raise CloudExceptions::ValidationError, error_message if errors.each { |e| ui.error(e); error_message = "#{error_message} #{e}." }.any?
end

#validate_params!Object



61
# File 'lib/chef/knife/cloud/helpers.rb', line 61

def validate_params!; end