Permalink
Browse files

Update status command to show status of all stacks

  • Loading branch information...
Jon Spalding
Jon Spalding committed May 8, 2011
1 parent 5adb546 commit 3456837a7fa724a095727a048924022bdffe1e1b
Showing with 30 additions and 16 deletions.
  1. +26 −16 lib/misty/cli/status.rb
  2. +4 −0 lib/misty/project.rb
View
@@ -3,30 +3,40 @@ module CLI::Commands
class Status < Misty::CLI::Command
include Config
- def run(args)
- res = cloud_formation_client.describe_stack_resources("StackName" => @project.stack_name(args[0]))
-
- res.body["StackResources"].each_with_index do |instance, i|
- details = ec2_client.describe_instances('instance-id' => instance["PhysicalResourceId"]).body["reservationSet"][0]["instancesSet"][0]
+ def run(args)
+ formations = args.empty? ? @project.formations.values : @project.formations[args[0].to_sym]
+
+ formations.each do |formation|
+ puts "#{formation.name}".red
+ begin
+ res = cloud_formation_client.describe_stack_resources({ "StackName" => formation.stack_name })
+ rescue
+ puts "Stack not running".yellow
+ next
+ end
- puts sprintf "%-11s: %-40s %-12s %-12s %-21s %-62s %-14s (%s)",
- i.to_s.magenta,
- details["tagSet"]['Name'],
- instance["PhysicalResourceId"],
- details["instanceType"],
- "[#{instance_state(details)}]",
- details["dnsName"].blue,
- details["placement"]["availabilityZone"],
- details["tagSet"]["ServerGroup"].yellow
+ res.body["StackResources"].each_with_index do |instance, i|
+ details = ec2_client.describe_instances('instance-id' => instance["PhysicalResourceId"]).body["reservationSet"][0]["instancesSet"][0]
+
+ puts sprintf "%-11s: %-40s %-12s %-12s %-21s %-62s %-14s (%s)",
+ i.to_s.magenta,
+ details["tagSet"]['Name'],
+ instance["PhysicalResourceId"],
+ details["instanceType"],
+ "[#{instance_state(details)}]",
+ details["dnsName"].blue,
+ details["placement"]["availabilityZone"],
+ details["tagSet"]["ServerGroup"].yellow
+ end
end
end
-
+
def instance_state(instance)
instance["instanceState"]["name"] == "running" ? instance["instanceState"]["name"].green : instance["instanceState"]["name"].red
end
def self.description
- "Usage 'misty status FORMATION_NAME'"
+ "Usage 'misty status FORMATION_NAME' or 'misty status'"
end
end
View
@@ -11,6 +11,10 @@ def stack_name(formation)
@formations[formation.to_sym].stack_name
end
+ def stack_names
+ @formations.map{|k,v| v.stack_name }
+ end
+
end
class Formation

0 comments on commit 3456837

Please sign in to comment.