Class: Commands::ListInstances
- Inherits:
-
Object
- Object
- Commands::ListInstances
- Defined in:
- lib/commands/list_instances.rb
Instance Method Summary collapse
-
#options ⇒ Object
holds the options that were passed you can set any initial defaults here.
- #register(opts, global_options) ⇒ Object
-
#required_options ⇒ Object
required options.
- #run(global_options, amazon) ⇒ Object
Instance Method Details
#options ⇒ Object
holds the options that were passed you can set any initial defaults here
8 9 10 11 |
# File 'lib/commands/list_instances.rb', line 8 def @options ||= { } end |
#register(opts, global_options) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/commands/list_instances.rb', line 20 def register(opts, ) opts. = "Usage: list [options]" opts.description = "List the server instances" opts.on('-r', "--role role", MetaOptions.roles, "Role to look for.") do |v| [:role] = v end opts.on('-g', "--group deploy_group", "Required: Group to look for.") do |v| [:group] = v end end |
#required_options ⇒ Object
required options
14 15 16 17 18 |
# File 'lib/commands/list_instances.rb', line 14 def @required_options ||= Set.new [ :group ] end |
#run(global_options, amazon) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/commands/list_instances.rb', line 35 def run(, amazon) ec2 = amazon.ec2 instances = amazon.find_and_sort_named_instances([:group], [:role]) first = true instances.each do |instance| if first s = sprintf("%-40s%-14s%-40s","Name", "Instance", "Public Host") puts s first = false end name = instance[:Name] resource_id = instance[:resource_id] public_host = instance[:public_hostname] s = sprintf("%-40s%-14s%-40s",name, resource_id, public_host) puts s end end |