1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/bin/fog
2010-01-14 21:27:08 -08:00

128 lines
2.9 KiB
Ruby
Executable file

#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), '..', 'lib', 'fog')
require 'irb'
require 'yaml'
module Fog
module Credentials
key = (ARGV.first && :"#{ARGV.first}") || :default
unless Fog.credentials(key)
print("\n To run as '#{key}', add credentials like the following to ~/.fog\n")
yml = <<-YML
:#{key}:
: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
YML
print(yml)
exit
end
end
end
module AWS
class << self
key = (ARGV.first && :"#{ARGV.first}") || :default
if Fog.credentials(key)[:aws_access_key_id] && Fog.credentials(key)[:aws_secret_access_key]
def connections
@@connections ||= Hash.new do |hash, key|
credentials = {
:aws_access_key_id => Fog.credentials[:aws_access_key_id],
:aws_secret_access_key => Fog.credentials[:aws_secret_access_key]
}
hash[key] = case key
when :ec2
Fog::AWS::EC2.new(credentials)
when :s3
Fog::AWS::S3.new(credentials)
end
end
end
def addresses
connections[:ec2].addresses
end
def directories
connections[:s3].directories
end
def flavors
connections[:ec2].flavors
end
def images
connections[:ec2].images
end
def servers
connections[:ec2].servers
end
def key_pairs
connections[:ec2].key_pairs
end
def security_groups
connections[:ec2].security_groups
end
def snapshots
connections[:ec2].snapshots
end
def volumes
connections[:ec2].volumes
end
end
end
end
module Rackspace
class << self
key = (ARGV.first && :"#{ARGV.first}") || :default
if Fog.credentials(key)[:rackspace_api_key] && Fog.credentials(key)[:rackspace_username]
def connections
@@connections ||= Hash.new do |hash, key|
credentials = {
:rackspace_api_key => Fog.credentials[:rackspace_api_key],
:rackspace_username => Fog.credentials[:rackspace_username]
}
hash[key] = case key
when :files
Fog::Rackspace::Files.new(credentials)
when :servers
Fog::Rackspace::Servers.new(credentials)
end
end
end
def flavors
connections[:servers].flavors
end
def images
connections[:servers].images
end
def servers
connections[:servers].servers
end
end
end
end
ARGV.clear # Avoid passing args to IRB
IRB.setup(nil)
@irb = IRB::Irb.new(nil)
IRB.conf[:MAIN_CONTEXT] = @irb.context
@irb.context.workspace = IRB::WorkSpace.new(binding)
catch(:IRB_EXIT) { @irb.eval_input }