diff --git a/bin/fog b/bin/fog index ed3926a54..5f2a3649c 100755 --- a/bin/fog +++ b/bin/fog @@ -4,11 +4,6 @@ require File.join(lib_dir, 'fog') require 'irb' require 'yaml' -require File.join(lib_dir, 'fog', 'aws', 'bin') -require File.join(lib_dir, 'fog', 'rackspace', 'bin') -require File.join(lib_dir, 'fog', 'slicehost', 'bin') -require File.join(lib_dir, 'fog', 'terremark', 'bin') - require File.join(lib_dir, 'fog', 'bin') Fog.credential = (ARGV.first && :"#{ARGV.first}") || :default @@ -16,6 +11,11 @@ unless Fog.credentials exit end +require File.join(lib_dir, 'fog', 'aws', 'bin') +require File.join(lib_dir, 'fog', 'rackspace', 'bin') +require File.join(lib_dir, 'fog', 'slicehost', 'bin') +require File.join(lib_dir, 'fog', 'terremark', 'bin') + ARGV.clear # Avoid passing args to IRB IRB.setup(nil) @irb = IRB::Irb.new(nil) @@ -24,15 +24,13 @@ IRB.conf[:PROMPT][:FOG] = IRB.conf[:PROMPT][:SIMPLE].dup IRB.conf[:PROMPT][:FOG][:RETURN] = "%s\n" @irb.context.prompt_mode = :FOG @irb.context.workspace = IRB::WorkSpace.new(binding) + +services = Fog.services.map{|service| service.to_s} +available_services = if services.length > 1 + services[0...-1].join(', ') << ' and ' << services[-1] +else + services.first +end +print "Welcome to fog interactive; your '#{Fog.credential.to_s}' configuration provides access to #{available_services}.\n" + catch(:IRB_EXIT) { @irb.eval_input } - - -# require 'irb' -# ARGV.clear # Avoid passing args to IRB -# IRB.setup(nil) -# @irb = IRB::Irb.new(nil) -# IRB.conf[:MAIN_CONTEXT] = @irb.context -# IRB.conf[:PROMPT][:SHINDO] = {} -# end -# for key, value in IRB.conf[:PROMPT][:SIMPLE] -# IRB.conf[:PROMPT][:SHINDO][key] = "#{@formatador.indentation}#{value}" \ No newline at end of file diff --git a/lib/fog.rb b/lib/fog.rb index 798602f1c..6c04a1a9e 100644 --- a/lib/fog.rb +++ b/lib/fog.rb @@ -47,46 +47,6 @@ module Fog self.dependencies.each {|dependency| load(dependency)} end - def self.credential=(new_credential) - @credential = new_credential - @credentials = nil - end - - def self.credential - @credential || :default - end - - def self.credentials - @credentials ||= begin - path = File.expand_path('~/.fog') - credentials = if File.exists?(path) - File.open(path) do |file| - YAML.load(file.read) - end - else - nil - end - unless credentials && credentials[credential] - print("\n To run as '#{credential}', add credentials like the following to ~/.fog\n") - yml = <<-YML - -:#{credential}: - :aws_access_key_id: INTENTIONALLY_LEFT_BLANK - :aws_secret_access_key: INTENTIONALLY_LEFT_BLANK - :rackspace_api_key: INTENTIONALLY_LEFT_BLANK - :rackspace_username: INTENTIONALLY_LEFT_BLANK - :slicehost_password: INTENTIONALLY_LEFT_BLANK - :terremark_username: INTENTIONALLY_LEFT_BLANK - :terremark_password: INTENTIONALLY_LEFT_BLANK - -YML - print(yml) - raise(ArgumentError.new("Missing Credentials")) - end - credentials[credential] - end - end - end Fog.dependencies.each {|dependency| require(dependency)} diff --git a/lib/fog/bin.rb b/lib/fog/bin.rb index a7bf2d74d..8aeec28ad 100644 --- a/lib/fog/bin.rb +++ b/lib/fog/bin.rb @@ -1,9 +1,49 @@ module Fog class << self + def credential=(new_credential) + @credential = new_credential + @credentials = nil + end + + def credential + @credential || :default + end + + def credentials + @credentials ||= begin + path = File.expand_path('~/.fog') + credentials = if File.exists?(path) + File.open(path) do |file| + YAML.load(file.read) + end + else + nil + end + unless credentials && credentials[credential] + print("\n To run as '#{credential}', add credentials like the following to ~/.fog\n") + yml = <<-YML + +:#{credential}: + :aws_access_key_id: INTENTIONALLY_LEFT_BLANK + :aws_secret_access_key: INTENTIONALLY_LEFT_BLANK + :rackspace_api_key: INTENTIONALLY_LEFT_BLANK + :rackspace_username: INTENTIONALLY_LEFT_BLANK + :slicehost_password: INTENTIONALLY_LEFT_BLANK + :terremark_username: INTENTIONALLY_LEFT_BLANK + :terremark_password: INTENTIONALLY_LEFT_BLANK + +YML + print(yml) + raise(ArgumentError.new("Missing Credentials")) + end + credentials[credential] + end + end + def services services = [] - [::AWS, ::Rackspace, ::Slicehost].each do |service| + [::AWS, ::Rackspace, ::Slicehost, ::Terremark].each do |service| if service.initialized? services << service end diff --git a/lib/fog/collection.rb b/lib/fog/collection.rb index 60a2af575..8ac38eecd 100644 --- a/lib/fog/collection.rb +++ b/lib/fog/collection.rb @@ -73,17 +73,20 @@ module Fog data = "#{Thread.current[:formatador].indentation}<#{self.class.name}\n" Thread.current[:formatador].indent do unless self.class.attributes.empty? - data << "#{Thread.current[:formatador].indentation}\n" + data << "#{Thread.current[:formatador].indentation}" data << self.class.attributes.map {|attribute| "#{attribute}=#{send(attribute).inspect}"}.join(",\n#{Thread.current[:formatador].indentation}") + data << "\n" end - data << "#{Thread.current[:formatador].indentation}[\n" + data << "#{Thread.current[:formatador].indentation}[" unless self.empty? + data << "\n" Thread.current[:formatador].indent do data << self.map {|member| member.inspect}.join(",\n") data << "\n" end + data << Thread.current[:formatador].indentation end - data << "#{Thread.current[:formatador].indentation}]\n" + data << "]\n" end data << "#{Thread.current[:formatador].indentation}>" data diff --git a/lib/fog/terremark/bin.rb b/lib/fog/terremark/bin.rb index 446cdfb61..28eedd8fc 100644 --- a/lib/fog/terremark/bin.rb +++ b/lib/fog/terremark/bin.rb @@ -19,6 +19,12 @@ module Terremark @@connections[service] end + else + + def initialized? + false + end + end end end