2009-10-01 23:22:47 -07:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
require File.join(File.dirname(__FILE__), '..', 'lib', 'fog')
|
|
|
|
require 'irb'
|
|
|
|
require 'yaml'
|
|
|
|
|
2010-01-09 17:29:27 -08:00
|
|
|
module Fog
|
|
|
|
module Credentials
|
2010-01-25 16:21:38 -08:00
|
|
|
Fog.credential = (ARGV.first && :"#{ARGV.first}") || :default
|
|
|
|
unless Fog.credentials
|
2010-01-14 21:27:08 -08:00
|
|
|
exit
|
2009-12-08 22:30:50 -08:00
|
|
|
end
|
2010-01-09 17:29:27 -08:00
|
|
|
end
|
|
|
|
end
|
2009-10-07 23:45:33 -07:00
|
|
|
|
2010-01-09 17:29:27 -08:00
|
|
|
module AWS
|
|
|
|
class << self
|
2010-01-21 19:47:40 -08:00
|
|
|
credential = (ARGV.first && :"#{ARGV.first}") || :default
|
2010-01-25 16:21:38 -08:00
|
|
|
if Fog.credentials[:aws_access_key_id] && Fog.credentials[:aws_secret_access_key]
|
2009-10-01 23:22:47 -07:00
|
|
|
|
2010-01-23 12:08:37 -08:00
|
|
|
def [](service)
|
2010-01-09 17:29:27 -08:00
|
|
|
@@connections ||= Hash.new do |hash, key|
|
2010-01-25 16:21:38 -08:00
|
|
|
credentials = Fog.credentials.reject do |k, v|
|
2010-01-23 12:08:37 -08:00
|
|
|
![:aws_access_key_id, :aws_secret_access_key].include?(k)
|
|
|
|
end
|
2010-01-09 17:29:27 -08:00
|
|
|
hash[key] = case key
|
|
|
|
when :ec2
|
|
|
|
Fog::AWS::EC2.new(credentials)
|
|
|
|
when :s3
|
|
|
|
Fog::AWS::S3.new(credentials)
|
|
|
|
end
|
|
|
|
end
|
2010-01-23 12:08:37 -08:00
|
|
|
@@connections[service]
|
2010-01-09 17:29:27 -08:00
|
|
|
end
|
2009-10-07 23:45:33 -07:00
|
|
|
|
2009-10-15 13:45:14 -07:00
|
|
|
def addresses
|
2010-01-23 12:08:37 -08:00
|
|
|
self[:ec2].addresses
|
2009-10-15 13:45:14 -07:00
|
|
|
end
|
2009-10-01 23:22:47 -07:00
|
|
|
|
2010-01-14 20:44:39 -08:00
|
|
|
def directories
|
2010-01-23 12:08:37 -08:00
|
|
|
self[:s3].directories
|
2009-10-15 13:45:14 -07:00
|
|
|
end
|
2009-10-08 23:01:09 -07:00
|
|
|
|
2010-01-10 13:22:18 -08:00
|
|
|
def flavors
|
2010-01-23 12:08:37 -08:00
|
|
|
self[:ec2].flavors
|
2010-01-10 13:22:18 -08:00
|
|
|
end
|
|
|
|
|
2010-01-10 13:35:20 -08:00
|
|
|
def images
|
2010-01-23 12:08:37 -08:00
|
|
|
self[:ec2].images
|
2010-01-10 13:35:20 -08:00
|
|
|
end
|
|
|
|
|
2010-01-08 11:29:07 -08:00
|
|
|
def servers
|
2010-01-23 12:08:37 -08:00
|
|
|
self[:ec2].servers
|
2009-10-15 13:45:14 -07:00
|
|
|
end
|
2009-10-07 23:45:33 -07:00
|
|
|
|
2009-10-15 13:45:14 -07:00
|
|
|
def key_pairs
|
2010-01-23 12:08:37 -08:00
|
|
|
self[:ec2].key_pairs
|
2009-10-15 13:45:14 -07:00
|
|
|
end
|
2009-10-07 23:45:33 -07:00
|
|
|
|
2009-10-15 13:45:14 -07:00
|
|
|
def security_groups
|
2010-01-23 12:08:37 -08:00
|
|
|
self[:ec2].security_groups
|
2009-10-15 13:45:14 -07:00
|
|
|
end
|
2009-10-14 22:03:31 -07:00
|
|
|
|
2009-10-15 13:45:14 -07:00
|
|
|
def snapshots
|
2010-01-23 12:08:37 -08:00
|
|
|
self[:ec2].snapshots
|
2009-10-15 13:45:14 -07:00
|
|
|
end
|
2009-10-14 22:03:31 -07:00
|
|
|
|
2009-10-15 13:45:14 -07:00
|
|
|
def volumes
|
2010-01-23 12:08:37 -08:00
|
|
|
self[:ec2].volumes
|
2009-10-15 13:45:14 -07:00
|
|
|
end
|
2009-10-14 22:03:31 -07:00
|
|
|
|
2009-10-15 13:45:14 -07:00
|
|
|
end
|
2009-10-14 22:03:31 -07:00
|
|
|
end
|
2009-10-07 23:45:33 -07:00
|
|
|
end
|
|
|
|
|
2009-10-14 22:03:31 -07:00
|
|
|
module Rackspace
|
|
|
|
class << self
|
2010-01-25 16:21:38 -08:00
|
|
|
if Fog.credentials[:rackspace_api_key] && Fog.credentials[:rackspace_username]
|
2009-10-14 22:03:31 -07:00
|
|
|
|
2010-01-23 12:08:37 -08:00
|
|
|
def [](service)
|
2010-01-09 17:29:27 -08:00
|
|
|
@@connections ||= Hash.new do |hash, key|
|
2010-01-21 19:47:40 -08:00
|
|
|
credential = (ARGV.first && :"#{ARGV.first}") || :default
|
2010-01-25 16:21:38 -08:00
|
|
|
credentials = Fog.credentials.reject do |k,v|
|
2010-01-23 12:08:37 -08:00
|
|
|
![:rackspace_api_key, :rackspace_username].include?(k)
|
|
|
|
end
|
2010-01-09 17:29:27 -08:00
|
|
|
hash[key] = case key
|
|
|
|
when :files
|
|
|
|
Fog::Rackspace::Files.new(credentials)
|
|
|
|
when :servers
|
|
|
|
Fog::Rackspace::Servers.new(credentials)
|
|
|
|
end
|
|
|
|
end
|
2010-01-23 12:08:37 -08:00
|
|
|
@@connections[service]
|
2010-01-09 17:29:27 -08:00
|
|
|
end
|
|
|
|
|
2009-11-19 08:19:46 -08:00
|
|
|
def flavors
|
2010-01-23 12:08:37 -08:00
|
|
|
self[:servers].flavors
|
2009-11-19 08:19:46 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
def images
|
2010-01-23 12:08:37 -08:00
|
|
|
self[:servers].images
|
2009-11-19 08:19:46 -08:00
|
|
|
end
|
|
|
|
|
2009-10-15 13:45:14 -07:00
|
|
|
def servers
|
2010-01-23 12:08:37 -08:00
|
|
|
self[:servers].servers
|
2009-10-15 13:45:14 -07:00
|
|
|
end
|
|
|
|
|
2009-10-14 22:03:31 -07:00
|
|
|
end
|
|
|
|
end
|
2009-10-07 23:45:33 -07:00
|
|
|
end
|
|
|
|
|
2009-10-01 23:22:47 -07: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 }
|