Module: Chef::Knife::OcaBase
- Included in:
- OcaServerDelete, OcaServerList, OcaTemplateInstantiate, OcaTemplateList
- Defined in:
- lib/chef/knife/oca_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
- #dns_reverse_lookup(ip) ⇒ Object
- #locate_config_value(key) ⇒ Object
- #msg_pair(label, value, color = :cyan) ⇒ Object
- #validate!(keys = [:oca_one_auth, :oca_xml_rpc_endpoint]) ⇒ 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 :(
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/chef/knife/oca_base.rb', line 32 def self.included(includer) includer.class_eval do deps do require 'fog' require 'readline' require 'chef/json_compat' end option :oca_one_auth, :short => "-K ONE_AUTH", :long => "--oca-one-auth ONE_AUTH", :description => "Your OCA OpenNebula username:password credentials", :proc => Proc.new { |key| Chef::Config[:knife][:oca_one_auth] = key } option :oca_xml_rpc_endpoint, :short => "-C ENDPOINT", :long => "--oca-xml-rpc-endpoint ENDPOINT", :description => "Your OCA OpenNebula XML-RPC endpoint, e.g. http://host:port/RPC2", :proc => Proc.new { |key| Chef::Config[:knife][:oca_xml_rpc_endpoint] = key } end end |
Instance Method Details
#connection ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/chef/knife/oca_base.rb', line 55 def connection @connection ||= begin connection = Fog::Compute.new( :provider => 'oca', :oca_one_auth => Chef::Config[:oca_one_auth], :oca_xml_rpc_endpoint => Chef::Config[:oca_xml_rpc_endpoint], ) end end |
#dns_reverse_lookup(ip) ⇒ Object
91 92 93 94 95 |
# File 'lib/chef/knife/oca_base.rb', line 91 def dns_reverse_lookup(ip) Resolv::DNS.new.getname(ip.to_s).to_s rescue Resolv::ResolvError => e '-not available-' end |
#locate_config_value(key) ⇒ Object
65 66 67 68 |
# File 'lib/chef/knife/oca_base.rb', line 65 def locate_config_value(key) key = key.to_sym config[key] || Chef::Config[:knife][key] end |
#msg_pair(label, value, color = :cyan) ⇒ Object
70 71 72 73 74 |
# File 'lib/chef/knife/oca_base.rb', line 70 def msg_pair(label, value, color=:cyan) if value && !value.to_s.empty? puts "#{ui.color(label, color)}: #{value}" end end |
#validate!(keys = [:oca_one_auth, :oca_xml_rpc_endpoint]) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/chef/knife/oca_base.rb', line 76 def validate!(keys=[:oca_one_auth, :oca_xml_rpc_endpoint]) errors = [] keys.each do |k| pretty_key = k.to_s.gsub(/_/, ' ').gsub(/\w+/){ |w| (w =~ /(ssh)|(oca)/i) ? w.upcase : w.capitalize } if Chef::Config[k].nil? && Chef::Config[:knife][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 |