Skip to content

Commit

Permalink
support filter for describe_instances
Browse files Browse the repository at this point in the history
  • Loading branch information
clkao committed Feb 20, 2012
1 parent 8ec4c22 commit 7e4900a
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions lib/Net/Amazon/EC2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,22 @@ sub _hashit {
return $encoded;
}

sub _build_filters {
my ($self, $args) = @_;
my $filters = delete $args->{Filter};

return unless $filters && ref($filters) eq 'ARRAY';

$filters = [ $filters ] unless ref($filters->[0]) eq 'ARRAY';
my $count = 1;
foreach my $filter (@{$filters}) {
my ($name, @args) = @$filter;
$args->{"Filter." . $count.".Name"} = $name;
$args->{"Filter." . $count.".Value.".$_} = $args[$_-1] for 1..scalar @args;
$count++;
}
}

=head1 OBJECT METHODS
=head2 allocate_address()
Expand Down Expand Up @@ -1686,7 +1702,8 @@ Returns an array ref of Net::Amazon::EC2::ReservationInfo objects
sub describe_instances {
my $self = shift;
my %args = validate( @_, {
InstanceId => { type => SCALAR | ARRAYREF, optional => 1 },
InstanceId => { type => SCALAR | ARRAYREF, optional => 1 },
Filter => { type => ARRAYREF, optional => 1 },
});

# If we have a array ref of instances lets split them out into their InstanceId.n format
Expand All @@ -1698,7 +1715,8 @@ sub describe_instances {
$count++;
}
}


$self->_build_filters(\%args);
my $xml = $self->_sign(Action => 'DescribeInstances', %args);
my $reservations;

Expand Down

0 comments on commit 7e4900a

Please sign in to comment.