Module: Chef::Knife::StormBase
- Included in:
- StormServerDelete, StormServerList, StormServerReboot
- Defined in:
- lib/chef/knife/storm_base.rb
Class Method Summary collapse
Instance Method Summary collapse
- #connection ⇒ Object
- #locate_config_value(key) ⇒ Object
- #msg_pair(label, value, color = :cyan) ⇒ Object
- #validate!(keys = [:storm_on_demand_username, :storm_on_demand_password]) ⇒ Object
Class Method Details
.included(includer) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/chef/knife/storm_base.rb', line 11 def self.included(includer) includer.class_eval do deps do require 'fog' require 'readline' require 'chef/json_compat' end option :storm_on_demand_username, :short => "-U USERNAME", :long => "--storm-user", :description => "StormOnDemand api username", :proc => Proc.new { |key| Chef::Config[:knife][:storm_on_demand_username] = key } option :storm_on_demand_password, :short => "-P PASSWORD", :long => "--storm-pass", :description => "StormOnDemand api password", :proc => Proc.new { |key| Chef::Config[:knife][:storm_on_demand_password] = key } end end |
Instance Method Details
#connection ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/chef/knife/storm_base.rb', line 35 def connection @connection ||= begin connection = Fog::Compute.new({ :provider => 'stormondemand', :storm_on_demand_username => locate_config_value(:storm_on_demand_username), :storm_on_demand_password => locate_config_value(:storm_on_demand_password) }) end end |
#locate_config_value(key) ⇒ Object
45 46 47 48 |
# File 'lib/chef/knife/storm_base.rb', line 45 def locate_config_value(key) key = key.to_sym config[key] || Chef::Config[:knife][key] end |
#msg_pair(label, value, color = :cyan) ⇒ Object
50 51 52 53 54 |
# File 'lib/chef/knife/storm_base.rb', line 50 def msg_pair(label, value, color=:cyan) if value && !value.to_s.empty? puts "#{ui.color(label, color)}: #{value}" end end |
#validate!(keys = [:storm_on_demand_username, :storm_on_demand_password]) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/chef/knife/storm_base.rb', line 56 def validate!(keys=[:storm_on_demand_username, :storm_on_demand_password]) errors = [] keys.each do |k| pretty_key = k.to_s.gsub(/_/, ' ').gsub(/\w+/){ |w| w.capitalize } if Chef::Config[:knife][k].nil? errors << "You did not provide a valid '#{pretty_key}' value." end end exit 1 if errors.each{ |e| ui.error(e) }.any? end |