class Ec2list::Command
Attributes
options[R]
Public Class Methods
new(argv = [])
click to toggle source
# File lib/ec2list/command.rb, line 5 def initialize(argv = []) @options = build_options(argv) load_profile end
Public Instance Methods
run()
click to toggle source
# File lib/ec2list/command.rb, line 10 def run AWS.memoize do fetch_instances.each do |instance| print_instance(instance) end end end
Private Instance Methods
build_options(argv)
click to toggle source
# File lib/ec2list/command.rb, line 35 def build_options(argv) Slop.parse(argv) do banner "Usage: ec2list [options]" on :p, :profile, "Profile name", argument: :optional, default: "default" end end
fetch_instances()
click to toggle source
# File lib/ec2list/command.rb, line 20 def fetch_instances AWS::EC2.new. instances. select { |instance| instance.status == :running } end
load_profile()
click to toggle source
# File lib/ec2list/command.rb, line 43 def load_profile unless profile = AWSConfig[options[:profile]] abort "Can't locate profile '#{options[:profile]}' in ~/.aws/config" end AWS.config(profile.config_hash) end
print_instance(instance)
click to toggle source
# File lib/ec2list/command.rb, line 26 def print_instance(instance) tags = instance.tags puts [ tags[:Name], instance.private_ip_address, instance.public_ip_address, ].join("\t") end