1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

more cleanup around bin/fog usage and messaging

This commit is contained in:
geemus (Wesley Beary) 2010-02-15 17:15:56 -08:00
parent aac4131c37
commit 72551a87d7
5 changed files with 67 additions and 60 deletions

30
bin/fog
View file

@ -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}"

View file

@ -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)}

View file

@ -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

View file

@ -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

View file

@ -19,6 +19,12 @@ module Terremark
@@connections[service]
end
else
def initialized?
false
end
end
end
end