Module: Status
- Included in:
- Ec2InstanceManager
- Defined in:
- lib/ec2-instance-manager/status.rb
Instance Method Summary collapse
- #display_addresses ⇒ Object
- #display_ami_ids(owner_id = nil) ⇒ Object
- #display_instances ⇒ Object
- #display_volumes ⇒ Object
- #get_instance_state(instance_id) ⇒ Object
- #status_info ⇒ Object
Instance Method Details
#display_addresses ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ec2-instance-manager/status.rb', line 33 def display_addresses result = ec2.describe_addresses if result and result["addressesSet"] result["addressesSet"]["item"].each do |ip| puts "#{white(ip["publicIp"])} => #{ip["instanceId"].nil? ? 'unassigned' : ip["instanceId"]}" end else puts white("No addresses.") end end |
#display_ami_ids(owner_id = nil) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/ec2-instance-manager/status.rb', line 9 def display_ami_ids(owner_id = nil) result = ec2.describe_images(:owner_id => owner_id || config[@customer_key]['amazon_account_number']) if result and result["imagesSet"] result["imagesSet"]["item"].each {|image| puts "#{white(image["imageId"])} - #{image["imageLocation"]}"} else puts white("No images.") end end |
#display_instances ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ec2-instance-manager/status.rb', line 18 def display_instances result = ec2.describe_instances if result and result["reservationSet"] result["reservationSet"]["item"].each do |item| instance_id = item["instancesSet"]["item"].first["instanceId"] ami_id = item["instancesSet"]["item"].first["imageId"] running_state = item["instancesSet"]["item"].first["instanceState"]["name"] dns_name = item["instancesSet"]["item"].first["dnsName"] puts "Instance Id: #{white(instance_id)} - #{output_running_state(running_state)} (AMI Id: #{white(ami_id)}) #{dns_name}" end else puts white("No instances.") end end |
#display_volumes ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ec2-instance-manager/status.rb', line 44 def display_volumes result = ec2.describe_volumes if result and result["volumeSet"] result["volumeSet"]["item"].each do |vol| instance_id = nil if vol["attachmentSet"] instance_id = vol["attachmentSet"]["item"].first["instanceId"] end if vol["status"] == 'deleting' puts "#{white(vol["volumeId"])} (Size: #{vol["size"]} / Zone: #{vol["availabilityZone"]}) - #{vol["status"]}" else puts "#{white(vol["volumeId"])} (Size: #{vol["size"]} / Zone: #{vol["availabilityZone"]}) - #{vol["status"]} => #{instance_id.nil? ? 'unassigned' : instance_id}" end end else puts white("No volumes.") end end |
#get_instance_state(instance_id) ⇒ Object
2 3 4 5 6 7 |
# File 'lib/ec2-instance-manager/status.rb', line 2 def get_instance_state(instance_id) result = ec2.describe_instances(:instance_id => instance_id) instance_state = result["reservationSet"]["item"].first["instancesSet"]["item"].first["instanceState"]["name"] dns_name = result["reservationSet"]["item"].first["instancesSet"]["item"].first["dnsName"] return instance_state, dns_name end |
#status_info ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ec2-instance-manager/status.rb', line 63 def status_info puts "Fetching information about your instances..." display_instances puts puts "Fetching your registered private AMI Id's..." display_ami_ids puts puts "Fetching information about your public IP's..." display_addresses puts puts "Fetching information about your volumes..." display_volumes end |