Skip to content

Commit

Permalink
Put CLI and Client under a common Aeolus module
Browse files Browse the repository at this point in the history
These module names were changed:

AeolusCli    -> Aeolus::Cli
AeolusClient -> Aeolus::Client

This scopes our code under common Aeolus module.

To adhere to gem naming conventions in Ruby, the gem name was changed
accordingly:

aeolus_cli -> aeolus-cli

Closes #20.
  • Loading branch information
jistr committed Feb 1, 2013
1 parent c501f73 commit af1f29d
Show file tree
Hide file tree
Showing 39 changed files with 168 additions and 160 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in aeolus_cli.gemspec
# Specify your gem's dependencies in aeolus-cli.gemspec
gemspec
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
aeolus_cli (0.0.2)
aeolus-cli (0.0.2)
activeresource (~> 3.2.9)
activesupport (~> 3.2.9)
nokogiri (~> 1.5.5)
Expand Down Expand Up @@ -54,7 +54,7 @@ PLATFORMS
ruby

DEPENDENCIES
aeolus_cli!
aeolus-cli!
aruba
cucumber
rspec
6 changes: 3 additions & 3 deletions aeolus_cli.gemspec → aeolus-cli.gemspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -*- encoding: utf-8 -*-
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'aeolus_cli/version'
require 'aeolus/cli/version'

Gem::Specification.new do |gem|
gem.name = "aeolus_cli"
gem.version = AeolusCli::VERSION
gem.name = "aeolus-cli"
gem.version = Aeolus::Cli::VERSION
gem.authors = "Crag Wolfe"
gem.email = "[email protected]"
gem.description = %q{Command-line interface to aeolus}
Expand Down
4 changes: 2 additions & 2 deletions bin/aeolus
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env ruby

require 'aeolus_cli/main'
require 'aeolus/cli/main'

begin
AeolusCli::Main.start
Aeolus::Cli::Main.start
rescue Exception => ex
if $aeolus_cli_supress_trace_message
exit 1
Expand Down
15 changes: 15 additions & 0 deletions lib/aeolus/cli.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Aeolus
end

module Aeolus::Cli
end

class Aeolus::Cli::Error < StandardError
attr_reader :message

def initialize(message)
@message = message
end
end

class Aeolus::Cli::ConfigError < Aeolus::Cli::Error; end
32 changes: 16 additions & 16 deletions lib/aeolus_cli/common_cli.rb → lib/aeolus/cli/common_cli.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'active_resource'
require 'thor'
require 'aeolus_cli/formatting'
require 'aeolus_client/base'
require 'aeolus_client/provider_type'
require 'aeolus/cli/formatting'
require 'aeolus/client/base'
require 'aeolus/client/provider_type'

