2010-02-12 00:41:37 -05:00
|
|
|
module Fog
|
|
|
|
class << self
|
|
|
|
|
2010-02-15 20:15:56 -05:00
|
|
|
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]
|
2010-02-15 23:18:52 -05:00
|
|
|
print("\n To run as '#{credential}', add the following to ~/.fog\n")
|
2010-02-15 20:15:56 -05:00
|
|
|
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
|
|
|
|
|
2010-02-12 00:41:37 -05:00
|
|
|
def services
|
|
|
|
services = []
|
2010-02-15 20:15:56 -05:00
|
|
|
[::AWS, ::Rackspace, ::Slicehost, ::Terremark].each do |service|
|
2010-02-12 00:41:37 -05:00
|
|
|
if service.initialized?
|
|
|
|
services << service
|
|
|
|
end
|
|
|
|
end
|
|
|
|
services
|
|
|
|
end
|
|
|
|
|
|
|
|
def flavors
|
|
|
|
flavors = {}
|
|
|
|
services.each do |service|
|
|
|
|
flavors[service] = service.flavors
|
|
|
|
end
|
|
|
|
flavors
|
|
|
|
end
|
|
|
|
|
|
|
|
def images
|
|
|
|
images = {}
|
|
|
|
services.each do |service|
|
|
|
|
images[service] = service.images
|
|
|
|
end
|
|
|
|
images
|
|
|
|
end
|
|
|
|
|
|
|
|
def servers
|
|
|
|
servers = {}
|
|
|
|
services.each do |service|
|
|
|
|
servers[service] = service.servers
|
|
|
|
end
|
|
|
|
servers
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|