Module: Chef::Knife::RightscaleBase
- Included in:
- RightscaleCloudList, RightscaleDeploymentList, RightscaleImageList, RightscaleSecuritygroupList, RightscaleServerCreate, RightscaleServerDelete, RightscaleServerList, RightscaleServertemplateList, RightscaleVersion
- Defined in:
- lib/chef/knife/rightscale_base.rb
Class Method Summary collapse
-
.included(includer) ⇒ Object
:nodoc: Would prefer to do this in a rational way, but can’t be done b/c of Mixlib::CLI’s design :(.
Instance Method Summary collapse
- #connection ⇒ Object
- #locate_config_value(key) ⇒ Object
- #msg_pair(label, value, color = :cyan) ⇒ Object
- #right_api_client ⇒ Object
- #set_log_level(obj) ⇒ Object
- #validate!(keys = [:rightscale_user, :rightscale_password, :rightscale_account_id]) ⇒ Object
Class Method Details
.included(includer) ⇒ Object
:nodoc: Would prefer to do this in a rational way, but can’t be done b/c of Mixlib::CLI’s design :(
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/chef/knife/rightscale_base.rb', line 34 def self.included(includer) includer.class_eval do deps do require 'right_api_helper' end option :rightscale_user, :short => "-U USER", :long => "--rightscale-user USER", :description => "Your RightScale User Email", :proc => Proc.new { |key| Chef::Config[:knife][:rightscale_user] = key } option :rightscale_password, :short => "-P PASSWORD", :long => "--rightscale-password PASSWORD", :description => "Your RightScale password", :proc => Proc.new { |key| Chef::Config[:knife][:rightscale_password] = key } option :rightscale_account_id, :short => "-A ID", :long => "--rightscale-account-id ID", :description => "Your RightScale account ID", :proc => Proc.new { |key| Chef::Config[:knife][:rightscale_account_id] = key } option :rightscale_api_url, :short => "-L API_URL", :long => "--rightscale-api-url API_URL", :description => "The API URL (defaults to my.rightscale.com)", :default => "https://my.rightscale.com", :proc => Proc.new { |key| Chef::Config[:knife][:rightscale_api_url] = key } end end |
Instance Method Details
#connection ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/chef/knife/rightscale_base.rb', line 69 def connection @connection ||= begin api_shim = RightApiHelper::API15.new(right_api_client) set_log_level(api_shim) api_shim end end |
#locate_config_value(key) ⇒ Object
96 97 98 99 |
# File 'lib/chef/knife/rightscale_base.rb', line 96 def locate_config_value(key) key = key.to_sym config[key] || Chef::Config[:knife][key] end |
#msg_pair(label, value, color = :cyan) ⇒ Object
101 102 103 104 105 |
# File 'lib/chef/knife/rightscale_base.rb', line 101 def msg_pair(label, value, color=:cyan) if value && !value.to_s.empty? puts "#{ui.color(label, color)}: #{value}" end end |
#right_api_client ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/chef/knife/rightscale_base.rb', line 77 def right_api_client @right_api_client ||= begin session = RightApiHelper::Session.new set_log_level(session) right_api_client = session.create_client( Chef::Config[:knife][:rightscale_user], Chef::Config[:knife][:rightscale_password], Chef::Config[:knife][:rightscale_account_id], Chef::Config[:knife][:rightscale_api_url] ) right_api_client end end |
#set_log_level(obj) ⇒ Object
91 92 93 94 |
# File 'lib/chef/knife/rightscale_base.rb', line 91 def set_log_level(obj) log_level = (config[:verbosity] >= 1) ? Logger::DEBUG : Logger::INFO obj.log_level(log_level) end |
#validate!(keys = [:rightscale_user, :rightscale_password, :rightscale_account_id]) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/chef/knife/rightscale_base.rb', line 107 def validate!(keys=[:rightscale_user, :rightscale_password, :rightscale_account_id]) errors = [] keys.each do |k| pretty_key = k.to_s.gsub(/_/, ' ').gsub(/\w+/){ |w| (w =~ /(ssh)|(aws)/i) ? w.upcase : w.capitalize } if Chef::Config[:knife][k].nil? && config[k].nil? errors << "You did not provide a valid '#{pretty_key}' value." end end if errors.each{|e| ui.error(e)}.any? exit 1 end end |