| 1 | package VM::EC2::Instance::Set; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | VM::EC2::Instance::Set - Object describing a set of instances | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | use VM::EC2; | ||
| 10 | |||
| 11 | $ec2 = VM::EC2->new(...); | ||
| 12 | @instances = $ec2->run_instances(-image_id=>'ami-12345'); | ||
| 13 | for my $i (@instances) { | ||
| 14 | $res = $i->reservationId; | ||
| 15 | $req = $i->requesterId; | ||
| 16 | $owner = $i->ownerId; | ||
| 17 | @groups = $i->groups; | ||
| 18 | } | ||
| 19 | |||
| 20 | =head1 DESCRIPTION | ||
| 21 | |||
| 22 | This object is used internally to manage the output of | ||
| 23 | VM::EC2->run_instances(), which returns information about the | ||
| 24 | reservation and security groups as well as the list of launched | ||
| 25 | instances. Because reservations are infrequently used, this object is | ||
| 26 | not used directly; instead the reservation and requester IDs contained | ||
| 27 | within it are stored in the VM::EC2::Instance objects returned | ||
| 28 | by run_instances(). | ||
| 29 | |||
| 30 | =head1 METHODS | ||
| 31 | |||
| 32 | One object method is supported: | ||
| 33 | |||
| 34 | =head2 @instances = $reservation_set->instances() | ||
| 35 | |||
| 36 | This will return the instances contained within the instance set. | ||
| 37 | |||
| 38 | =head1 SEE ALSO | ||
| 39 | |||
| 40 | L<VM::EC2> | ||
| 41 | L<VM::EC2::Generic> | ||
| 42 | L<VM::EC2::Instance> | ||
| 43 | |||
| 44 | =head1 AUTHOR | ||
| 45 | |||
| 46 | Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>. | ||
| 47 | |||
| 48 | Copyright (c) 2011 Ontario Institute for Cancer Research | ||
| 49 | |||
| 50 | This package and its accompanying libraries is free software; you can | ||
| 51 | redistribute it and/or modify it under the terms of the GPL (either | ||
| 52 | version 1, or at your option, any later version) or the Artistic | ||
| 53 | License 2.0. Refer to LICENSE for the full license text. In addition, | ||
| 54 | please see DISCLAIMER.txt for disclaimers of warranty. | ||
| 55 | |||
| 56 | =cut | ||
| 57 | |||
| 58 | |||
| 59 | use strict; | ||
| 60 | use base 'VM::EC2::Generic'; | ||
| 61 | use VM::EC2::Instance; | ||
| 62 | use VM::EC2::Group; | ||
| 63 | |||
| 64 | sub instances { | ||
| 65 | my $self = shift; | ||
| 66 | |||
| 67 | my $p = $self->payload; | ||
| 68 | my $reservation_id = $p->{reservationId}; | ||
| 69 | my $owner_id = $p->{ownerId}; | ||
| 70 | my $requester_id = $p->{requesterId}; | ||
| 71 | my @groups = map {VM::EC2::Group->new($_,$self->aws, | ||
| 72 | $self->xmlns,$self->requestId)} @{$p->{groupSet}{item}}; | ||
| 73 | |||
| 74 | my $instances = $p->{instancesSet}{item}; | ||
| 75 | return map {VM::EC2::Instance->new( | ||
| 76 | -instance => $_, | ||
| 77 | -aws => $self->aws, | ||
| 78 | -xmlns => $self->xmlns, | ||
| 79 | -requestId => $self->requestId, | ||
| 80 | -reservation => $reservation_id, | ||
| 81 | -requester => $requester_id, | ||
| 82 | -owner => $owner_id, | ||
| 83 | -groups => \@groups) | ||
| 84 | } @$instances; | ||
| 85 | } | ||
| 86 | |||
| 87 | |||
| 88 | 1; |