Module: Chef::Knife::CloudstackBase
- Included in:
- CloudstackDiskofferingList, CloudstackKeypairCreate, CloudstackKeypairDelete, CloudstackKeypairList, CloudstackNetworkCreate, CloudstackNetworkDelete, CloudstackNetworkList, CloudstackNetworkofferingList, CloudstackPortforwardingruleList, CloudstackPublicipCreate, CloudstackPublicipList, CloudstackSecuritygroupList, CloudstackServerCreate, CloudstackServerDelete, CloudstackServerDestroy, CloudstackServerList, CloudstackServerStart, CloudstackServerStop, CloudstackServiceofferingList, CloudstackTemplateList, CloudstackVolumeDelete, CloudstackVolumeDetach, CloudstackVolumeList, CloudstackZoneList
- Defined in:
- lib/chef/knife/cloudstack_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
- #validate!(keys = [:cloudstack_access_key_id, :cloudstack_secret_access_key, :cloudstack_api_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 :(
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/chef/knife/cloudstack_base.rb', line 28 def self.included(includer) includer.class_eval do deps do require 'fog' require 'readline' require 'chef/json_compat' end option :cloudstack_access_key_id, :short => "-A ID", :long => "--cloudstack-access-key-id KEY", :description => "Your Cloudstack Access Key ID", :proc => Proc.new { |pkey| Chef::Config[:knife][:cloudstack_access_key_id] = pkey } option :cloudstack_secret_access_key, :short => "-K SECRET", :long => "--cloudstack-secret-access-key SECRET", :description => "Your Cloudstack API Secret Access Key", :proc => Proc.new { |skey| Chef::Config[:knife][:cloudstack_secret_access_key] = skey } option :cloudstack_api_endpoint, :long => "--cloudstack-api-endpoint ENDPOINT", :description => "Your Cloudstack API endpoint", :proc => Proc.new { |endpoint| Chef::Config[:knife][:cloudstack_api_endpoint] = endpoint } end end |
Instance Method Details
#connection ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/chef/knife/cloudstack_base.rb', line 56 def connection @connection ||= begin cloudstack_uri = URI.parse(Chef::Config[:knife][:cloudstack_api_endpoint]) connection = Fog::Compute.new( :provider => :cloudstack, :cloudstack_api_key => Chef::Config[:knife][:cloudstack_access_key_id], :cloudstack_secret_access_key => Chef::Config[:knife][:cloudstack_secret_access_key], :cloudstack_host => cloudstack_uri.host, :cloudstack_port => cloudstack_uri.port, :cloudstack_path => cloudstack_uri.path, :cloudstack_scheme => cloudstack_uri.scheme ) end end |
#locate_config_value(key) ⇒ Object
71 72 73 74 |
# File 'lib/chef/knife/cloudstack_base.rb', line 71 def locate_config_value(key) key = key.to_sym Chef::Config[:knife][key] || config[key] end |
#msg_pair(label, value, color = :cyan) ⇒ Object
76 77 78 79 80 |
# File 'lib/chef/knife/cloudstack_base.rb', line 76 def msg_pair(label, value, color=:cyan) if value && !value.to_s.empty? puts "#{ui.color(label, color)}: #{value}" end end |
#validate!(keys = [:cloudstack_access_key_id, :cloudstack_secret_access_key, :cloudstack_api_endpoint]) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/chef/knife/cloudstack_base.rb', line 82 def validate!(keys=[:cloudstack_access_key_id, :cloudstack_secret_access_key, :cloudstack_api_endpoint]) 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? errors << "You did not provided a valid '#{pretty_key}' value." end end if errors.each{|e| ui.error(e)}.any? exit 1 end end |