lib/cloudstack-cli/base.rb in cloudstack-cli-0.15.1 vs lib/cloudstack-cli/base.rb in cloudstack-cli-1.0.0.rc1
- old
+ new
@@ -4,10 +4,11 @@
module CloudstackCli
class Base < Thor
include Thor::Actions
include CloudstackCli::Helper
+ include CloudstackCli::OptionResolver
attr_reader :config
# catch control-c and exit
trap("SIGINT") {
@@ -19,18 +20,19 @@
def self.exit_on_failure?
true
end
no_commands do
- def client(opts = {})
+ def client
@config ||= load_configuration
- @client ||= CloudstackClient::Connection.new(
+ @client ||= CloudstackClient::Client.new(
@config[:url],
@config[:api_key],
- @config[:secret_key],
- opts.merge({debug: options[:debug]})
+ @config[:secret_key]
)
+ @client.debug = true if options[:debug]
+ @client
end
def load_configuration(config_file = options[:config_file], env = options[:env])
unless File.exists?(config_file)
say "Configuration file #{config_file} not found.", :red
@@ -57,21 +59,9 @@
say "The environment #{env || '\'-\''} contains no valid data.", :red
say "Please check with 'cs environment list' and set a valid default environment."
exit 1
end
config
- end
-
- def find_project(name = options[:project], allow_all = true)
- return nil unless name
- if allow_all && %w(ALL -1).include?(name)
- return {'id' => '-1'}
- end
- unless project = client.get_project(name)
- say "Project '#{name}' not found", :red
- exit 1
- end
- project
end
def filter_by(objects, key, value)
objects.select {|r| r[key].downcase == value.downcase}
end