diff --git a/lib/aeolus_cli/common_cli.rb b/lib/aeolus_cli/common_cli.rb index a1a7528..46a0d3e 100644 --- a/lib/aeolus_cli/common_cli.rb +++ b/lib/aeolus_cli/common_cli.rb @@ -1,8 +1,8 @@ require 'active_resource' require 'thor' require 'aeolus_cli/formatting' -require 'aeolus_cli/model/base' -require 'aeolus_cli/model/provider_type' +require 'aeolus_client/base' +require 'aeolus_client/provider_type' class AeolusCli::CommonCli < Thor class_option :conductor_url, :type => :string @@ -96,9 +96,9 @@ def load_aeolus_config(options) ("Error in configuration file: #{key} is missing" ) unless @config[:conductor].has_key?(key) end - AeolusCli::Model::Base.site = @config[:conductor][:url] - AeolusCli::Model::Base.user = @config[:conductor][:username] - AeolusCli::Model::Base.password = @config[:conductor][:password] + AeolusClient::Base.site = @config[:conductor][:url] + AeolusClient::Base.user = @config[:conductor][:username] + AeolusClient::Base.password = @config[:conductor][:password] else raise AeolusCli::ConfigError.new("Error in configuration file") end @@ -127,13 +127,13 @@ def load_aeolus_config(options) end # allow overrides from command line if options[:conductor_url] - AeolusCli::Model::Base.site = options[:conductor_url] + AeolusClient::Base.site = options[:conductor_url] end if options[:username] - AeolusCli::Model::Base.user = options[:username] + AeolusClient::Base.user = options[:username] end if options[:password] - AeolusCli::Model::Base.password = options[:password] + AeolusClient::Base.password = options[:password] end end @@ -179,7 +179,7 @@ def provider_type(type_s) def provider_type_hash deltacloud_driver_to_provider_type = Hash.new - provider_types = AeolusCli::Model::ProviderType.all + provider_types = AeolusClient::ProviderType.all if provider_types.size == 0 raise "Retrieved zero provider types from Conductor" end diff --git a/lib/aeolus_cli/formatting/human_format.rb b/lib/aeolus_cli/formatting/human_format.rb index 00606f4..ff80c3c 100644 --- a/lib/aeolus_cli/formatting/human_format.rb +++ b/lib/aeolus_cli/formatting/human_format.rb @@ -9,8 +9,8 @@ class HumanFormat < Format def initialize(shell) super(shell) - register("AeolusCli::Model::Provider", ProviderPresenter) - register("AeolusCli::Model::ProviderAccount", ProviderAccountPresenter) + register("AeolusClient::Provider", ProviderPresenter) + register("AeolusClient::ProviderAccount", ProviderAccountPresenter) end def detail(object, fields_override = nil) diff --git a/lib/aeolus_cli/formatting/machine_format.rb b/lib/aeolus_cli/formatting/machine_format.rb index 41ba16f..987248d 100644 --- a/lib/aeolus_cli/formatting/machine_format.rb +++ b/lib/aeolus_cli/formatting/machine_format.rb @@ -9,8 +9,8 @@ def initialize(shell, separator = "\t") super(shell) @separator = separator - register("AeolusCli::Model::Provider", ProviderPresenter) - register("AeolusCli::Model::ProviderAccount", ProviderAccountPresenter) + register("AeolusClient::Provider", ProviderPresenter) + register("AeolusClient::ProviderAccount", ProviderAccountPresenter) end def detail(object, fields_override = nil) diff --git a/lib/aeolus_cli/model/provider_type.rb b/lib/aeolus_cli/model/provider_type.rb deleted file mode 100644 index ba5f3ef..0000000 --- a/lib/aeolus_cli/model/provider_type.rb +++ /dev/null @@ -1,11 +0,0 @@ -class ProviderTypeXMLFormat - include ActiveResource::Formats::XmlFormat - - def decode(xml) - ActiveResource::Formats::XmlFormat.decode(xml)['provider_type'] - end -end - -class AeolusCli::Model::ProviderType < AeolusCli::Model::Base - self.format = ProviderTypeXMLFormat.new -end diff --git a/lib/aeolus_cli/provider.rb b/lib/aeolus_cli/provider.rb index 9b13ad5..56dd116 100644 --- a/lib/aeolus_cli/provider.rb +++ b/lib/aeolus_cli/provider.rb @@ -1,12 +1,12 @@ require 'aeolus_cli/common_cli' -require 'aeolus_cli/model/provider' +require 'aeolus_client/provider' class AeolusCli::Provider < AeolusCli::CommonCli desc "list", "List all providers" method_options_for_resource_list def list - providers = AeolusCli::Model::Provider.all + providers = AeolusClient::Provider.all output_format.list(providers, resource_fields(options[:fields]), resource_sort_by(options[:sort_by])) @@ -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 = AeolusCli::Model::Provider.new(:name => provider_name, + p = AeolusClient::Provider.new(:name => provider_name, :url => options[:deltacloud_url], :provider_type => provider_type(options[:provider_type]), :deltacloud_provider => options[:deltacloud_provider]) diff --git a/lib/aeolus_cli/provider_account.rb b/lib/aeolus_cli/provider_account.rb index ca040e3..e36b547 100644 --- a/lib/aeolus_cli/provider_account.rb +++ b/lib/aeolus_cli/provider_account.rb @@ -1,5 +1,5 @@ require 'aeolus_cli/common_cli' -require 'aeolus_cli/model/provider_account' +require 'aeolus_client/provider_account' class AeolusCli::ProviderAccount < AeolusCli::CommonCli @@ -7,7 +7,7 @@ class AeolusCli::ProviderAccount < AeolusCli::CommonCli method_options_for_resource_list # TODO maybe an optional variable for provider_type def list - accounts = AeolusCli::Model::ProviderAccount.all_full_detail + accounts = AeolusClient::ProviderAccount.all_full_detail output_format.list(accounts, resource_fields(options[:fields]), resource_sort_by(options[:sort_by])) @@ -22,13 +22,13 @@ def list :default => "unlimited", :desc => "maximum running instances" def add(label) credentials = credentials_from_file(options[:credentials_file]) - provider = AeolusCli::Model::Provider.all.find {|p| p.name == options[:provider_name]} + provider = AeolusClient::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 = AeolusCli::Model::ProviderAccount.new( + pa = AeolusClient::ProviderAccount.new( :label => label, :provider => {:id => provider.id}, :credentials => credentials, diff --git a/lib/aeolus_cli/model/base.rb b/lib/aeolus_client/base.rb similarity index 93% rename from lib/aeolus_cli/model/base.rb rename to lib/aeolus_client/base.rb index f063a40..681e934 100644 --- a/lib/aeolus_cli/model/base.rb +++ b/lib/aeolus_client/base.rb @@ -28,10 +28,10 @@ def from_xml(xml, save_cache = false) # declaring the namespace but for style reasons not including the Base # class definition within the block (saving as much excessive # indentation as possible) -module AeolusCli::Model +module AeolusClient end -class AeolusCli::Model::Base < ActiveResource::Base +class AeolusClient::Base < ActiveResource::Base self.timeout = 600 self.format = :xml end diff --git a/lib/aeolus_cli/model/provider.rb b/lib/aeolus_client/provider.rb similarity index 87% rename from lib/aeolus_cli/model/provider.rb rename to lib/aeolus_client/provider.rb index 2e4f7a8..f34ae44 100644 --- a/lib/aeolus_cli/model/provider.rb +++ b/lib/aeolus_client/provider.rb @@ -1,4 +1,4 @@ -class ProviderXMLFormat +class AeolusClient::ProviderXMLFormat include ActiveResource::Formats::XmlFormat def decode(xml) @@ -29,6 +29,6 @@ def decode(xml) end end -class AeolusCli::Model::Provider < AeolusCli::Model::Base - self.format = ProviderXMLFormat.new +class AeolusClient::Provider < AeolusClient::Base + self.format = AeolusClient::ProviderXMLFormat.new end diff --git a/lib/aeolus_cli/model/provider_account.rb b/lib/aeolus_client/provider_account.rb similarity index 86% rename from lib/aeolus_cli/model/provider_account.rb rename to lib/aeolus_client/provider_account.rb index 1c831db..dca82d1 100644 --- a/lib/aeolus_cli/model/provider_account.rb +++ b/lib/aeolus_client/provider_account.rb @@ -1,4 +1,4 @@ -class ProviderAccountXMLFormat +class AeolusClient::ProviderAccountXMLFormat include ActiveResource::Formats::XmlFormat def decode(xml) @@ -32,15 +32,15 @@ def decode(xml) end end -class AeolusCli::Model::ProviderAccount < AeolusCli::Model::Base - self.format = ProviderAccountXMLFormat.new +class AeolusClient::ProviderAccount < AeolusClient::Base + self.format = AeolusClient::ProviderAccountXMLFormat.new # FIXME: This should not be necessary when we update API to show full # representations in resource collections. def self.all_full_detail self.all.map! do |account| # getting a separate resource gives more details than collection - AeolusCli::Model::ProviderAccount.find(account.id) + AeolusClient::ProviderAccount.find(account.id) end end end diff --git a/lib/aeolus_client/provider_type.rb b/lib/aeolus_client/provider_type.rb new file mode 100644 index 0000000..59c8b82 --- /dev/null +++ b/lib/aeolus_client/provider_type.rb @@ -0,0 +1,11 @@ +class AeolusClient::ProviderTypeXMLFormat + include ActiveResource::Formats::XmlFormat + + def decode(xml) + ActiveResource::Formats::XmlFormat.decode(xml)['provider_type'] + end +end + +class AeolusClient::ProviderType < AeolusClient::Base + self.format = AeolusClient::ProviderTypeXMLFormat.new +end diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 9f93712..92357f8 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -12,9 +12,9 @@ AeolusCli::Provider.start end it 'the configuration file should be loaded' do - AeolusCli::Model::Base.site.to_s.should == 'http://example.com:3013/api' - AeolusCli::Model::Base.user.to_s.should == 'master' - AeolusCli::Model::Base.password.to_s.should == 'ofuniverse' + AeolusClient::Base.site.to_s.should == 'http://example.com:3013/api' + AeolusClient::Base.user.to_s.should == 'master' + AeolusClient::Base.password.to_s.should == 'ofuniverse' ActiveResource::Base.logger.level.should == Logger::DEBUG end end @@ -24,7 +24,7 @@ AeolusCli::Provider.start(["--username", "override-user"]) end it 'the configuration file should be loaded' do - AeolusCli::Model::Base.user.to_s.should == 'override-user' + AeolusClient::Base.user.to_s.should == 'override-user' end end @@ -33,7 +33,7 @@ AeolusCli::Provider.start(["--password", "override-password"]) end it 'the configuration file should be loaded' do - AeolusCli::Model::Base.password.to_s.should == 'override-password' + AeolusClient::Base.password.to_s.should == 'override-password' end end @@ -43,7 +43,7 @@ "https://localhost/conductor/api"]) end it 'the configuration file should be loaded' do - AeolusCli::Model::Base.site.to_s.should == + AeolusClient::Base.site.to_s.should == 'https://localhost/conductor/api' end end