Class: Vaws::Aws::Ec2Describer

Inherits:
Describer show all
Defined in:
lib/vaws/aws/ec2_describer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Describer

#single_option_validation

Constructor Details

#initializeEc2Describer

Returns a new instance of Ec2Describer.



9
10
11
12
13
# File 'lib/vaws/aws/ec2_describer.rb', line 9

def initialize
  @ec2_client = ::Aws::EC2::Client.new
  @tag        = 'No Name'
  @term_table = ''
end

Instance Attribute Details

#term_tableObject (readonly)

Returns the value of attribute term_table.



7
8
9
# File 'lib/vaws/aws/ec2_describer.rb', line 7

def term_table
  @term_table
end

Instance Method Details

#set_basic_infoObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/vaws/aws/ec2_describer.rb', line 15

def set_basic_info
  rows       = []
  next_token = nil
  sg_ids     = ""

  begin
    param_args              = {
      max_results: 1000
    }
    param_args[:next_token] = next_token if next_token
    resp                    = @ec2_client.describe_instances(param_args)
    resp[:reservations].each do |reservation|
      reservation.instances.each do |instance|
        instance.tags.each do |tag|
          @tag = tag.value if tag.key == 'Name'
        end
        instance.security_groups.each_with_index do |sg, index|
          sg_ids << "#{sg.group_id}, "
          sg_ids = sg_ids.gsub(/, $/, '') if index == instance.security_groups.size - 1
        end
        instance_id   = instance.instance_id
        instance_type = instance.instance_type
        public_ip     = instance.public_ip_address
        private_ip    = instance.private_ip_address
        state_name    = instance.state.name
        rows << [@tag, instance_id, instance_type, public_ip, private_ip, state_name, sg_ids]
        sg_ids = ''
      end
    end
    next_token = resp.next_token
  end while next_token
  @term_table = Terminal::Table.new :headings => ['Name', 'Id', 'Type', 'GlobalIp', 'PrivateIp', 'Status', 'SecurityGroupId'], :rows => rows.sort
end