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
|
2010-01-25 19:21:38 -05:00
|
|
|
Fog.credential = (ARGV.first && :"#{ARGV.first}") || :default
|
|
|
|
unless Fog.credentials
|
2010-01-15 00:27:08 -05:00
|
|
|
exit
|
2009-12-09 01:30:50 -05:00
|
|
|
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
|
2010-01-21 22:47:40 -05:00
|
|
|
credential = (ARGV.first && :"#{ARGV.first}") || :default
|
2010-01-25 19:21:38 -05:00
|
|
|
if Fog.credentials[:aws_access_key_id] && Fog.credentials[:aws_secret_access_key]
|
2009-10-02 02:22:47 -04:00
|
|
|
|
2010-02-12 00:34:44 -05:00
|
|
|
def initialized?
|
2010-02-06 18:42:38 -05:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2010-01-23 15:08:37 -05:00
|
|
|
def [](service)
|
2010-01-09 20:29:27 -05:00
|
|
|
@@connections ||= Hash.new do |hash, key|
|
2010-01-25 19:21:38 -05:00
|
|
|
credentials = Fog.credentials.reject do |k, v|
|
2010-01-23 15:08:37 -05:00
|
|
|
![:aws_access_key_id, :aws_secret_access_key].include?(k)
|
|
|
|
end
|
2010-01-09 20:29:27 -05:00
|
|
|
hash[key] = case key
|
|
|
|
when :ec2
|
|
|
|
Fog::AWS::EC2.new(credentials)
|
|
|
|
when :s3
|
|
|
|
Fog::AWS::S3.new(credentials)
|
|
|
|
end
|
|
|
|
end
|
2010-01-23 15:08:37 -05:00
|
|
|
@@connections[service]
|
2010-01-09 20:29:27 -05:00
|
|
|
end
|
2009-10-08 02:45:33 -04:00
|
|
|
|
2009-10-15 16:45:14 -04:00
|
|
|
def addresses
|
2010-01-23 15:08:37 -05:00
|
|
|
self[:ec2].addresses
|
2009-10-15 16:45:14 -04:00
|
|
|
end
|
2009-10-02 02:22:47 -04:00
|
|
|
|
2010-01-14 23:44:39 -05:00
|
|
|
def directories
|
2010-01-23 15:08:37 -05:00
|
|
|
self[:s3].directories
|
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
|
2010-01-23 15:08:37 -05:00
|
|
|
self[:ec2].flavors
|
2010-01-10 16:22:18 -05:00
|
|
|
end
|
|
|
|
|
2010-01-10 16:35:20 -05:00
|
|
|
def images
|
2010-01-23 15:08:37 -05:00
|
|
|
self[:ec2].images
|
2010-01-10 16:35:20 -05:00
|
|
|
end
|
|
|
|
|
2010-01-08 14:29:07 -05:00
|
|
|
def servers
|
2010-01-23 15:08:37 -05:00
|
|
|
self[: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-23 15:08:37 -05:00
|
|
|
self[: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-23 15:08:37 -05:00
|
|
|
self[: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-23 15:08:37 -05:00
|
|
|
self[: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-23 15:08:37 -05:00
|
|
|
self[:ec2].volumes
|
2009-10-15 16:45:14 -04:00
|
|
|
end
|
2009-10-15 01:03:31 -04:00
|
|
|
|
2010-02-06 18:42:38 -05:00
|
|
|
else
|
|
|
|
|
2010-02-12 00:34:44 -05:00
|
|
|
def initialized?
|
2010-02-06 18:42:38 -05:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
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
|
2010-01-25 19:21:38 -05:00
|
|
|
if Fog.credentials[:rackspace_api_key] && Fog.credentials[:rackspace_username]
|
2009-10-15 01:03:31 -04:00
|
|
|
|
2010-02-12 00:34:44 -05:00
|
|
|
def initialized?
|
2010-02-06 18:42:38 -05:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2010-01-23 15:08:37 -05:00
|
|
|
def [](service)
|
2010-01-09 20:29:27 -05:00
|
|
|
@@connections ||= Hash.new do |hash, key|
|
2010-01-25 19:21:38 -05:00
|
|
|
credentials = Fog.credentials.reject do |k,v|
|
2010-01-23 15:08:37 -05:00
|
|
|
![:rackspace_api_key, :rackspace_username].include?(k)
|
|
|
|
end
|
2010-01-09 20:29:27 -05:00
|
|
|
hash[key] = case key
|
|
|
|
when :files
|
|
|
|
Fog::Rackspace::Files.new(credentials)
|
|
|
|
when :servers
|
|
|
|
Fog::Rackspace::Servers.new(credentials)
|
|
|
|
end
|
|
|
|
end
|
2010-01-23 15:08:37 -05:00
|
|
|
@@connections[service]
|
2010-01-09 20:29:27 -05:00
|
|
|
end
|
|
|
|
|
2009-11-19 11:19:46 -05:00
|
|
|
def flavors
|
2010-01-23 15:08:37 -05:00
|
|
|
self[:servers].flavors
|
2009-11-19 11:19:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def images
|
2010-01-23 15:08:37 -05:00
|
|
|
self[:servers].images
|
2009-11-19 11:19:46 -05:00
|
|
|
end
|
|
|
|
|
2009-10-15 16:45:14 -04:00
|
|
|
def servers
|
2010-01-23 15:08:37 -05:00
|
|
|
self[:servers].servers
|
2009-10-15 16:45:14 -04:00
|
|
|
end
|
|
|
|
|
2010-02-06 18:42:38 -05:00
|
|
|
else
|
|
|
|
|
2010-02-12 00:34:44 -05:00
|
|
|
def initialized?
|
2010-02-06 18:42:38 -05:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2009-10-15 01:03:31 -04:00
|
|
|
end
|
|
|
|
end
|
2009-10-08 02:45:33 -04:00
|
|
|
end
|
|
|
|
|
2010-02-06 18:43:02 -05:00
|
|
|
module Slicehost
|
|
|
|
class << self
|
|
|
|
if Fog.credentials[:slicehost_password]
|
|
|
|
|
2010-02-12 00:34:44 -05:00
|
|
|
def initialized?
|
2010-02-06 18:43:02 -05:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def [](service)
|
|
|
|
@@connections ||= Hash.new do |hash, key|
|
|
|
|
credentials = Fog.credentials.reject do |k,v|
|
|
|
|
![:slicehost_password].include?(k)
|
|
|
|
end
|
|
|
|
hash[key] = case key
|
|
|
|
when :slices
|
|
|
|
Fog::Slicehost.new(credentials)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@@connections[service]
|
|
|
|
end
|
|
|
|
|
|
|
|
def flavors
|
|
|
|
self[:slices].flavors
|
|
|
|
end
|
|
|
|
|
|
|
|
def images
|
|
|
|
self[:slices].images
|
|
|
|
end
|
|
|
|
|
|
|
|
def servers
|
|
|
|
self[:slices].servers
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
2010-02-12 00:34:44 -05:00
|
|
|
def initialized?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module Terremark
|
|
|
|
class << self
|
|
|
|
if Fog.credentials[:terremark_password] && Fog.credentials[:terremark_username]
|
|
|
|
|
|
|
|
def initialized?
|
2010-02-06 18:43:02 -05:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2010-02-12 00:34:44 -05:00
|
|
|
def [](service)
|
|
|
|
@@connections ||= Hash.new do |hash, key|
|
|
|
|
credentials = Fog.credentials.reject do |k,v|
|
|
|
|
![:terremark_username, :terremark_password].include?(k)
|
|
|
|
end
|
|
|
|
hash[key] = case key
|
|
|
|
when :vcloud
|
|
|
|
Fog::Terremark.new(credentials)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@@connections[service]
|
|
|
|
end
|
|
|
|
|
2010-02-06 18:43:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-02-06 18:42:38 -05:00
|
|
|
module Fog
|
|
|
|
class << self
|
|
|
|
|
|
|
|
def services
|
|
|
|
services = []
|
2010-02-06 18:43:02 -05:00
|
|
|
[::AWS, ::Rackspace, ::Slicehost].each do |service|
|
2010-02-12 00:34:44 -05:00
|
|
|
if service.initialized?
|
2010-02-06 18:42:38 -05:00
|
|
|
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
|
|
|
|
|
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 }
|