2009-10-02 02:22:47 -04:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
require File.join(File.dirname(__FILE__), '..', 'lib', 'fog')
|
|
|
|
require 'irb'
|
|
|
|
require 'yaml'
|
|
|
|
|
2010-01-09 20:29:27 -05:00
|
|
|
module Fog
|
|
|
|
module Credentials
|
2009-12-09 01:30:50 -05:00
|
|
|
key = (ARGV.first && :"#{ARGV.first}") || :default
|
|
|
|
unless Fog.credentials(key)
|
2009-12-21 16:26:40 -05:00
|
|
|
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)
|
2009-12-09 01:30:50 -05:00
|
|
|
raise ArgumentError.new("No credentials for :#{key}")
|
|
|
|
end
|
2010-01-09 20:29:27 -05:00
|
|
|
end
|
|
|
|
end
|
2009-10-08 02:45:33 -04:00
|
|
|
|
2010-01-09 20:29:27 -05:00
|
|
|
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]
|
2009-10-02 02:22:47 -04:00
|
|
|
|
2010-01-09 20:29:27 -05:00
|
|
|
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
|
2009-10-08 02:45:33 -04:00
|
|
|
|
2009-10-15 16:45:14 -04:00
|
|
|
def addresses
|
2010-01-09 20:29:27 -05:00
|
|
|
connections[:ec2].addresses
|
2009-10-15 16:45:14 -04:00
|
|
|
end
|
2009-10-02 02:22:47 -04:00
|
|
|
|
2009-10-15 16:45:14 -04:00
|
|
|
def buckets
|
2010-01-09 20:29:27 -05:00
|
|
|
connections[:s3].buckets
|
2009-10-15 16:45:14 -04:00
|
|
|
end
|
2009-10-09 02:01:09 -04:00
|
|
|
|
2010-01-10 16:22:18 -05:00
|
|
|
def flavors
|
|
|
|
connections[:ec2].flavors
|
|
|
|
end
|
|
|
|
|
2010-01-08 14:29:07 -05:00
|
|
|
def servers
|
2010-01-09 20:29:27 -05:00
|
|
|
connections[:ec2].servers
|
2009-10-15 16:45:14 -04:00
|
|
|
end
|
2009-10-08 02:45:33 -04:00
|
|
|
|
2009-10-15 16:45:14 -04:00
|
|
|
def key_pairs
|
2010-01-09 20:29:27 -05:00
|
|
|
connections[:ec2].key_pairs
|
2009-10-15 16:45:14 -04:00
|
|
|
end
|
2009-10-08 02:45:33 -04:00
|
|
|
|
2009-10-15 16:45:14 -04:00
|
|
|
def security_groups
|
2010-01-09 20:29:27 -05:00
|
|
|
connections[:ec2].security_groups
|
2009-10-15 16:45:14 -04:00
|
|
|
end
|
2009-10-15 01:03:31 -04:00
|
|
|
|
2009-10-15 16:45:14 -04:00
|
|
|
def snapshots
|
2010-01-09 20:29:27 -05:00
|
|
|
connections[:ec2].snapshots
|
2009-10-15 16:45:14 -04:00
|
|
|
end
|
2009-10-15 01:03:31 -04:00
|
|
|
|
2009-10-15 16:45:14 -04:00
|
|
|
def volumes
|
2010-01-09 20:29:27 -05:00
|
|
|
connections[:ec2].volumes
|
2009-10-15 16:45:14 -04:00
|
|
|
end
|
2009-10-15 01:03:31 -04:00
|
|
|
|
2009-10-15 16:45:14 -04:00
|
|
|
end
|
2009-10-15 01:03:31 -04:00
|
|
|
end
|
2009-10-08 02:45:33 -04:00
|
|
|
end
|
|
|
|
|
2009-10-15 01:03:31 -04:00
|
|
|
module Rackspace
|
|
|
|
class << self
|
2009-12-09 01:30:50 -05:00
|
|
|
key = (ARGV.first && :"#{ARGV.first}") || :default
|
|
|
|
if Fog.credentials(key)[:rackspace_api_key] && Fog.credentials(key)[:rackspace_username]
|
2009-10-15 01:03:31 -04:00
|
|
|
|
2010-01-09 20:29:27 -05:00
|
|
|
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
|
|
|
|
|
2009-11-19 11:19:46 -05:00
|
|
|
def flavors
|
2010-01-09 20:29:27 -05:00
|
|
|
connections[:servers].flavors
|
2009-11-19 11:19:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def images
|
2010-01-09 20:29:27 -05:00
|
|
|
connections[:servers].images
|
2009-11-19 11:19:46 -05:00
|
|
|
end
|
|
|
|
|
2009-10-15 16:45:14 -04:00
|
|
|
def servers
|
2010-01-09 20:29:27 -05:00
|
|
|
connections[:servers].servers
|
2009-10-15 16:45:14 -04:00
|
|
|
end
|
|
|
|
|
2009-10-15 01:03:31 -04:00
|
|
|
end
|
|
|
|
end
|
2009-10-08 02:45:33 -04:00
|
|
|
end
|
|
|
|
|
2009-10-02 02:22:47 -04:00
|
|
|
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 }
|