class AeolusCli::CommonCli < Thor
class Aeolus::Cli::CommonCli < Thor
class_option :conductor_url, :type => :string
class_option :username, :type => :string
class_option :password, :type => :string
Expand Down Expand Up @@ -74,7 +74,7 @@ def load_aeolus_config(options)
if ENV.has_key?("AEOLUS_CLI_CONF")
config_fname = ENV["AEOLUS_CLI_CONF"]
if !is_file?(config_fname)
raise AeolusCli::ConfigError.new(
raise Aeolus::Cli::ConfigError.new(
"environment variable AEOLUS_CLI_CONF with value "+
"'#{ ENV['AEOLUS_CLI_CONF']}' does not point to an existing file")
end
Expand All @@ -92,15 +92,15 @@ def load_aeolus_config(options)
@config = YAML::load(File.open(File.expand_path(config_fname)))
if @config.has_key?(:conductor)
[:url, :password, :username].each do |key|
raise AeolusCli::ConfigError.new \
raise Aeolus::Cli::ConfigError.new \
("Error in configuration file: #{key} is missing"
) unless @config[:conductor].has_key?(key)
end
AeolusClient::Base.site = @config[:conductor][:url]
AeolusClient::Base.user = @config[:conductor][:username]
AeolusClient::Base.password = @config[:conductor][:password]
Aeolus::Client::Base.site = @config[:conductor][:url]
Aeolus::Client::Base.user = @config[:conductor][:username]
Aeolus::Client::Base.password = @config[:conductor][:password]
else
raise AeolusCli::ConfigError.new("Error in configuration file")
raise Aeolus::Cli::ConfigError.new("Error in configuration file")
end
if @config.has_key?(:logging)
if @config[:logging].has_key?(:logfile)
Expand All @@ -116,7 +116,7 @@ def load_aeolus_config(options)
if @config[:logging].has_key?(:level)
log_level = @config[:logging][:level]
if ! ['DEBUG','WARN','INFO','ERROR','FATAL'].include?(log_level)
raise AeolusCli::ConfigError.new \
raise Aeolus::Cli::ConfigError.new \
("log level specified in configuration #{log_level}, is not valid."+
". shoud be one of DEBUG, WARN, INFO, ERROR or FATAL")
else
Expand All @@ -127,19 +127,19 @@ def load_aeolus_config(options)
end
# allow overrides from command line
if options[:conductor_url]
AeolusClient::Base.site = options[:conductor_url]
Aeolus::Client::Base.site = options[:conductor_url]
end
if options[:username]
AeolusClient::Base.user = options[:username]
Aeolus::Client::Base.user = options[:username]
end
if options[:password]
AeolusClient::Base.password = options[:password]
Aeolus::Client::Base.password = options[:password]
end
end

# Set output format (human vs. machine)
def set_output_format(options)
@output_format = AeolusCli::Formatting.create_format(shell, options)
@output_format = Aeolus::Cli::Formatting.create_format(shell, options)
end

# Transforms e.g. 'name,status' into [:name, :status]
Expand Down Expand Up @@ -179,7 +179,7 @@ def provider_type(type_s)

def provider_type_hash
deltacloud_driver_to_provider_type = Hash.new
provider_types = AeolusClient::ProviderType.all
provider_types = Aeolus::Client::ProviderType.all
if provider_types.size == 0
raise "Retrieved zero provider types from Conductor"
end
Expand Down
6 changes: 3 additions & 3 deletions lib/aeolus_cli/formatting.rb → lib/aeolus/cli/formatting.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'aeolus_cli/formatting/errors'
require 'aeolus/cli/formatting/errors'

module AeolusCli::Formatting
module Aeolus::Cli::Formatting
class << self
def create_format(shell, options)
format_name = options[:format] || default_format
Expand All @@ -17,7 +17,7 @@ def default_format
def load_format_class(format_name)
class_name = format_name.gsub(/^(.)/) { |first_letter| first_letter.upcase } + "Format"
begin
require "aeolus_cli/formatting/#{format_name}_format"
require "aeolus/cli/formatting/#{format_name}_format"
const_get(class_name)
rescue LoadError, NameError
raise UnknownFormatError.new(format_name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module AeolusCli::Formatting
module Aeolus::Cli::Formatting
class PresenterMissingError < StandardError
def initialize(format, object)
super("Presenter not defined for #{object.class.name} in #{format.to_s}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'aeolus_cli/formatting/errors'
require 'aeolus_cli/formatting/presenter_sorter'
require 'aeolus/cli/formatting/errors'
require 'aeolus/cli/formatting/presenter_sorter'

module AeolusCli::Formatting
module Aeolus::Cli::Formatting
# This class (or more precisely, classes that inherit from this one) can
# format various objects for printing. Formatting is done via presenters.
# Presenter classes can be registered with the Format to indicate which
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
require 'aeolus_cli/formatting/format'
require 'aeolus_cli/formatting/human_presenter_filter'
require 'aeolus_cli/formatting/provider_presenter'
require 'aeolus_cli/formatting/provider_account_presenter'
require 'aeolus/cli/formatting/format'
require 'aeolus/cli/formatting/human_presenter_filter'
require 'aeolus/cli/formatting/provider_presenter'
require 'aeolus/cli/formatting/provider_account_presenter'

module AeolusCli::Formatting
module Aeolus::Cli::Formatting
# Format that prints objects in a human-friendly way.
class HumanFormat < Format
def initialize(shell)
super(shell)

register("AeolusClient::Provider", ProviderPresenter)
register("AeolusClient::ProviderAccount", ProviderAccountPresenter)
register("Aeolus::Client::Provider", ProviderPresenter)
register("Aeolus::Client::ProviderAccount", ProviderAccountPresenter)
end

def detail(object, fields_override = nil)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'delegate'

module AeolusCli::Formatting
module Aeolus::Cli::Formatting
# Wrapper for presenters that alters/adds behavior for
# more human-friendly output.
class HumanPresenterFilter < SimpleDelegator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
require 'aeolus_cli/formatting/format'
require 'aeolus_cli/formatting/provider_presenter'
require 'aeolus_cli/formatting/provider_account_presenter'
require 'aeolus/cli/formatting/format'
require 'aeolus/cli/formatting/provider_presenter'
require 'aeolus/cli/formatting/provider_account_presenter'

module AeolusCli::Formatting
module Aeolus::Cli::Formatting
# Format that prints objects in a machine-friendly way.
class MachineFormat < Format
def initialize(shell, separator = "\t")
super(shell)
@separator = separator

register("AeolusClient::Provider", ProviderPresenter)
register("AeolusClient::ProviderAccount", ProviderAccountPresenter)
register("Aeolus::Client::Provider", ProviderPresenter)
register("Aeolus::Client::ProviderAccount", ProviderAccountPresenter)
end

def detail(object, fields_override = nil)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'aeolus_cli/formatting/errors'
require 'aeolus/cli/formatting/errors'

module AeolusCli::Formatting
module Aeolus::Cli::Formatting
# Presenter class formats a single object for output. The generic Presenter
# produces sort of machine-friendly output.
class Presenter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module AeolusCli::Formatting
module Aeolus::Cli::Formatting
# Sorts array of Presenter objects by their field values.
class PresenterSorter
# Parameter sort_by is expected like e.g. [[:status, :desc], [:name, :asc]],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'aeolus_cli/formatting/presenter'
require 'aeolus/cli/formatting/presenter'

module AeolusCli::Formatting
module Aeolus::Cli::Formatting
class ProviderAccountPresenter < Presenter
default_list_item_fields(:name, :provider, :username, :quota)
default_detail_fields(:name, :provider, :username, :quota)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'aeolus_cli/formatting/presenter'
require 'aeolus/cli/formatting/presenter'

module AeolusCli::Formatting
module Aeolus::Cli::Formatting
class ProviderPresenter < Presenter
default_list_item_fields(:name, :provider_type, :deltacloud_provider, :deltacloud_url)
default_detail_fields(:id, :name, :provider_type, :deltacloud_provider, :deltacloud_url)
Expand Down
14 changes: 14 additions & 0 deletions lib/aeolus/cli/main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'aeolus/cli'
require 'thor'
require 'aeolus/cli/provider'
require 'aeolus/cli/provider_account'

class Aeolus::Cli::Main < Thor

desc 'provider', 'show provider subcommands'
subcommand 'provider', Aeolus::Cli::Provider

desc 'provider_account', 'show provider account subcommands'
subcommand 'provider_account', Aeolus::Cli::ProviderAccount

end
10 changes: 5 additions & 5 deletions lib/aeolus_cli/provider.rb → lib/aeolus/cli/provider.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require 'aeolus_cli/common_cli'
require 'aeolus_client/provider'
require 'aeolus/cli/common_cli'
require 'aeolus/client/provider'

class AeolusCli::Provider < AeolusCli::CommonCli
class Aeolus::Cli::Provider < Aeolus::Cli::CommonCli

desc "list", "List all providers"
method_options_for_resource_list
def list
providers = AeolusClient::Provider.all
providers = Aeolus::Client::Provider.all
output_format.list(providers,
resource_fields(options[:fields]),
resource_sort_by(options[:sort_by]))
Expand All @@ -19,7 +19,7 @@ def list
method_option :deltacloud_provider, :type => :string
def add(provider_name)
# TODO: validation on provider_type (make sure exists)
p = AeolusClient::Provider.new(:name => provider_name,
p = Aeolus::Client::Provider.new(:name => provider_name,
:url => options[:deltacloud_url],
:provider_type => provider_type(options[:provider_type]),
:deltacloud_provider => options[:deltacloud_provider])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require 'aeolus_cli/common_cli'
require 'aeolus_client/provider_account'
require 'aeolus/cli/common_cli'
require 'aeolus/client/provider_account'

class AeolusCli::ProviderAccount < AeolusCli::CommonCli
class Aeolus::Cli::ProviderAccount < Aeolus::Cli::CommonCli

desc "list", "list provider accounts"
method_options_for_resource_list
# TODO maybe an optional variable for provider_type
def list
accounts = AeolusClient::ProviderAccount.all_full_detail
accounts = Aeolus::Client::ProviderAccount.all_full_detail
output_format.list(accounts,
resource_fields(options[:fields]),
resource_sort_by(options[:sort_by]))
Expand All @@ -22,13 +22,13 @@ def list
:default => "unlimited", :desc => "maximum running instances"
def add(label)
credentials = credentials_from_file(options[:credentials_file])
provider = AeolusClient::Provider.all.find {|p| p.name == options[:provider_name]}
provider = Aeolus::Client::Provider.all.find {|p| p.name == options[:provider_name]}
unless provider
self.shell.say "ERROR: The provider '#{options[:provider_name]}' does not exist"
exit(1)
end

pa = AeolusClient::ProviderAccount.new(
pa = Aeolus::Client::ProviderAccount.new(
:label => label,
:provider => {:id => provider.id},
:credentials => credentials,
Expand Down
5 changes: 5 additions & 0 deletions lib/aeolus/cli/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Aeolus
module Cli
VERSION = "0.0.2"
end
end
5 changes: 4 additions & 1 deletion lib/aeolus_client.rb → lib/aeolus/client.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require 'active_resource'

module AeolusClient
module Aeolus
end

module Aeolus::Client
end

module ActiveResource
Expand Down
4 changes: 2 additions & 2 deletions lib/aeolus_client/base.rb → lib/aeolus/client/base.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require 'aeolus_client'
require 'aeolus/client'
require 'logger'

# FIXME: get rid of these when refactoring config loading:
ActiveResource::Base.logger = Logger.new(STDOUT)
ActiveResource::Base.logger.level = Logger::INFO

class AeolusClient::Base < ActiveResource::Base
class Aeolus::Client::Base < ActiveResource::Base
self.timeout = 600
self.format = :xml
end
Loading

0 comments on commit af1f29d

Please sign in to comment.