Module: Chef::Knife::Cloud::Helpers
- Included in:
- BootstrapCommand, BootstrapProtocol, Command, Service
- Defined in:
- lib/chef/knife/cloud/helpers.rb
Instance Method Summary collapse
- #after_exec_command ⇒ Object
-
#before_exec_command ⇒ Object
Derived classes can override before_exec_command and after_exec_command.
- #create_service_instance ⇒ Object
- #execute_command ⇒ Object
- #locate_config_value(key) ⇒ Object
-
#msg_pair(label, value, color = :cyan) ⇒ Object
Additional helpers.
- #pretty_key(key) ⇒ Object
- #set_default_config ⇒ Object
- #validate!(*keys) ⇒ Object
- #validate_params! ⇒ Object
Instance Method Details
#after_exec_command ⇒ Object
46 |
# File 'lib/chef/knife/cloud/helpers.rb', line 46 def after_exec_command; end |
#before_exec_command ⇒ Object
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_instance ⇒ Object
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_command ⇒ Object
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_config ⇒ Object
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 = "" raise CloudExceptions::ValidationError, if errors.each { |e| ui.error(e); = "#{} #{e}." }.any? end |
#validate_params! ⇒ Object
61 |
# File 'lib/chef/knife/cloud/helpers.rb', line 61 def validate_params!; end |