class CloudstackClient::Cli
Public Class Methods
start(given_args=ARGV, config={})
click to toggle source
rescue error globally
Calls superclass method
# File lib/cloudstack_client/cli.rb 37 def self.start(given_args=ARGV, config={}) 38 super 39 rescue => e 40 error_class = e.class.name.split('::') 41 if error_class.size == 2 && error_class.first == "CloudstackClient" 42 puts "\e[31mERROR\e[0m: #{error_class.last} - #{e.message}" 43 puts e.backtrace if ARGV.include? "--debug" 44 else 45 raise 46 end 47 end
Public Instance Methods
client(opts = {})
click to toggle source
# File lib/cloudstack_client/cli.rb 105 def client(opts = {}) 106 @config ||= CloudstackClient::Configuration.load(options) 107 @client ||= CloudstackClient::Client.new( 108 @config[:url], 109 @config[:api_key], 110 @config[:secret_key], 111 opts 112 ) 113 end
console()
click to toggle source
# File lib/cloudstack_client/cli.rb 92 def console 93 cs_client = client(options) 94 95 print "cloudstack_client version #{CloudstackClient::VERSION}" 96 puts " (CloudStack API version #{cs_client.api.api_version})" 97 puts " try: list_virtual_machines state: \"running\"" 98 99 ARGV.clear 100 Ripl.config[:prompt] = "#{@config[:environment]} >> " 101 Ripl.start binding: cs_client.instance_eval{ binding } 102 end
list_apis()
click to toggle source
# File lib/cloudstack_client/cli.rb 64 def list_apis 65 apis = client(no_api_methods: true).send_request('command' => 'listApis') 66 apis.each do |command| 67 command.delete("response") if options[:remove_response] 68 if options[:remove_description] 69 command.delete("description") 70 command["params"].each {|param| param.delete("description")} 71 end 72 end 73 74 print case options[:format] 75 when "yaml" 76 apis.to_yaml 77 else 78 options[:pretty_print] ? JSON.pretty_generate(apis) : JSON.generate(apis) 79 end 80 end
version()
click to toggle source
# File lib/cloudstack_client/cli.rb 50 def version 51 say "cloudstack_client version #{CloudstackClient::VERSION}" 52 end