3 See the NOTICE file distributed with
this work
for additional information
4 regarding copyright ownership.
6 Licensed under the Apache License, Version 2.0 (the
"License");
7 you may not use
this file except in compliance with the License.
8 You may obtain a copy of the License at
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an
"AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License
for the specific language governing permissions and
16 limitations under the License.
20 package EnsCloud::Describer;
23 requires
'region_alias';
26 use Text::SimpleTable;
27 our $col_widths_headings = {
28 tags => [ 22,
'Tag' ],
29 instance_id => [ 10,
'Instance' ],
30 ip_address => [ 14,
'Ip Address' ],
31 dns_name => [ 57,
'DNS Name' ],
32 instance_type => [ 9,
'Type' ],
33 launch_time => [ 16,
'Launch' ],
34 image_id => [ 12,
'Ami id' ],
35 name => [ 45,
'Name' ],
36 description => [ 45,
'Description' ],
37 image_state => [ 7,
'State' ],
39 # snap_creation => [ 23, 'Snap Creation' ],
40 # [ 13, 'Vol Creation' ]
41 size => [ 5,
'Size' ],
42 create_time => [ 20,
'Create Time' ],
44 # [ 20, 'Attach Time' ],
45 # [ 13, 'Volume Id' ],
47 # [ 10, 'Vol. status' ],
48 # [ 8, 'Attach status' ],
49 # zone => [ 10, 'Zone' ]
50 # [ 13, 'Snapshot Id' ],
51 # [ 19, 'Start Time' ],
53 # status => [ 10, 'Status' ],
55 # [ 11, 'owner alias' ],
58 has ec2_wanted_version => (
60 default =>
'2011-02-28'
66 # isa => 'Net::Amazon::EC2',
70 # has 'region_alias' => (
80 'useast' =>
'us-east-1',
81 'uswest' =>
'us-west-1',
82 'asia' =>
'ap-southeast-1',
84 return Net::Amazon::EC2->new(
85 AWSAccessKeyId => $ENV{AWS_ACCESS_KEY_ID},
86 SecretAccessKey => $ENV{AWS_ACCESS_KEY_SECRET},
88 region => $region_lookup->{ $self->region_alias },
89 version => $self->ec2_wanted_version
97 my $volumes = $self->ec2->describe_volumes;
98 my @sorted_volumes = sort { $a->{size} <=> $b->{size} } @$volumes;
100 my $instances = $self->ec2->describe_instances;
104 foreach my $instance (@$instances) {
106 # print dump $instance->instances_set;
108 my $instance_set = $instance->instances_set->[0];
109 $instance2ip->{ $instance_set->{instance_id} } =
110 $instance_set->{ip_address};
115 my $table = Text::SimpleTable->new(
117 [ 20,
'Create Time' ],
118 [ 20,
'Attach Time' ],
120 [ 13,
'Instance Id' ],
121 [ 15,
'Ip Address' ],
123 [ 10,
'Vol. status' ],
124 [ 8,
'Attach status' ],
125 [ 13,
'Snapshot Id' ],
129 foreach my $volume (@sorted_volumes) {
131 # print dump $instance->instances_set;
133 my $attachments = $volume->attachments;
136 "Volume [$volume->{volume_id}] is attached to multiple instances: this not handled by this script\n"
138 if @$attachments > 1;
139 $volume->{create_time} =~ s/.000Z$
140 $attachments->[0]->{attach_time} =~ s/.000Z$
142 # die dump $instance_set;
145 $volume->{create_time},
146 $attachments->[0]->{attach_time} ||
'',
147 $volume->{volume_id},
148 $attachments->[0]->{instance_id} ||
'',
149 $instance2ip->{ $attachments->[0]->{instance_id} } ||
'',
150 $attachments->[0]->{device} ||
'',
152 $attachments->[0]->{status} ||
'',
154 $volume->{snapshot_id} ||
'no snapshot',
166 my $instances = $self->ec2->describe_instances;
167 my $table = Text::SimpleTable->new(
168 $col_widths_headings->{tags},
169 $col_widths_headings->{instance_id},
170 $col_widths_headings->{ip_address},
171 $col_widths_headings->{dns_name},
172 $col_widths_headings->{instance_type},
173 $col_widths_headings->{launch_time},
174 $col_widths_headings->{image_state},
175 $col_widths_headings->{image_id}
177 foreach my $instance (@$instances) {
179 # print dump $instance->instances_set;
181 my $instance_set = $instance->instances_set->[0];
182 $instance_set->{launch_time} =~ s/:\d+\.000Z$
184 #die dump $instance_set;
186 $instance_set->{tags} ||
'',
187 $instance_set->{instance_id},
188 $instance_set->{ip_address} ||
'',
189 $instance_set->{dns_name} ||
'',
190 $instance_set->{instance_type},
191 $instance_set->{launch_time},
192 $instance_set->{instance_state}->name,
193 $instance_set->{image_id},
199 # __PACKAGE__->meta->make_immutable;