first pass at namespaced bin commands

This commit is contained in:
Wesley Beary 2009-10-14 22:03:31 -07:00
parent 5830adeccb
commit f557705dc1
1 changed files with 60 additions and 39 deletions

61
bin/fog
View File

@ -3,52 +3,73 @@ require File.join(File.dirname(__FILE__), '..', 'lib', 'fog')
require 'irb'
require 'yaml'
def credentials
@credentials ||= begin
if ARGV[0] && File.exists?(File.expand_path(ARGV[0]))
@credentials = YAML.load(File.open(File.expand_path(ARGV[0])).read)
YAML.load(File.open(File.expand_path(ARGV[0])).read)
elsif File.exists?(File.expand_path('~/.fog'))
@credentials = YAML.load(File.open(File.expand_path('~/.fog')).read)
YAML.load(File.open(File.expand_path('~/.fog')).read)
end
end
end
def ec2
@ec2 = Fog::AWS::EC2.new(
:aws_access_key_id => @credentials[:aws_access_key_id],
:aws_secret_access_key => @credentials[:aws_secret_access_key]
)
end
module AWS
class << self
def s3
@s3 = Fog::AWS::S3.new(
:aws_access_key_id => @credentials[:aws_access_key_id],
:aws_secret_access_key => @credentials[:aws_secret_access_key]
@@ec2 = Fog::AWS::EC2.new(
:aws_access_key_id => credentials[:aws_access_key_id],
:aws_secret_access_key => credentials[:aws_secret_access_key]
)
@@s3 = Fog::AWS::S3.new(
:aws_access_key_id => credentials[:aws_access_key_id],
:aws_secret_access_key => credentials[:aws_secret_access_key]
)
end
def addresses
ec2.addresses
@@ec2.addresses
end
def buckets
s3.buckets
@@s3.buckets
end
def instances
ec2.instances
@@ec2.instances
end
def key_pairs
ec2.key_pairs
@@ec2.key_pairs
end
def security_groups
ec2.security_groups
@@ec2.security_groups
end
def snapshots
ec2.snapshots
@@ec2.snapshots
end
def volumes
ec2.volumes
@@ec2.volumes
end
end
end
module Rackspace
class << self
@@servers = Fog::Rackspace::Servers.new(
:rackspace_api_key => credentials[:rackspace_api_key],
:rackspace_username => credentials[:rackspace_username]
)
def servers
@@servers.servers
end
end
end
ARGV.clear # Avoid passing args to IRB