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:
parent
aac4131c37
commit
72551a87d7
5 changed files with 67 additions and 60 deletions
30
bin/fog
30
bin/fog
|
@ -4,11 +4,6 @@ require File.join(lib_dir, 'fog')
|
||||||
require 'irb'
|
require 'irb'
|
||||||
require 'yaml'
|
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')
|
require File.join(lib_dir, 'fog', 'bin')
|
||||||
|
|
||||||
Fog.credential = (ARGV.first && :"#{ARGV.first}") || :default
|
Fog.credential = (ARGV.first && :"#{ARGV.first}") || :default
|
||||||
|
@ -16,6 +11,11 @@ unless Fog.credentials
|
||||||
exit
|
exit
|
||||||
end
|
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
|
ARGV.clear # Avoid passing args to IRB
|
||||||
IRB.setup(nil)
|
IRB.setup(nil)
|
||||||
@irb = IRB::Irb.new(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.conf[:PROMPT][:FOG][:RETURN] = "%s\n"
|
||||||
@irb.context.prompt_mode = :FOG
|
@irb.context.prompt_mode = :FOG
|
||||||
@irb.context.workspace = IRB::WorkSpace.new(binding)
|
@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 }
|
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}"
|
|
40
lib/fog.rb
40
lib/fog.rb
|
@ -47,46 +47,6 @@ module Fog
|
||||||
self.dependencies.each {|dependency| load(dependency)}
|
self.dependencies.each {|dependency| load(dependency)}
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
Fog.dependencies.each {|dependency| require(dependency)}
|
Fog.dependencies.each {|dependency| require(dependency)}
|
||||||
|
|
|
@ -1,9 +1,49 @@
|
||||||
module Fog
|
module Fog
|
||||||
class << self
|
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
|
def services
|
||||||
services = []
|
services = []
|
||||||
[::AWS, ::Rackspace, ::Slicehost].each do |service|
|
[::AWS, ::Rackspace, ::Slicehost, ::Terremark].each do |service|
|
||||||
if service.initialized?
|
if service.initialized?
|
||||||
services << service
|
services << service
|
||||||
end
|
end
|
||||||
|
|
|
@ -73,17 +73,20 @@ module Fog
|
||||||
data = "#{Thread.current[:formatador].indentation}<#{self.class.name}\n"
|
data = "#{Thread.current[:formatador].indentation}<#{self.class.name}\n"
|
||||||
Thread.current[:formatador].indent do
|
Thread.current[:formatador].indent do
|
||||||
unless self.class.attributes.empty?
|
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 << self.class.attributes.map {|attribute| "#{attribute}=#{send(attribute).inspect}"}.join(",\n#{Thread.current[:formatador].indentation}")
|
||||||
|
data << "\n"
|
||||||
end
|
end
|
||||||
data << "#{Thread.current[:formatador].indentation}[\n"
|
data << "#{Thread.current[:formatador].indentation}["
|
||||||
unless self.empty?
|
unless self.empty?
|
||||||
|
data << "\n"
|
||||||
Thread.current[:formatador].indent do
|
Thread.current[:formatador].indent do
|
||||||
data << self.map {|member| member.inspect}.join(",\n")
|
data << self.map {|member| member.inspect}.join(",\n")
|
||||||
data << "\n"
|
data << "\n"
|
||||||
end
|
end
|
||||||
|
data << Thread.current[:formatador].indentation
|
||||||
end
|
end
|
||||||
data << "#{Thread.current[:formatador].indentation}]\n"
|
data << "]\n"
|
||||||
end
|
end
|
||||||
data << "#{Thread.current[:formatador].indentation}>"
|
data << "#{Thread.current[:formatador].indentation}>"
|
||||||
data
|
data
|
||||||
|
|
|
@ -19,6 +19,12 @@ module Terremark
|
||||||
@@connections[service]
|
@@connections[service]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
def initialized?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue