-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_insts
executable file
·74 lines (70 loc) · 2.55 KB
/
my_insts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/perl -w
#
use strict;
use warnings;
my $filters = "";
my $queries = "InstanceId";
my $output = "text";
my $show_reservation = 0;
my $except_insts = {};
while( @ARGV != 0 )
{
my $arg = shift @ARGV;
if ( $arg eq "-time" ) {
$filters .= "\"Name=launch-time,Values=" . (shift @ARGV) . "\"";
} elsif ( $arg eq "-state" ) {
$filters .= "\"Name=instance-state-name,Values=" . (shift @ARGV) . "\"";
} elsif ( $arg eq "-type" ) {
$filters .= "\"Name=instance-type,Values=" . (shift @ARGV) . "\"";
} elsif ( $arg eq "-image" ) {
$filters .= "\"Name=image-id,Values=" . (shift @ARGV) . "\"";
} elsif ( $arg eq "-zone" ) {
$filters .= "\"Name=availability-zone,Values=" . (shift @ARGV) . "\"";
} elsif ( $arg eq "-token" ) {
$filters .= "\"Name=client-token,Values=" . (shift @ARGV) . "\"";
} elsif ( $arg eq "-reservation" ) {
$filters .= "\"Name=reservation-id,Values=" . (shift @ARGV) . "\"";
} elsif ( $arg eq "-except_master" ) {
my $inst = `master_inst`;
$except_insts->{$inst} = 1;
} elsif ( $arg eq "-except" ) {
my $inst = shift @ARGV;
$except_insts->{$inst} = 1;
} elsif ( $arg eq "-show_time" ) {
$queries .= ",LaunchTime";
} elsif ( $arg eq "-show_state" ) {
$queries .= ",State.Name";
} elsif ( $arg eq "-show_type" ) {
$queries .= ",InstanceType";
} elsif ( $arg eq "-show_image" ) {
$queries .= ",ImageId";
} elsif ( $arg eq "-show_zone" ) {
$queries .= ",Placement.AvailabilityZone";
} elsif ( $arg eq "-show_script" ) {
$queries .= ",UserData";
} elsif ( $arg eq "-show_token" ) {
$queries .= ",ClientToken";
} elsif ( $arg eq "-show_useful" ) {
$queries .= ",LaunchTime,State.Name,InstanceType,ImageId,Placement.AvailabilityZone,UserData,ClientToken";
} elsif ( $arg eq "-show_reservation" ) {
$show_reservation = 1;
} elsif ( $arg eq "-json" ) {
$output = "json";
} else {
die "ERROR: unknown create_insts option '$arg'\n";
}
}
$queries = "--query Reservations[*].[Instances[*].[${queries}]]";
$show_reservation and $queries =~ s/Instances/ReservationId,Instances/;
$filters ne "" and $filters = "--filters ${filters}";
my @lines = `aws ec2 describe-instances ${filters} ${queries} --output ${output}`;
for my $line ( @lines )
{
if ( scalar( keys %$except_insts ) ) {
my ( $inst, @rest ) = split( /\s+/, $line );
if ( exists $except_insts->{$inst} ) {
next;
}
}
print $line;
}