From 745674267754b76b6332023d06ee2929f810c24a Mon Sep 17 00:00:00 2001 From: Justin Harris Date: Mon, 15 Apr 2013 16:04:33 -0500 Subject: [PATCH] min_api is specified in rest_client call --- lib/rhc/commands.rb | 7 +++---- lib/rhc/commands/base.rb | 17 ++++++----------- lib/rhc/commands/cartridge.rb | 11 +++++------ 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/lib/rhc/commands.rb b/lib/rhc/commands.rb index 8ba85b515..41224be21 100644 --- a/lib/rhc/commands.rb +++ b/lib/rhc/commands.rb @@ -35,7 +35,7 @@ def parse_options_and_call_procs *args end # Separate option lists with '--' - remaining = args.split('--').map{ |a| opts.parse!(a) }.inject([]) do |arr, sub| + remaining = args.split('--').map{ |a| opts.parse!(a) }.inject([]) do |arr, sub| arr << '--' unless arr.empty? arr.concat(sub) end @@ -151,7 +151,7 @@ def self.deprecated! instance = Commander::Runner.instance command_name = instance.command_name_from_args command = instance.active_command - + if new_cmd = command.deprecated(command_name) new_cmd = "rhc #{command.name}" if new_cmd == true RHC::Helpers.deprecated_command new_cmd @@ -225,7 +225,6 @@ def self.to_commander(instance=Commander::Runner.instance) cmd = opts[:class].new cmd.options = options cmd.config = config - cmd.min_api = opts[:min_api] args = fill_arguments(cmd, options, args_metadata, options_metadata, args) needs_configuration!(cmd, options, config) @@ -282,7 +281,7 @@ def self.fill_arguments(cmd, options, args_metadata, options_metadata, args) value = cmd.send(context_helper) if value.nil? and context_helper if value.nil? - value = + value = if arg[:arg_type] == :list all = [] while available.first && available.first != '--' diff --git a/lib/rhc/commands/base.rb b/lib/rhc/commands/base.rb index 9b992545c..48a7e0fa5 100644 --- a/lib/rhc/commands/base.rb +++ b/lib/rhc/commands/base.rb @@ -10,7 +10,6 @@ class RHC::Commands::Base attr_writer :options, :config - attr_accessor :min_api def initialize(options=Commander::Command::Options.new, config=RHC::Config.new) @@ -34,14 +33,14 @@ def rest_client(opts={}) auth = RHC::Auth::Basic.new(options) auth = RHC::Auth::Token.new(options, auth, token_store) if (options.use_authorization_tokens || options.token) && !(options.rhlogin && options.password) debug "Authenticating with #{auth.class}" - client = client_from_options(:auth => auth) - - if client && min_api.to_f > client.api_version_negotiated.to_f - raise RHC::ServerAPINotSupportedException.new(min_api, client.api_version_negotiated) - end + client_from_options(:auth => auth) + end - client + if opts[:min_api] && opts[:min_api].to_f > @rest_client.api_version_negotiated.to_f + raise RHC::ServerAPINotSupportedException.new(opts[:min_api], @rest_client.api_version_negotiated) end + + @rest_client end def token_store @@ -110,10 +109,6 @@ def self.suppress_wizard @suppress_wizard = true end - def self.minimum_api(value) - options[:min_api] = value - end - def self.suppress_wizard? @suppress_wizard end diff --git a/lib/rhc/commands/cartridge.rb b/lib/rhc/commands/cartridge.rb index ddef94765..e3fd7198d 100644 --- a/lib/rhc/commands/cartridge.rb +++ b/lib/rhc/commands/cartridge.rb @@ -8,7 +8,7 @@ class Cartridge < Base description <<-DESC Cartridges add functionality to OpenShift applications. Each application has one web cartridge to listen for HTTP requests, and any number - of addon cartridges. Addons may include databases like MySQL and Mongo, + of addon cartridges. Addons may include databases like MySQL and Mongo, administrative tools like phpMyAdmin, or build clients like Jenkins. Most cartridges that listen for incoming network traffic are placed on @@ -17,7 +17,7 @@ class Cartridge < Base (like Jenkins) or provide environment variables. Use the 'cartridges' command to see a list of all available cartridges. - Add a new cartridge to your application with 'add-cartridge'. + Add a new cartridge to your application with 'add-cartridge'. For scalable applications, use the 'cartridge-scale' command on the web cartridge to set the minimum and maximum scale. @@ -36,10 +36,10 @@ def list carts = rest_client.cartridges.sort_by{ |c| "#{c.type == 'standalone' && 1}_#{c.tags.include?('experimental') ? 1 : 0}_#{(c.display_name || c.name).downcase}" } pager - + if options.verbose carts.each do |c| - paragraph do + paragraph do name = c.display_name != c.name && "#{color(c.display_name, :cyan)} [#{c.name}]" || c.name tags = c.tags - RHC::Rest::Cartridge::HIDDEN_TAGS say header([name, "(#{c.only_in_new? ? 'web' : 'addon'})"]) @@ -216,10 +216,9 @@ def scale(cartridge) option ["--remove amount"], "Remove the indicated amount from the additional storage capacity" option ["--set amount"], "Set the specified amount of additional storage capacity" option ["-f", "--force"], "Force the action" - minimum_api 1.3 def storage(cartridge) cartridges = Array(cartridge) - rest_app = rest_client.find_application(options.namespace, options.app, :include => :cartridges) + rest_app = rest_client(:min_api => 1.3).find_application(options.namespace, options.app, :include => :cartridges) # Pull the desired action #