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



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

def after_exec_command; end

#before_exec_commandObject

Derived classes can override before_exec_command and after_exec_command



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

def before_exec_command; end

#create_service_instanceObject

Raises:

  • (Chef::Exceptions::Override)


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

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)


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

def execute_command
  raise Chef::Exceptions::Override, "You must override execute_command in #{self}"
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



58
59
60
# File 'lib/chef/knife/cloud/helpers.rb', line 58

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

#set_default_configObject



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

def set_default_config; end

#validate!(*keys) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/chef/knife/cloud/helpers.rb', line 45

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 config[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



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

def validate_params!; end