Class: Commands::ListInstances

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/list_instances.rb

Instance Method Summary collapse

Instance Method Details

#optionsObject

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
  @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, global_options)
  opts.banner = "Usage: list [options]"
  opts.description = "List the server instances"

  opts.on('-r', "--role role", MetaOptions.roles, "Role to look for.") do |v|
    options[:role] = v
  end

  opts.on('-g', "--group deploy_group", "Required: Group to look for.") do |v|
    options[:group] = v
  end

end

#required_optionsObject

required options



14
15
16
17
18
# File 'lib/commands/list_instances.rb', line 14

def required_options
  @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(global_options, amazon)
  ec2 = amazon.ec2

  instances = amazon.find_and_sort_named_instances(options[:group], options[: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