EC2.pm

filter: Statementstmt 21.6% 322 / 1490 Branchbran 4.5% 20 / 442 Conditioncond 1.3% 5 / 375 MC/DCmcdc 0.4% 1 / 242 Subroutinesub 53.7% 78 / 145 Podpod 95.0% 58 / 61 totaltotal 17.5% 484 / 2755 CC 418 SCAR 55.2
CC
418
Cov
15%
describe_instances
1310.1
run_instances
1122.0
describe_security_groups
650.0
CRAP 249.4
↑ Summary EC2/RunningInstances.pm »
1 package Net::Amazon::EC2;
2 1 $Net::Amazon::EC2::VERSION = '0.36';
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use LWP::Protocol::https;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Digest::SHA qw(hmac_sha256 hmac_sha256_hex sha256_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use MIME::Base64 qw(encode_base64 decode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use POSIX qw(strftime);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Params::Validate qw(validate SCALAR ARRAYREF HASHREF BOOLEAN);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Data::Dumper qw(Dumper);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use URI::Escape qw(uri_escape_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Encode qw(encode_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶use Net::Amazon::EC2::DescribeImagesResponse;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Net::Amazon::EC2::DescribeKeyPairsResponse;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Net::Amazon::EC2::DescribeSubnetResponse;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Net::Amazon::EC2::GroupSet;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Net::Amazon::EC2::InstanceState;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use Net::Amazon::EC2::IpPermission;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use Net::Amazon::EC2::LaunchPermission;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use Net::Amazon::EC2::LaunchPermissionOperation;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use Net::Amazon::EC2::ProductCode;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use Net::Amazon::EC2::ProductInstanceResponse;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use Net::Amazon::EC2::ReservationInfo;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use Net::Amazon::EC2::RunningInstances;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use Net::Amazon::EC2::SecurityGroup;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use Net::Amazon::EC2::UserData;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use Net::Amazon::EC2::UserIdGroupPair;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 ▶use Net::Amazon::EC2::IpRange;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶use Net::Amazon::EC2::KeyPair;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use Net::Amazon::EC2::DescribeImageAttribute;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶use Net::Amazon::EC2::ConsoleOutput;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use Net::Amazon::EC2::Errors;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 1 ▶use Net::Amazon::EC2::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶use Net::Amazon::EC2::ConfirmProductInstanceResponse;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 ▶use Net::Amazon::EC2::DescribeAddress;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶use Net::Amazon::EC2::AvailabilityZone;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 ▶use Net::Amazon::EC2::BlockDeviceMapping;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 ▶use Net::Amazon::EC2::PlacementResponse;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 1 ▶use Net::Amazon::EC2::Volume;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 1 ▶use Net::Amazon::EC2::Attachment;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 1 ▶use Net::Amazon::EC2::Snapshot;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 1 ▶use Net::Amazon::EC2::BundleInstanceResponse;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 1 ▶use Net::Amazon::EC2::Region;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 1 ▶use Net::Amazon::EC2::ReservedInstance;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 1 ▶use Net::Amazon::EC2::ReservedInstanceOffering;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 1 ▶use Net::Amazon::EC2::MonitoredInstance;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 1 ▶use Net::Amazon::EC2::InstancePassword;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 1 ▶use Net::Amazon::EC2::SnapshotAttribute;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 1 ▶use Net::Amazon::EC2::CreateVolumePermission;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 1 ▶use Net::Amazon::EC2::AvailabilityZoneMessage;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 1 ▶use Net::Amazon::EC2::StateReason;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 1 ▶use Net::Amazon::EC2::InstanceBlockDeviceMapping;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 1 ▶use Net::Amazon::EC2::InstanceStateChange;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 1 ▶use Net::Amazon::EC2::DescribeInstanceAttributeResponse;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 1 ▶use Net::Amazon::EC2::EbsInstanceBlockDeviceMapping;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 1 ▶use Net::Amazon::EC2::EbsBlockDevice;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 1 ▶use Net::Amazon::EC2::TagSet;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 1 ▶use Net::Amazon::EC2::DescribeTags;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 1 ▶use Net::Amazon::EC2::Details;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 1 ▶use Net::Amazon::EC2::Events;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 1 ▶use Net::Amazon::EC2::InstanceStatus;
Subroutine BEGIN: called CC=1 SCAR=0.0
69 1 ▶use Net::Amazon::EC2::InstanceStatuses;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 1 ▶use Net::Amazon::EC2::SystemStatus;
Subroutine BEGIN: called CC=1 SCAR=0.0
71 1 ▶use Net::Amazon::EC2::NetworkInterfaceSet;
Subroutine BEGIN: called CC=1 SCAR=0.0
72  
73 =head1 NAME
74  
75 Net::Amazon::EC2 - Perl interface to the Amazon Elastic Compute Cloud (EC2)
76 environment.
77  
78 =head1 VERSION
79  
80 EC2 Query API version: '2014-06-15'
81  
82 =head1 SYNOPSIS
83  
84 use Net::Amazon::EC2;
85  
86 my $ec2 = Net::Amazon::EC2->new(
87 AWSAccessKeyId => 'PUBLIC_KEY_HERE',
88 SecretAccessKey => 'SECRET_KEY_HERE',
89 signature_version => 4,
90 );
91  
92 # Start 1 new instance from AMI: ami-XXXXXXXX
93 my $instance = $ec2->run_instances(ImageId => 'ami-XXXXXXXX', MinCount => 1, MaxCount => 1);
94  
95 my $running_instances = $ec2->describe_instances;
96  
97 foreach my $reservation (@$running_instances) {
98 foreach my $instance ($reservation->instances_set) {
99 print $instance->instance_id . "\n";
100 }
101 }
102  
103 my $instance_id = $instance->instances_set->[0]->instance_id;
104  
105 print "$instance_id\n";
106  
107 # Terminate instance
108  
109 my $result = $ec2->terminate_instances(InstanceId => $instance_id);
110  
111 If an error occurs while communicating with EC2, these methods will
112 throw a L<Net::Amazon::EC2::Errors> exception.
113  
114 =head1 DESCRIPTION
115  
116 This module is a Perl interface to Amazon's Elastic Compute Cloud. It uses the Query API to
117 communicate with Amazon's Web Services framework.
118  
119 =head1 CLASS METHODS
120  
121 =head2 new(%params)
122  
123 This is the constructor, it will return you a Net::Amazon::EC2 object to work with. It takes
124 these parameters:
125  
126 =over
127  
128 =item AWSAccessKeyId (required, unless an IAM role is present)
129  
130 Your AWS access key. For information on IAM roles, see L<http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/UsingIAM.html#UsingIAMrolesWithAmazonEC2Instances>
131  
132 =item SecretAccessKey (required, unless an IAM role is present)
133  
134 Your secret key, B<WARNING!> don't give this out or someone will be able to use your account
135 and incur charges on your behalf.
136  
137 =item SecurityToken (optional)
138  
139 When using temporary credentials from STS the Security Token must be passed
140 in along with the temporary AWSAccessKeyId and SecretAccessKey. The most common case is when using IAM credentials with the addition of MFA (multi-factor authentication). See L<http://docs.aws.amazon.com/STS/latest/UsingSTS/Welcome.html>
141  
142 =item region (optional)
143  
144 The region to run the API requests through. Defaults to us-east-1.
145  
146 =item ssl (optional)
147  
148 If set to a true value, the base_url will use https:// instead of http://. Setting base_url
149 explicitly will override this. Defaults to true as of 0.22.
150  
151 =item debug (optional)
152  
153 A flag to turn on debugging. Among other useful things, it will make the failing api calls print
154 a stack trace. It is turned off by default.
155  
156 =item return_errors (optional)
157  
158 Previously, Net::Amazon::EC2 would return a L<Net::Amazon::EC2::Errors>
159 object when it encountered an error condition. As of 0.19, this
160 object is thrown as an exception using croak or confess depending on
161 if the debug flag is set.
162  
163 If you want/need the old behavior, set this attribute to a true value.
164  
165 =back
166  
167 =cut
168  
169 has 'AWSAccessKeyId' => (
170 is => 'ro',
171 isa => 'Str',
172 required => 1,
173 lazy => 1,
174 0 ▶ default => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
175 0 ▶ if (defined($_[0]->temp_creds)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]->temp_creds) { } 0 0 0
176 0 return $_[0]->temp_creds->{'AccessKeyId'};
177 } else {
178 0 return undef;
179 }
180 }
181 1 );
182 has 'SecretAccessKey' => (
183 is => 'ro',
184 isa => 'Str',
185 required => 1,
186 lazy => 1,
187 0 ▶ default => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
188 0 ▶ if (defined($_[0]->temp_creds)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]->temp_creds) { } 0 0 0
189 0 return $_[0]->temp_creds->{'SecretAccessKey'};
190 } else {
191 0 return undef;
192 }
193 }
194 1 );
195 has 'SecurityToken' => (
196 is => 'ro',
197 isa => 'Maybe[Str]',
198 required => 0,
199 predicate => 'has_SecurityToken',
200 3 ▶ default => sub {
Subroutine __ANON__: called CC=2 SCAR=8.1
201 3 ▶ if (defined($_[0]->temp_creds)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0]->temp_creds) { } 0 3 3
202 0 return $_[0]->temp_creds->{'Token'};
203 } else {
204 3 return undef;
205 }
206 }
207 1 );
208 1 has 'debug' => ( is => 'ro', isa => 'Str', required => 0, default => 0 );
209 1 has 'signature_version' => ( is => 'ro', isa => 'Int', required => 1, default => 4 );
210 1 has 'version' => ( is => 'ro', isa => 'Str', required => 1, default => '2014-06-15' );
211 1 has 'region' => ( is => 'ro', isa => 'Str', required => 1, default => 'us-east-1' );
212 1 has 'ssl' => ( is => 'ro', isa => 'Bool', required => 1, default => 1 );
213 1 has 'return_errors' => ( is => 'ro', isa => 'Bool', default => 0 );
214 has 'base_url' => (
215 is => 'ro',
216 isa => 'Str',
217 required => 1,
218 lazy => 1,
219 0 ▶ default => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
220 0 ▶ return 'http' . ($_[0]->ssl ? 's' : '') . '://ec2.' . $_[0]->region . '.amazonaws.com' . ($_[0]->region =~ m/^cn-/ ? '.cn' : '');
Branch: 2 branches
BranchTrueFalseTotal
$_[0]->ssl ? : 0 0 0
$_[0]->region =~ /^cn-/ ? : 0 0 0
221 }
222 1 );
223 has 'temp_creds' => (
224 is => 'ro',
225 3 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
226 3 my $ret;
227 3 $ret = $_[0]->_fetch_iam_security_credentials();
228 },
229 1 predicate => 'has_temp_creds'
230 );
231  
232 0 ▶sub timestamp {
Subroutine timestamp: not called CC=1 SCAR=6.9
Pod undocumented
233 0 return strftime("%Y-%m-%dT%H:%M:%SZ",gmtime);
234 }
235  
236 3 ▶sub _fetch_iam_security_credentials {
Subroutine _fetch_iam_security_credentials: called CC=8 SCAR=33.6
237 3 my $self = shift;
238 3 my $retval = {};
239  
240 3 my $ua = LWP::UserAgent->new();
241 # Fail quickly if this is not running on an EC2 instance
242 3 $ua->timeout(2);
243  
244 3 my $url = 'http://169.254.169.254/latest/meta-data/iam/security-credentials/';
245 3 $self->_debug("Attempting to fetch instance credentials");
246  
247 3 my $res = $ua->get($url);
248 3 ▶ if ($res->code == 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->code == 200) 0 3 3
249 # Assumes the first profile is the only profile
250 0 my $profile = (split /\n/, $res->content())[0];
251  
252 0 $res = $ua->get($url . $profile);
253  
254 0 ▶ if ($res->code == 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->code == 200) 0 0 0
255 0 $retval->{'Profile'} = $profile;
256 0 foreach (split /\n/, $res->content()) {
257 0 ▶ return undef if /Code/ && !/Success/;
Branch: 1 branch
BranchTrueFalseTotal
if /Code/ and not /Success/ 0 0 0
Condition0%0/3
/Code/ and not /Success/
!ll&&!rl&&r
000
MC/DC0%0/2
/Code/ and not /Success/
/Code/ not /Success/
Truth table0%0/3
A and not(B)
A= /Code/B= not /Success/
ABresult
0X0
100
111
258 0 ▶ if (m/.*"([^"]+)"\s+:\s+"([^"]+)",/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/.*"([^"]+)"\s+:\s+"([^"]+)",/) 0 0 0
259 0 $retval->{$1} = $2;
260 }
261 }
262 0 ▶ return $retval if (keys %{$retval});
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$retval;} 0 0 0
263 }
264 }
265 3 return undef;
266 }
267  
268 3 ▶sub _sign {
Subroutine _sign: called CC=3 SCAR=13.3
269 3 my $self = shift;
270  
271 3 ▶ if ( $self->signature_version == 2 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->signature_version == 2) { } 0 3 3
elsif ($self->signature_version == 4) { } 3 0 3
272 0 $self->_sign_v2(@_);
273 }
274 elsif ( $self->signature_version == 4 ) {
275 3 $self->_sign_v4(@_);
276 }
277 else {
278 0 die "I don't know what signature version " .
279 $self->signature_version . "means.\n";
280 }
281 }
282  
283 0 ▶sub _sign_v2 {
Subroutine _sign_v2: not called CC=4 SCAR=30.0
284 0 my $self = shift;
285 0 my %args = @_;
286 0 my $action = delete $args{Action};
287 0 my %sign_hash = %args;
288 0 my $timestamp = $self->timestamp;
289  
290 0 $sign_hash{AWSAccessKeyId} = $self->AWSAccessKeyId;
291 0 $sign_hash{Action} = $action;
292 0 $sign_hash{Timestamp} = $timestamp;
293 0 $sign_hash{Version} = $self->version;
294 0 $sign_hash{SignatureVersion} = $self->signature_version;
295 0 $sign_hash{SignatureMethod} = "HmacSHA256";
296 0 ▶ if ($self->has_temp_creds || $self->has_SecurityToken) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_temp_creds or $self->has_SecurityToken) 0 0 0
Condition0%0/3
$self->has_temp_creds or $self->has_SecurityToken
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->has_temp_creds or $self->has_SecurityToken
$self->has_temp_creds $self->has_SecurityToken
Truth table0%0/3
A or B
A= $self->has_temp_credsB= $self->has_SecurityToken
ABresult
1X1
011
000
297 0 $sign_hash{SecurityToken} = $self->SecurityToken;
298 }
299  
300 0 my $sign_this = "POST\n";
301 0 my $uri = URI->new($self->base_url);
302  
303 0 $sign_this .= lc($uri->host) . "\n";
304 0 $sign_this .= "/\n";
305  
306 0 my @signing_elements;
307  
308 0 foreach my $key (sort keys %sign_hash) {
309 0 push @signing_elements, uri_escape_utf8($key)."=".uri_escape_utf8($sign_hash{$key});
310 }
311  
312 0 $sign_this .= join "&", @signing_elements;
313  
314 0 $self->_debug("QUERY TO SIGN: $sign_this");
315 0 my $encoded = $self->_hashit($self->SecretAccessKey, $sign_this);
316  
317 0 my $content = join "&", @signing_elements, 'Signature=' . uri_escape_utf8($encoded);
318  
319 0 my $ur = $uri->as_string();
320 0 $self->_debug("GENERATED QUERY URL: $ur");
321 0 my $ua = LWP::UserAgent->new();
322 0 $ua->env_proxy;
323 0 my $res = $ua->post($ur, Content => $content);
324 0 $self->_handle_response($res);
325 }
326  
327 0 ▶sub _hashit {
Subroutine _hashit: not called CC=1 SCAR=6.9
328 0 my $self = shift;
329 0 my ($secret_access_key, $query_string) = @_;
330
331 0 return encode_base64(hmac_sha256($query_string, $secret_access_key), '');
332 }
333  
334 3 ▶sub _sign_v4 {
Subroutine _sign_v4: called CC=4 SCAR=13.9
335 3 my $self = shift;
336 3 my %args = @_;
337 3 my $algorithm = 'AWS4-HMAC-SHA256';
338 3 my $service = 'ec2';
339 3 my @now = gmtime();
340 3 my $amz_date = strftime("%Y%m%dT%H%M%SZ", @now);
341 3 my $datestamp = strftime("%Y%m%d", @now);
342 3 my $credential_scope = $datestamp . "/" . $self->region . "/" . $service . "/aws4_request";
343 3 my $content_type = "application/x-www-form-urlencoded";
344 3 my $signed_headers = "content-type;host;x-amz-date";
345  
346 # Step 1: create canonical request string
347 3 my $uri = URI->new($self->base_url);
348 3 my $canonical_headers = "content-type:" . $content_type . "\n" .
349 "host:" . lc($uri->host) . "\n" .
350 "x-amz-date:" . $amz_date . "\n";
351 3 $args{Version} = $self->version;
352 3 ▶ if ($self->SecurityToken) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->SecurityToken) 0 3 3
353 # If we have a security token from an IAM role, passed
354 # as instance metadata, it needs to be included in
355 # the list of canonical headers and passed with the
356 # request
357 0 $args{'X-Amz-Security-Token'} = $self->SecurityToken;
358 0 $canonical_headers .= "x-amz-security-token:". $self->SecurityToken . "\n";
359 0 $signed_headers .= ";x-amz-security-token";
360 }
361 3 my @content_elements;
362 3 foreach my $key (sort keys %args) {
363 6 push @content_elements, uri_escape_utf8($key)."=".uri_escape_utf8($args{$key});
364 }
365 3 my $content .= join "&", @content_elements;
366  
367 3 $self->_debug("CONTENT: $content");
368  
369  
370 3 my $canonical_request = "POST\n"; # method
371 3 $canonical_request .= "/\n"; # uri
372 3 $canonical_request .= "\n"; # query-string
373 3 $canonical_request .= $canonical_headers . "\n"; # headers
374 3 $canonical_request .= $signed_headers . "\n"; # signed headers
375 3 $canonical_request .= sha256_hex($content); # payload
376 3 $self->_debug("CANONICAL REQUEST: $canonical_request");
377  
378 # Step 2: create string to sign
379 3 my $sign_this = $algorithm . "\n";
380 3 $sign_this .= $amz_date . "\n";
381 3 $sign_this .= $credential_scope . "\n";
382 3 $sign_this .= sha256_hex($canonical_request);
383  
384 3 $self->_debug("STRING TO SIGN: $sign_this");
385  
386 # Step 3: calculate the signature
387 3 my $key_date = $self->_hmac(encode_utf8('AWS4' . $self->SecretAccessKey), $datestamp);
388 3 my $key_region = $self->_hmac($key_date, $self->region);
389 3 my $key_service = $self->_hmac($key_region, $service);
390 3 my $signing_key = $self->_hmac($key_service, 'aws4_request');
391  
392 3 my $signature = $self->_hmac($signing_key, encode_utf8($sign_this), 1);
393  
394 # send request
395 3 my $auth_header = $algorithm .
396 ' Credential=' . $self->AWSAccessKeyId . '/' . $credential_scope .
397 ', SignedHeaders=' . $signed_headers .
398 ', Signature=' . $signature;
399  
400  
401 3 my $hdrs = [ "Authorization" => $auth_header,
402 "Content-Type" => $content_type,
403 "X-Amz-Date" => $amz_date ];
404  
405 0 ▶ push @{ $hdrs }, "X-Amz-Security-Token" => $self->SecurityToken if $self->SecurityToken;
Branch: 1 branch
BranchTrueFalseTotal
if $self->SecurityToken 0 3 3
406  
407 3 my $req = HTTP::Request->new('POST', $uri, $hdrs, $content);
408 3 $self->_debug("HTTP REQUEST: " . $req->as_string() . "\n");
409  
410 3 my $ua = LWP::UserAgent->new();
411 3 $ua->env_proxy;
412 3 my $res = $ua->request($req);
413 3 $self->_handle_response($res);
414 }
415  
416 3 ▶sub _handle_response {
Subroutine _handle_response: called CC=3 SCAR=11.1
417 3 my ($self, $res) = @_;
418 # We should force <item> elements to be in an array
419 3 my $xs = XML::Simple->new(
420 ForceArray => qr/(?:item|Errors)/i, # Always want item elements unpacked to arrays
421 KeyAttr => '', # Turn off folding for 'id', 'name', 'key' elements
422 SuppressEmpty => undef, # Turn empty values into explicit undefs
423 );
424 3 my $xml;
425
426 # Check the result for connectivity problems, if so throw an error
427 3 ▶ if ($res->code >= 500) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->code >= 500) { } 3 0 3
428 3 my $message = $res->status_line;
429 3 $xml = <<EOXML;
430 <xml>
431 <RequestID>N/A</RequestID>
432 <Errors>
433 <Error>
434 <Code>HTTP POST FAILURE</Code>
435 <Message>$message</Message>
436 </Error>
437 </Errors>
438 </xml>
439 EOXML
440  
441 }
442 else {
443 0 $xml = $res->content();
444 }
445  
446 3 my $ref = $xs->XMLin($xml);
447 3 ▶ warn Dumper($ref) . "\n\n" if $self->debug == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug == 1 1 2 3
448  
449 3 return $ref;
450 }
451  
452 3 ▶sub _parse_errors {
Subroutine _parse_errors: called CC=5 SCAR=16.1
453 3 my $self = shift;
454 3 my $errors_xml = shift;
455
456 3 my $es;
457 3 my $request_id = $errors_xml->{RequestID};
458  
459 3 foreach my $e (@{$errors_xml->{Errors}}) {
460 my $error = Net::Amazon::EC2::Error->new(
461 code => $e->{Error}{Code},
462 message => $e->{Error}{Message},
463 3 );
464
465 3 push @$es, $error;
466 }
467
468 3 my $errors = Net::Amazon::EC2::Errors->new(
469 request_id => $request_id,
470 errors => $es,
471 );
472  
473 3 foreach my $error (@{$errors->errors}) {
474 3 $self->_debug("ERROR CODE: " . $error->code . " MESSAGE: " . $error->message . " FOR REQUEST: " . $errors->request_id);
475 }
476  
477 # User wants old behaviour
478 3 ▶ if ($self->return_errors) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->return_errors) 1 2 3
479 1 return $errors;
480 }
481  
482 # Print a stack trace if debugging is enabled
483 2 ▶ if ($self->debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug) { } 1 1 2
484 1 confess 'Last error was: ' . $es->[-1]->message;
485 } else {
486 1 croak $errors;
487 }
488 }
489  
490 18 ▶sub _debug {
Subroutine _debug: called CC=4 SCAR=14.3
491 18 my $self = shift;
492 18 my $message = shift;
493
494 18 ▶ if ((grep { defined && length} $self->debug) && $self->debug == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $self->debug and $self->debug == 1) 6 12 18
Condition50%3/6
grep {defined $_ and length $_;} $self->debug and $self->debug == 1
!ll&&!rl&&r
0126
defined $_ && length $_
!ll&&!rl&&r
0018
MC/DC50%1/2
grep {defined $_ and length $_;} $self->debug and $self->debug == 1
grep {defined $_ and length $_;} $self->debug $self->debug == 1
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table66%2/3
A and B
A= grep {defined $_ and length $_;} $self->debugB= $self->debug == 1
ABresult
0X0
100
111
Truth table33%1/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
495 6 print "$message\n\n\n\n";
496 }
497 }
498  
499 15 ▶sub _hmac {
Subroutine _hmac: called CC=2 SCAR=6.9
500 15 my $self = shift;
501 15 my ($key, $msg, $hex) = @_;
502 15 ▶ my $func = $hex ? \&hmac_sha256_hex : \&hmac_sha256;
Branch: 1 branch
BranchTrueFalseTotal
$hex ? : 3 12 15
503 15 return &$func(encode_utf8($msg), $key);
504 }
505  
506 3 ▶sub _build_filters {
Subroutine _build_filters: called CC=6 SCAR=29.7
507 3 my ($self, $args) = @_;
508 3 my $filters = delete $args->{Filter};
509  
510 3 ▶ return unless $filters && ref($filters) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless $filters and ref $filters eq "ARRAY" 3 0 3
Condition33%1/3
$filters and ref $filters eq "ARRAY"
!ll&&!rl&&r
300
MC/DC0%0/2
$filters and ref $filters eq "ARRAY"
$filters ref $filters eq "ARRAY"
Truth table33%1/3
A and B
A= $filtersB= ref $filters eq "ARRAY"
ABresult
0X0
100
111
511  
512 0 ▶ $filters = [ $filters ] unless ref($filters->[0]) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $filters->[0] eq "ARRAY" 0 0 0
513 0 my $count = 1;
514 0 foreach my $filter (@{$filters}) {
515 0 my ($name, @args) = @$filter;
516 0 $args->{"Filter." . $count.".Name"} = $name;
517 0 $args->{"Filter." . $count.".Value.".$_} = $args[$_-1] for 1..scalar @args;
518 0 $count++;
519 }
520 }
521  
522 #Split a list into hash entries, this takes a printf string so we can add the iterator anywhere.
523 #E.g. _split_into_args('Owner.%s',\%args, \@owners) adds the following to %args:
524 # 'Owner.2' => 'account239'
525 # 'Owner.1' => 'account743'
526 # ...
527 0 ▶sub _split_into_args {
Subroutine _split_into_args: not called CC=3 SCAR=24.8
528 0 my ( $formatstr, $hashref, $listref ) = @_;
529  
530 0 my $count = 1;
531 0 foreach my $value ( @{$listref} ) {
532 0 my $formatedstr = sprintf "$formatstr", $count++;
533 0 ▶ $hashref->{$formatedstr} = $value if defined($value);
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 0 0 0
534 }
535 }
536  
537 =head1 OBJECT METHODS
538  
539 =head2 allocate_address()
540  
541 Acquires an elastic IP address which can be associated with an EC2-classic instance to create a movable static IP. Takes no arguments.
542  
543 Returns the IP address obtained.
544  
545 =cut
546  
547 0 ▶sub allocate_address {
Subroutine allocate_address: not called CC=3 SCAR=24.8
Pod documented
548 0 my $self = shift;
549  
550 0 my $xml = $self->_sign(Action => 'AllocateAddress');
551  
552 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
553 0 return $self->_parse_errors($xml);
554 }
555 else {
556 0 return $xml->{publicIp};
557 }
558 }
559  
560 =head2 allocate_vpc_address()
561  
562 Acquires an elastic IP address which can be associated with a VPC instance to create a movable static IP. Takes no arguments.
563  
564 Returns the allocationId of the allocated address.
565  
566 =cut
567  
568 0 ▶sub allocate_vpc_address {
Subroutine allocate_vpc_address: not called CC=3 SCAR=24.8
Pod documented
569 0 my $self = shift;
570  
571 0 my $xml = $self->_sign(Action => 'AllocateAddress', Domain => 'vpc');
572  
573 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
574 0 return $self->_parse_errors($xml);
575 }
576 else {
577 0 return $xml->{allocationId};
578 }
579 }
580  
581 =head2 associate_address(%params)
582  
583 Associates an elastic IP address with an instance. It takes the following arguments:
584  
585 =over
586  
587 =item InstanceId (required)
588  
589 The instance id you wish to associate the IP address with
590  
591 =item PublicIp (optional)
592  
593 The IP address. Used for allocating addresses to EC2-classic instances.
594  
595 =item AllocationId (optional)
596  
597 The allocation ID. Used for allocating address to VPC instances.
598  
599 =back
600  
601 Returns true if the association succeeded.
602  
603 =cut
604  
605 0 ▶sub associate_address {
Subroutine associate_address: not called CC=4 SCAR=30.0
Pod documented
606 0 my $self = shift;
607 0 my %args = validate( @_, {
608 InstanceId => { type => SCALAR },
609 PublicIp => { type => SCALAR, optional => 1 },
610 AllocationId => { type => SCALAR, optional => 1 },
611 });
612
613 0 my $xml = $self->_sign(Action => 'AssociateAddress', %args);
614  
615 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
616 0 return $self->_parse_errors($xml);
617 }
618 else {
619 0 ▶ if ($xml->{return} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'return'} eq 'true') { } 0 0 0
620 0 return 1;
621 }
622 else {
623 0 return undef;
624 }
625 }
626 }
627  
628 =head2 attach_volume(%params)
629  
630 Attach a volume to an instance.
631  
632 =over
633  
634 =item VolumeId (required)
635  
636 The volume id you wish to attach.
637  
638 =item InstanceId (required)
639  
640 The instance id you wish to attach the volume to.
641  
642 =item Device (required)
643  
644 The device id you want the volume attached as.
645  
646 =back
647  
648 Returns a Net::Amazon::EC2::Attachment object containing the resulting volume status.
649  
650 =cut
651  
652 0 ▶sub attach_volume {
Subroutine attach_volume: not called CC=3 SCAR=24.8
Pod documented
653 0 my $self = shift;
654 0 my %args = validate( @_, {
655 VolumeId => { type => SCALAR },
656 InstanceId => { type => SCALAR },
657 Device => { type => SCALAR },
658 });
659  
660 0 my $xml = $self->_sign(Action => 'AttachVolume', %args);
661
662 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
663 0 return $self->_parse_errors($xml);
664 }
665 else {
666 my $attachment = Net::Amazon::EC2::Attachment->new(
667 volume_id => $xml->{volumeId},
668 status => $xml->{status},
669 instance_id => $xml->{instanceId},
670 attach_time => $xml->{attachTime},
671 device => $xml->{device},
672 0 );
673
674 0 return $attachment;
675 }
676 }
677  
678 =head2 authorize_security_group_ingress(%params)
679  
680 This method adds permissions to a security group. It takes the following parameters:
681  
682 =over
683  
684 =item GroupName (required)
685  
686 The name of the group to add security rules to.
687  
688 =item SourceSecurityGroupName (required when authorizing a user and group together)
689  
690 Name of the group to add access for.
691  
692 =item SourceSecurityGroupOwnerId (required when authorizing a user and group together)
693  
694 Owner of the group to add access for.
695  
696 =item IpProtocol (required when adding access for a CIDR)
697  
698 IP Protocol of the rule you are adding access for (TCP, UDP, or ICMP)
699  
700 =item FromPort (required when adding access for a CIDR)
701  
702 Beginning of port range to add access for.
703  
704 =item ToPort (required when adding access for a CIDR)
705  
706 End of port range to add access for.
707  
708 =item CidrIp (required when adding access for a CIDR)
709  
710 The CIDR IP space we are adding access for.
711  
712 =back
713  
714 Adding a rule can be done in two ways: adding a source group name + source group owner id, or,
715 CIDR IP range. Both methods allow IP protocol, from port and to port specifications.
716  
717 Returns 1 if rule is added successfully.
718  
719 =cut
720  
721 0 ▶sub authorize_security_group_ingress {
Subroutine authorize_security_group_ingress: not called CC=4 SCAR=30.0
Pod documented
722 0 my $self = shift;
723 0 my %args = validate( @_, {
724 GroupName => { type => SCALAR, optional => 1 },
725 GroupId => { type => SCALAR, optional => 1 },
726 SourceSecurityGroupName => {
727 type => SCALAR,
728 depends => ['SourceSecurityGroupOwnerId'],
729 optional => 1 ,
730 },
731 SourceSecurityGroupOwnerId => { type => SCALAR, optional => 1 },
732 IpProtocol => {
733 type => SCALAR,
734 depends => ['FromPort', 'ToPort'],
735 optional => 1
736 },
737 FromPort => { type => SCALAR, optional => 1 },
738 ToPort => { type => SCALAR, optional => 1 },
739 CidrIp => { type => SCALAR, optional => 1 },
740 });
741
742
743 0 my $xml = $self->_sign(Action => 'AuthorizeSecurityGroupIngress', %args);
744
745 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
746 0 return $self->_parse_errors($xml);
747 }
748 else {
749 0 ▶ if ($xml->{return} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'return'} eq 'true') { } 0 0 0
750 0 return 1;
751 }
752 else {
753 0 return undef;
754 }
755 }
756 }
757  
758 =head2 bundle_instance(%params)
759  
760 Bundles the Windows instance. This procedure is not applicable for Linux and UNIX instances.
761  
762 NOTE NOTE NOTE This is not well tested as I don't run windows instances
763  
764 =over
765  
766 =item InstanceId (required)
767  
768 The ID of the instance to bundle.
769  
770 =item Storage.S3.Bucket (required)
771  
772 The bucket in which to store the AMI. You can specify a bucket that you already own or a new bucket that Amazon EC2 creates on your behalf. If you specify a bucket that belongs to someone else, Amazon EC2 returns an error.
773  
774 =item Storage.S3.Prefix (required)
775  
776 Specifies the beginning of the file name of the AMI.
777  
778 =item Storage.S3.AWSAccessKeyId (required)
779  
780 The Access Key ID of the owner of the Amazon S3 bucket.
781  
782 =item Storage.S3.UploadPolicy (required)
783  
784 An Amazon S3 upload policy that gives Amazon EC2 permission to upload items into Amazon S3 on the user's behalf.
785  
786 =item Storage.S3.UploadPolicySignature (required)
787  
788 The signature of the Base64 encoded JSON document.
789  
790 JSON Parameters: (all are required)
791  
792 expiration - The expiration of the policy. Amazon recommends 12 hours or longer.
793 conditions - A list of restrictions on what can be uploaded to Amazon S3. Must contain the bucket and ACL conditions in this table.
794 bucket - The bucket to store the AMI.
795 acl - This must be set to ec2-bundle-read.
796  
797 =back
798  
799 Returns a Net::Amazon::EC2::BundleInstanceResponse object
800  
801 =cut
802  
803 0 ▶sub bundle_instance {
Subroutine bundle_instance: not called CC=3 SCAR=24.8
Pod documented
804 0 my $self = shift;
805 0 my %args = validate( @_, {
806 'InstanceId' => { type => SCALAR },
807 'Storage.S3.Bucket' => { type => SCALAR },
808 'Storage.S3.Prefix' => { type => SCALAR },
809 'Storage.S3.AWSAccessKeyId' => { type => SCALAR },
810 'Storage.S3.UploadPolicy' => { type => SCALAR },
811 'Storage.S3.UploadPolicySignature' => { type => SCALAR },
812 });
813  
814 0 my $xml = $self->_sign(Action => 'BundleInstance', %args);
815
816 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
817 0 return $self->_parse_errors($xml);
818 }
819 else {
820 my $bundle = Net::Amazon::EC2::BundleInstanceResponse->new(
821 instance_id => $xml->{bundleInstanceTask}{instanceId},
822 bundle_id => $xml->{bundleInstanceTask}{bundleId},
823 state => $xml->{bundleInstanceTask}{state},
824 start_time => $xml->{bundleInstanceTask}{startTime},
825 update_time => $xml->{bundleInstanceTask}{updateTime},
826 progress => $xml->{bundleInstanceTask}{progress},
827 s3_bucket => $xml->{bundleInstanceTask}{storage}{S3}{bucket},
828 s3_prefix => $xml->{bundleInstanceTask}{storage}{S3}{bucket},
829 s3_aws_access_key_id => $xml->{bundleInstanceTask}{storage}{S3}{bucket},
830 s3_upload_policy => $xml->{bundleInstanceTask}{storage}{S3}{bucket},
831 s3_policy_upload_signature => $xml->{bundleInstanceTask}{storage}{S3}{bucket},
832 bundle_error_code => $xml->{bundleInstanceTask}{error}{code},
833 bundle_error_message => $xml->{bundleInstanceTask}{error}{message},
834 0 );
835
836 0 return $bundle;
837 }
838 }
839  
840 =head2 cancel_bundle_task(%params)
841  
842 Cancels the bundle task. This procedure is not applicable for Linux and UNIX instances.
843  
844 =over
845  
846 =item BundleId (required)
847  
848 The ID of the bundle task to cancel.
849  
850 =back
851  
852 Returns a Net::Amazon::EC2::BundleInstanceResponse object
853  
854 =cut
855  
856 0 ▶sub cancel_bundle_task {
Subroutine cancel_bundle_task: not called CC=3 SCAR=24.8
Pod documented
857 0 my $self = shift;
858 0 my %args = validate( @_, {
859 'BundleId' => { type => SCALAR },
860 });
861  
862 0 my $xml = $self->_sign(Action => 'CancelBundleTask', %args);
863
864 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
865 0 return $self->_parse_errors($xml);
866 }
867 else {
868 my $bundle = Net::Amazon::EC2::BundleInstanceResponse->new(
869 instance_id => $xml->{bundleInstanceTask}{instanceId},
870 bundle_id => $xml->{bundleInstanceTask}{bundleId},
871 state => $xml->{bundleInstanceTask}{state},
872 start_time => $xml->{bundleInstanceTask}{startTime},
873 update_time => $xml->{bundleInstanceTask}{updateTime},
874 progress => $xml->{bundleInstanceTask}{progress},
875 s3_bucket => $xml->{bundleInstanceTask}{storage}{S3}{bucket},
876 s3_prefix => $xml->{bundleInstanceTask}{storage}{S3}{bucket},
877 s3_aws_access_key_id => $xml->{bundleInstanceTask}{storage}{S3}{bucket},
878 s3_upload_policy => $xml->{bundleInstanceTask}{storage}{S3}{bucket},
879 s3_policy_upload_signature => $xml->{bundleInstanceTask}{storage}{S3}{bucket},
880 bundle_error_code => $xml->{bundleInstanceTask}{error}{code},
881 bundle_error_message => $xml->{bundleInstanceTask}{error}{message},
882 0 );
883
884 0 return $bundle;
885 }
886 }
887  
888 =head2 confirm_product_instance(%params)
889  
890 Checks to see if the product code passed in is attached to the instance id, taking the following parameter:
891  
892 =over
893  
894 =item ProductCode (required)
895  
896 The Product Code to check
897  
898 =item InstanceId (required)
899  
900 The Instance Id to check
901  
902 =back
903  
904 Returns a Net::Amazon::EC2::ConfirmProductInstanceResponse object
905  
906 =cut
907  
908 0 ▶sub confirm_product_instance {
Subroutine confirm_product_instance: not called CC=3 SCAR=24.8
Pod documented
909 0 my $self = shift;
910 0 my %args = validate( @_, {
911 ProductCode => { type => SCALAR },
912 InstanceId => { type => SCALAR },
913 });
914  
915 0 my $xml = $self->_sign(Action => 'ConfirmProductInstance', %args);
916
917 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
918 0 return $self->_parse_errors($xml);
919 }
920 else {
921 my $confirm_response = Net::Amazon::EC2::ConfirmProductInstanceResponse->new(
922 'return' => $xml->{'return'},
923 owner_id => $xml->{ownerId},
924 0 );
925
926 0 return $confirm_response;
927 }
928 }
929  
930 =head2 create_image(%params)
931  
932 Creates an AMI that uses an Amazon EBS root device from a "running" or "stopped" instance.
933  
934 AMIs that use an Amazon EBS root device boot faster than AMIs that use instance stores.
935 They can be up to 1 TiB in size, use storage that persists on instance failure, and can be stopped and started.
936  
937 =over
938  
939 =item InstanceId (required)
940  
941 The ID of the instance.
942  
943 =item Name (required)
944  
945 The name of the AMI that was provided during image creation.
946  
947 Note that the image name has the following constraints:
948  
949 3-128 alphanumeric characters, parenthesis, commas, slashes, dashes, or underscores.
950  
951 =item Description (optional)
952  
953 The description of the AMI that was provided during image creation.
954  
955 =item NoReboot (optional)
956  
957 By default this property is set to false, which means Amazon EC2 attempts to cleanly shut down the
958 instance before image creation and reboots the instance afterwards. When set to true, Amazon EC2
959 does not shut down the instance before creating the image. When this option is used, file system
960 integrity on the created image cannot be guaranteed.
961  
962 =item BlockDeviceMapping (optional)
963  
964 Array ref of the device names exposed to the instance.
965  
966 You can specify device names as '<device>=<block_device>' similar to ec2-create-image command. (L<http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-CreateImage.html>)
967  
968 BlockDeviceMapping => [
969 '/dev/sda=:256:true:standard',
970 '/dev/sdb=none',
971 '/dev/sdc=ephemeral0',
972 '/dev/sdd=ephemeral1',
973 ],
974  
975 =back
976  
977 Returns the ID of the AMI created.
978  
979 =cut
980  
981 0 ▶sub create_image {
Subroutine create_image: not called CC=9 SCAR=45.0
Pod documented
982 0 my $self = shift;
983 0 my %args = validate( @_, {
984 InstanceId => { type => SCALAR },
985 Name => { type => SCALAR },
986 Description => { type => SCALAR, optional => 1 },
987 NoReboot => { type => SCALAR, optional => 1 },
988 BlockDeviceMapping => { type => ARRAYREF, optional => 1 },
989 });
990
991  
992 0 ▶ if (my $bdm = delete $args{BlockDeviceMapping}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $bdm = delete $args{"BlockDeviceMapping"}) 0 0 0
993 0 my $n = 0;
994 0 for my $bdme (@$bdm) {
995 0 my($device, $block_device) = split /=/, $bdme, 2;
996 0 $args{"BlockDeviceMapping.${n}.DeviceName"} = $device;
997  
998 0 ▶ if ($block_device =~ /^ephemeral[0-9]+$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($block_device =~ /^ephemeral[0-9]+$/) { } 0 0 0
elsif ($block_device eq 'none') { } 0 0 0
999 0 $args{"BlockDeviceMapping.${n}.VirtualName"} = $block_device;
1000 } elsif ($block_device eq 'none') {
1001 0 $args{"BlockDeviceMapping.${n}.NoDevice"} = '';
1002 } else {
1003 0 my @keys = qw(
1004 Ebs.SnapshotId
1005 Ebs.VolumeSize
1006 Ebs.DeleteOnTermination
1007 Ebs.VolumeType
1008 Ebs.Iops
1009 );
1010 0 for my $bde (split /:/, $block_device) {
1011 0 my $key = shift @keys;
1012 0 ▶ next unless $bde;
Branch: 1 branch
BranchTrueFalseTotal
unless $bde 0 0 0
1013 0 $args{"BlockDeviceMapping.${n}.${key}"} = $bde;
1014 }
1015 }
1016  
1017 0 $n++;
1018 }
1019 }
1020  
1021 0 my $xml = $self->_sign(Action => 'CreateImage', %args);
1022  
1023 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1024 0 return $self->_parse_errors($xml);
1025 }
1026 else {
1027 0 return $xml->{imageId};
1028 }
1029 }
1030  
1031 =head2 create_key_pair(%params)
1032  
1033 Creates a new 2048 bit key pair, taking the following parameter:
1034  
1035 =over
1036  
1037 =item KeyName (required)
1038  
1039 A name for this key. Should be unique.
1040  
1041 =back
1042  
1043 Returns a Net::Amazon::EC2::KeyPair object
1044  
1045 =cut
1046  
1047 0 ▶sub create_key_pair {
Subroutine create_key_pair: not called CC=3 SCAR=24.8
Pod documented
1048 0 my $self = shift;
1049 0 my %args = validate( @_, {
1050 KeyName => { type => SCALAR },
1051 });
1052
1053 0 my $xml = $self->_sign(Action => 'CreateKeyPair', %args);
1054  
1055 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1056 0 return $self->_parse_errors($xml);
1057 }
1058 else {
1059 my $key_pair = Net::Amazon::EC2::KeyPair->new(
1060 key_name => $xml->{keyName},
1061 key_fingerprint => $xml->{keyFingerprint},
1062 key_material => $xml->{keyMaterial},
1063 0 );
1064
1065 0 return $key_pair;
1066 }
1067 }
1068  
1069 =head2 create_security_group(%params)
1070  
1071 This method creates a new security group. It takes the following parameters:
1072  
1073 =over
1074  
1075 =item GroupName (required)
1076  
1077 The name of the new group to create.
1078  
1079 =item GroupDescription (required)
1080  
1081 A short description of the new group.
1082  
1083 =back
1084  
1085 Returns 1 if the group creation succeeds.
1086  
1087 =cut
1088  
1089 0 ▶sub create_security_group {
Subroutine create_security_group: not called CC=4 SCAR=30.0
Pod documented
1090 0 my $self = shift;
1091 0 my %args = validate( @_, {
1092 GroupName => { type => SCALAR },
1093 GroupDescription => { type => SCALAR },
1094 });
1095
1096
1097 0 my $xml = $self->_sign(Action => 'CreateSecurityGroup', %args);
1098  
1099 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1100 0 return $self->_parse_errors($xml);
1101 }
1102 else {
1103 0 ▶ if ($xml->{return} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'return'} eq 'true') { } 0 0 0
1104 0 return 1;
1105 }
1106 else {
1107 0 return undef;
1108 }
1109 }
1110 }
1111  
1112 =head2 create_snapshot(%params)
1113  
1114 Create a snapshot of a volume. It takes the following arguments:
1115  
1116 =over
1117  
1118 =item VolumeId (required)
1119  
1120 The volume id of the volume you want to take a snapshot of.
1121  
1122 =item Description (optional)
1123  
1124 Description of the Amazon EBS snapshot.
1125  
1126 =back
1127  
1128 Returns a Net::Amazon::EC2::Snapshot object of the newly created snapshot.
1129  
1130 =cut
1131  
1132 0 ▶sub create_snapshot {
Subroutine create_snapshot: not called CC=6 SCAR=37.4
Pod documented
1133 0 my $self = shift;
1134 0 my %args = validate( @_, {
1135 VolumeId => { type => SCALAR },
1136 Description => { type => SCALAR, optional => 1 },
1137 });
1138
1139 0 my $xml = $self->_sign(Action => 'CreateSnapshot', %args);
1140  
1141
1142 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1143 0 return $self->_parse_errors($xml);
1144 }
1145 else {
1146 0 ▶ unless ( grep { defined && length } $xml->{progress} and ref $xml->{progress} ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {defined $_ and length $_;} $xml->{"progress"} and ref $xml->{"progress"} ne "HASH") 0 0 0
Condition0%0/6
grep {defined $_ and length $_;} $xml->{"progress"} and ref $xml->{"progress"} ne "HASH"
!ll&&!rl&&r
000
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
grep {defined $_ and length $_;} $xml->{"progress"} and ref $xml->{"progress"} ne "HASH"
grep {defined $_ and length $_;} $xml->{"progress"} ref $xml->{"progress"} ne "HASH"
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A and B
A= grep {defined $_ and length $_;} $xml->{"progress"}B= ref $xml->{"progress"} ne "HASH"
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1147 0 $xml->{progress} = undef;
1148 }
1149  
1150 my $snapshot = Net::Amazon::EC2::Snapshot->new(
1151 snapshot_id => $xml->{snapshotId},
1152 status => $xml->{status},
1153 volume_id => $xml->{volumeId},
1154 start_time => $xml->{startTime},
1155 progress => $xml->{progress},
1156 owner_id => $xml->{ownerId},
1157 volume_size => $xml->{volumeSize},
1158 description => $xml->{description},
1159 0 );
1160  
1161 0 return $snapshot;
1162 }
1163 }
1164  
1165 =head2 create_tags(%params)
1166  
1167 Creates tags.
1168  
1169 =over
1170  
1171 =item ResourceId (required)
1172  
1173 The ID of the resource to create tags. Can be a scalar or arrayref
1174  
1175 =item Tags (required)
1176  
1177 Hashref where keys and values will be set on all resources given in the first element.
1178  
1179 =back
1180  
1181 Returns true if the tag creation succeeded.
1182  
1183 =cut
1184  
1185 0 ▶sub create_tags {
Subroutine create_tags: not called CC=8 SCAR=42.8
Pod documented
1186 0 my $self = shift;
1187 0 my %args = validate( @_, {
1188 ResourceId => { type => ARRAYREF | SCALAR },
1189 Tags => { type => HASHREF },
1190 });
1191  
1192 0 ▶ if (ref ($args{'ResourceId'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{'ResourceId'} eq 'ARRAY') { } 0 0 0
1193 0 my $keys = delete $args{'ResourceId'};
1194 0 _split_into_args('ResourceId.%s',\%args,$keys);
1195 }
1196 else {
1197 0 $args{"ResourceId.1"} = delete $args{'ResourceId'};
1198 }
1199  
1200 0 ▶ if (ref ($args{'Tags'}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"Tags"} eq "HASH") 0 0 0
1201 0 my $count = 1;
1202 0 my $tags = delete $args{'Tags'};
1203 0 foreach my $key ( keys %{$tags} ) {
1204 0 ▶ last if $count > 10;
Branch: 1 branch
BranchTrueFalseTotal
if $count > 10 0 0 0
1205 0 $args{"Tag." . $count . ".Key"} = $key;
1206 0 $args{"Tag." . $count . ".Value"} = $tags->{$key};
1207 0 $count++;
1208 }
1209 }
1210  
1211 0 my $xml = $self->_sign(Action => 'CreateTags', %args);
1212  
1213 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1214 0 return $self->_parse_errors($xml);
1215 }
1216 else {
1217 0 ▶ if ($xml->{return} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'return'} eq 'true') { } 0 0 0
1218 0 return 1;
1219 }
1220 else {
1221 0 return undef;
1222 }
1223 }
1224 }
1225  
1226 =head2 create_volume(%params)
1227  
1228 Creates a volume.
1229  
1230 =over
1231  
1232 =item Size (required)
1233  
1234 The size in GiB ( 1024^3 ) of the volume you want to create.
1235  
1236 =item SnapshotId (optional)
1237  
1238 The optional snapshot id to create the volume from. The volume must
1239 be equal or larger than the snapshot it was created from.
1240  
1241 =item AvailabilityZone (required)
1242  
1243 The availability zone to create the volume in.
1244  
1245 =item VolumeType (optional)
1246  
1247 The volume type: 'standard', 'gp2', or 'io1'. Defaults to 'standard'.
1248  
1249 =item Iops (required if VolumeType is 'io1')
1250  
1251 The number of I/O operations per second (IOPS) that the volume
1252 supports. This is limited to 30 times the volume size with an absolute maximum
1253 of 4000. It's likely these numbers will change in the future.
1254  
1255 Required when the volume type is io1; not used otherwise.
1256  
1257 =item Encrypted (optional)
1258  
1259 Encrypt the volume. EBS encrypted volumes are encrypted on the host using
1260 AWS managed keys. Only some instance types support encrypted volumes. At the
1261 time of writing encrypted volumes are not supported for boot volumes.
1262  
1263 =back
1264  
1265 Returns a Net::Amazon::EC2::Volume object containing the resulting volume
1266 status
1267  
1268 =cut
1269  
1270 0 ▶sub create_volume {
Subroutine create_volume: not called CC=6 SCAR=37.4
Pod documented
1271 0 my $self = shift;
1272 0 my %args = validate( @_, {
1273 Size => { type => SCALAR },
1274 SnapshotId => { type => SCALAR, optional => 1 },
1275 AvailabilityZone => { type => SCALAR },
1276 VolumeType => { type => SCALAR, optional => 1 },
1277 Iops => { type => SCALAR, optional => 1 },
1278 Encrypted => { type => SCALAR, optional => 1 },
1279  
1280 });
1281  
1282 0 my $xml = $self->_sign(Action => 'CreateVolume', %args);
1283  
1284
1285 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1286 0 return $self->_parse_errors($xml);
1287 }
1288 else {
1289  
1290 0 ▶ unless ( grep { defined && length } $xml->{snapshotId} and ref $xml->{snapshotId} ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {defined $_ and length $_;} $xml->{"snapshotId"} and ref $xml->{"snapshotId"} ne "HASH") 0 0 0
Condition0%0/6
grep {defined $_ and length $_;} $xml->{"snapshotId"} and ref $xml->{"snapshotId"} ne "HASH"
!ll&&!rl&&r
000
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
grep {defined $_ and length $_;} $xml->{"snapshotId"} and ref $xml->{"snapshotId"} ne "HASH"
grep {defined $_ and length $_;} $xml->{"snapshotId"} ref $xml->{"snapshotId"} ne "HASH"
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A and B
A= grep {defined $_ and length $_;} $xml->{"snapshotId"}B= ref $xml->{"snapshotId"} ne "HASH"
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1291 0 $xml->{snapshotId} = undef;
1292 }
1293  
1294 my $volume = Net::Amazon::EC2::Volume->new(
1295 volume_id => $xml->{volumeId},
1296 status => $xml->{status},
1297 zone => $xml->{availabilityZone},
1298 create_time => $xml->{createTime},
1299 snapshot_id => $xml->{snapshotId},
1300 size => $xml->{size},
1301 volume_type => $xml->{volumeType},
1302 iops => $xml->{iops},
1303 encrypted => $xml->{encrypted},
1304 0 );
1305  
1306 0 return $volume;
1307 }
1308 }
1309  
1310 =head2 delete_key_pair(%params)
1311  
1312 This method deletes a keypair. Takes the following parameter:
1313  
1314 =over
1315  
1316 =item KeyName (required)
1317  
1318 The name of the key to delete.
1319  
1320 =back
1321  
1322 Returns 1 if the key was successfully deleted.
1323  
1324 =cut
1325  
1326 0 ▶sub delete_key_pair {
Subroutine delete_key_pair: not called CC=4 SCAR=30.0
Pod documented
1327 0 my $self = shift;
1328 0 my %args = validate( @_, {
1329 KeyName => { type => SCALAR },
1330 });
1331
1332 0 my $xml = $self->_sign(Action => 'DeleteKeyPair', %args);
1333  
1334 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1335 0 return $self->_parse_errors($xml);
1336 }
1337 else {
1338 0 ▶ if ($xml->{return} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'return'} eq 'true') { } 0 0 0
1339 0 return 1;
1340 }
1341 else {
1342 0 return undef;
1343 }
1344 }
1345 }
1346  
1347 =head2 delete_security_group(%params)
1348  
1349 This method deletes a security group. It takes the following parameter:
1350  
1351 =over
1352  
1353 =item GroupName (required)
1354  
1355 The name of the security group to delete.
1356  
1357 =back
1358  
1359 Returns 1 if the delete succeeded.
1360  
1361 =cut
1362  
1363 0 ▶sub delete_security_group {
Subroutine delete_security_group: not called CC=4 SCAR=30.0
Pod documented
1364 0 my $self = shift;
1365 0 my %args = validate( @_, {
1366 GroupName => { type => SCALAR },
1367 });
1368
1369
1370 0 my $xml = $self->_sign(Action => 'DeleteSecurityGroup', %args);
1371
1372 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1373 0 return $self->_parse_errors($xml);
1374 }
1375 else {
1376 0 ▶ if ($xml->{return} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'return'} eq 'true') { } 0 0 0
1377 0 return 1;
1378 }
1379 else {
1380 0 return undef;
1381 }
1382 }
1383 }
1384  
1385 =head2 delete_snapshot(%params)
1386  
1387 Deletes the snapshots passed in. It takes the following arguments:
1388  
1389 =over
1390  
1391 =item SnapshotId (required)
1392  
1393 A snapshot id can be passed in. Will delete the corresponding snapshot.
1394  
1395 =back
1396  
1397 Returns true if the deleting succeeded.
1398  
1399 =cut
1400  
1401 0 ▶sub delete_snapshot {
Subroutine delete_snapshot: not called CC=4 SCAR=30.0
Pod documented
1402 0 my $self = shift;
1403 0 my %args = validate( @_, {
1404 SnapshotId => { type => SCALAR },
1405 });
1406  
1407 0 my $xml = $self->_sign(Action => 'DeleteSnapshot', %args);
1408  
1409 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1410 0 return $self->_parse_errors($xml);
1411 }
1412 else {
1413 0 ▶ if ($xml->{return} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'return'} eq 'true') { } 0 0 0
1414 0 return 1;
1415 }
1416 else {
1417 0 return undef;
1418 }
1419 }
1420 }
1421  
1422 =head2 delete_volume(%params)
1423  
1424 Delete a volume.
1425  
1426 =over
1427  
1428 =item VolumeId (required)
1429  
1430 The volume id you wish to delete.
1431  
1432 =back
1433  
1434 Returns true if the deleting succeeded.
1435  
1436 =cut
1437  
1438 0 ▶sub delete_volume {
Subroutine delete_volume: not called CC=4 SCAR=30.0
Pod documented
1439 0 my $self = shift;
1440 0 my %args = validate( @_, {
1441 VolumeId => { type => SCALAR, optional => 1 },
1442 });
1443  
1444 0 my $xml = $self->_sign(Action => 'DeleteVolume', %args);
1445  
1446
1447 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1448 0 return $self->_parse_errors($xml);
1449 }
1450 else {
1451 0 ▶ if ($xml->{return} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'return'} eq 'true') { } 0 0 0
1452 0 return 1;
1453 }
1454 else {
1455 0 return undef;
1456 }
1457 }
1458 }
1459  
1460 =head2 delete_tags(%params)
1461  
1462 Delete tags.
1463  
1464 =over
1465  
1466 =item ResourceId (required)
1467  
1468 The ID of the resource to delete tags
1469  
1470 =item Tag.Key (required)
1471  
1472 Key for a tag, may pass in a scalar or arrayref.
1473  
1474 =item Tag.Value (required)
1475  
1476 Value for a tag, may pass in a scalar or arrayref.
1477  
1478 =back
1479  
1480 Returns true if the releasing succeeded.
1481  
1482 =cut
1483  
1484 0 ▶sub delete_tags {
Subroutine delete_tags: not called CC=6 SCAR=37.4
Pod documented
1485 0 my $self = shift;
1486 0 my %args = validate( @_, {
1487 ResourceId => { type => ARRAYREF | SCALAR },
1488 'Tag.Key' => { type => ARRAYREF | SCALAR },
1489 'Tag.Value' => { type => ARRAYREF | SCALAR, optional => 1 },
1490 });
1491  
1492 # If we have a array ref of keys lets split them out into their Tag.n.Key format
1493 0 ▶ if (ref ($args{'Tag.Key'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"Tag.Key"} eq "ARRAY") 0 0 0
1494 0 my $keys = delete $args{'Tag.Key'};
1495 0 _split_into_args('Tag.%s.Key',\%args,$keys);
1496 }
1497  
1498 # If we have a array ref of values lets split them out into their Tag.n.Value format
1499 0 ▶ if (ref ($args{'Tag.Value'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"Tag.Value"} eq "ARRAY") 0 0 0
1500 0 my $values = delete $args{'Tag.Value'};
1501 0 _split_into_args('Tag.%s.Value',\%args,$values);
1502 }
1503  
1504 0 my $xml = $self->_sign(Action => 'DeleteTags', %args);
1505  
1506 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1507 0 return $self->_parse_errors($xml);
1508 }
1509 else {
1510 0 ▶ if ($xml->{return} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'return'} eq 'true') { } 0 0 0
1511 0 return 1;
1512 }
1513 else {
1514 0 return undef;
1515 }
1516 }
1517 }
1518  
1519  
1520 =head2 deregister_image(%params)
1521  
1522 This method will deregister an AMI. It takes the following parameter:
1523  
1524 =over
1525  
1526 =item ImageId (required)
1527  
1528 The image id of the AMI you want to deregister.
1529  
1530 =back
1531  
1532 Returns 1 if the deregistering succeeded
1533  
1534 =cut
1535  
1536 0 ▶sub deregister_image {
Subroutine deregister_image: not called CC=4 SCAR=30.0
Pod documented
1537 0 my $self = shift;
1538 0 my %args = validate( @_, {
1539 ImageId => { type => SCALAR },
1540 });
1541
1542  
1543 0 my $xml = $self->_sign(Action => 'DeregisterImage', %args);
1544  
1545 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1546 0 return $self->_parse_errors($xml);
1547 }
1548 else {
1549 0 ▶ if ($xml->{return} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'return'} eq 'true') { } 0 0 0
1550 0 return 1;
1551 }
1552 else {
1553 0 return undef;
1554 }
1555 }
1556 }
1557  
1558 =head2 describe_addresses(%params)
1559  
1560 This method describes the elastic addresses currently allocated and any instances associated with them. It takes the following arguments:
1561  
1562 =over
1563  
1564 =item PublicIp (optional)
1565  
1566 The IP address to describe. Can be either a scalar or an array ref.
1567  
1568 =back
1569  
1570 Returns an array ref of Net::Amazon::EC2::DescribeAddress objects
1571  
1572 =cut
1573  
1574 0 ▶sub describe_addresses {
Subroutine describe_addresses: not called CC=6 SCAR=37.4
Pod documented
1575 0 my $self = shift;
1576 0 my %args = validate( @_, {
1577 PublicIp => { type => SCALAR | ARRAYREF, optional => 1 },
1578 });
1579  
1580 # If we have a array ref of ip addresses lets split them out into their PublicIp.n format
1581 0 ▶ if (ref ($args{PublicIp}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"PublicIp"} eq "ARRAY") 0 0 0
1582 0 my $ip_addresses = delete $args{PublicIp};
1583 0 _split_into_args('PublicIp.%s',\%args,$ip_addresses);
1584 }
1585
1586 0 my $addresses;
1587 0 my $xml = $self->_sign(Action => 'DescribeAddresses', %args);
1588
1589 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1590 0 return $self->_parse_errors($xml);
1591 }
1592 else {
1593 0 foreach my $addy (@{$xml->{addressesSet}{item}}) {
1594 0 ▶ if (ref($addy->{instanceId}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $addy->{"instanceId"} eq "HASH") 0 0 0
1595 0 undef $addy->{instanceId};
1596 }
1597
1598 my $address = Net::Amazon::EC2::DescribeAddress->new(
1599 public_ip => $addy->{publicIp},
1600 instance_id => $addy->{instanceId},
1601 0 );
1602
1603 0 push @$addresses, $address;
1604 }
1605
1606 0 return $addresses;
1607 }
1608 }
1609  
1610 =head2 describe_availability_zones(%params)
1611  
1612 This method describes the availability zones currently available to choose from. It takes the following arguments:
1613  
1614 =over
1615  
1616 =item ZoneName (optional)
1617  
1618 The zone name to describe. Can be either a scalar or an array ref.
1619  
1620 =back
1621  
1622 Returns an array ref of Net::Amazon::EC2::AvailabilityZone objects
1623  
1624 =cut
1625  
1626 0 ▶sub describe_availability_zones {
Subroutine describe_availability_zones: not called CC=6 SCAR=37.4
Pod documented
1627 0 my $self = shift;
1628 0 my %args = validate( @_, {
1629 ZoneName => { type => SCALAR | ARRAYREF, optional => 1 },
1630 });
1631  
1632 # If we have a array ref of zone names lets split them out into their ZoneName.n format
1633 0 ▶ if (ref ($args{ZoneName}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"ZoneName"} eq "ARRAY") 0 0 0
1634 0 my $zone_names = delete $args{ZoneName};
1635 0 _split_into_args('ZoneName.%s',\%args,$zone_names);
1636 }
1637
1638 0 my $xml = $self->_sign(Action => 'DescribeAvailabilityZones', %args);
1639  
1640 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1641 0 return $self->_parse_errors($xml);
1642 }
1643 else {
1644 0 my $availability_zones;
1645 0 foreach my $az (@{$xml->{availabilityZoneInfo}{item}}) {
1646 0 my $availability_zone_messages;
1647 # Create the messages for this zone
1648 0 foreach my $azm (@{$az->{messageSet}{item}}) {
1649 my $availability_zone_message = Net::Amazon::EC2::AvailabilityZoneMessage->new(
1650 message => $azm->{message},
1651 0 );
1652
1653 0 push @$availability_zone_messages, $availability_zone_message;
1654 }
1655
1656 my $availability_zone = Net::Amazon::EC2::AvailabilityZone->new(
1657 zone_name => $az->{zoneName},
1658 zone_state => $az->{zoneState},
1659 region_name => $az->{regionName},
1660 0 messages => $availability_zone_messages,
1661 );
1662
1663 0 push @$availability_zones, $availability_zone;
1664 }
1665
1666 0 return $availability_zones;
1667 }
1668 }
1669  
1670 =head2 describe_bundle_tasks(%params)
1671  
1672 Describes current bundling tasks. This procedure is not applicable for Linux and UNIX instances.
1673  
1674 =over
1675  
1676 =item BundleId (optional)
1677  
1678 The optional ID of the bundle task to describe.
1679  
1680 =back
1681  
1682 Returns a array ref of Net::Amazon::EC2::BundleInstanceResponse objects
1683  
1684 =cut
1685  
1686 0 ▶sub describe_bundle_tasks {
Subroutine describe_bundle_tasks: not called CC=4 SCAR=30.0
Pod documented
1687 0 my $self = shift;
1688 0 my %args = validate( @_, {
1689 'BundleId' => { type => SCALAR, optional => 1 },
1690 });
1691  
1692 0 my $xml = $self->_sign(Action => 'DescribeBundleTasks', %args);
1693
1694 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1695 0 return $self->_parse_errors($xml);
1696 }
1697 else {
1698 0 my $bundle_tasks;
1699
1700 0 foreach my $item (@{$xml->{bundleInstanceTasksSet}{item}}) {
1701 my $bundle = Net::Amazon::EC2::BundleInstanceResponse->new(
1702 instance_id => $item->{instanceId},
1703 bundle_id => $item->{bundleId},
1704 state => $item->{state},
1705 start_time => $item->{startTime},
1706 update_time => $item->{updateTime},
1707 progress => $item->{progress},
1708 s3_bucket => $item->{storage}{S3}{bucket},
1709 s3_prefix => $item->{storage}{S3}{bucket},
1710 s3_aws_access_key_id => $item->{storage}{S3}{bucket},
1711 s3_upload_policy => $item->{storage}{S3}{bucket},
1712 s3_policy_upload_signature => $item->{storage}{S3}{bucket},
1713 bundle_error_code => $item->{error}{code},
1714 bundle_error_message => $item->{error}{message},
1715 0 );
1716
1717 0 push @$bundle_tasks, $bundle;
1718 }
1719
1720 0 return $bundle_tasks;
1721 }
1722 }
1723  
1724 =head2 describe_image_attributes(%params)
1725  
1726 This method pulls a list of attributes for the image id specified
1727  
1728 =over
1729  
1730 =item ImageId (required)
1731  
1732 A scalar containing the image you want to get the list of attributes for.
1733  
1734 =item Attribute (required)
1735  
1736 A scalar containing the attribute to describe.
1737  
1738 Valid attributes are:
1739  
1740 =over
1741  
1742 =item launchPermission - The AMIs launch permissions.
1743  
1744 =item ImageId - ID of the AMI for which an attribute will be described.
1745  
1746 =item productCodes - The product code attached to the AMI.
1747  
1748 =item kernel - Describes the ID of the kernel associated with the AMI.
1749  
1750 =item ramdisk - Describes the ID of RAM disk associated with the AMI.
1751  
1752 =item blockDeviceMapping - Defines native device names to use when exposing virtual devices.
1753  
1754 =item platform - Describes the operating system platform.
1755  
1756 =back
1757  
1758 =back
1759  
1760 Returns a Net::Amazon::EC2::DescribeImageAttribute object
1761  
1762 * NOTE: There is currently a bug in Amazon's SOAP and Query API
1763 for when you try and describe the attributes: kernel, ramdisk, blockDeviceMapping, or platform
1764 AWS returns an invalid response. No response yet from Amazon on an ETA for getting that bug fixed.
1765  
1766 =cut
1767  
1768 0 ▶sub describe_image_attribute {
Subroutine describe_image_attribute: not called CC=12 SCAR=50.5
Pod undocumented
1769 0 my $self = shift;
1770 0 my %args = validate( @_, {
1771 ImageId => { type => SCALAR },
1772 Attribute => { type => SCALAR }
1773 });
1774
1775 0 my $xml = $self->_sign(Action => 'DescribeImageAttribute', %args);
1776
1777 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1778 0 return $self->_parse_errors($xml);
1779 }
1780 else {
1781 0 my $launch_permissions;
1782 my $product_codes;
1783 0 my $block_device_mappings;
1784
1785 0 ▶ if ( grep { defined && length } $xml->{launchPermission}{item} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{"launchPermission"}{"item"}) 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1786 0 foreach my $lp (@{$xml->{launchPermission}{item}}) {
1787 my $launch_permission = Net::Amazon::EC2::LaunchPermission->new(
1788 group => $lp->{group},
1789 user_id => $lp->{userId},
1790 0 );
1791
1792 0 push @$launch_permissions, $launch_permission;
1793 }
1794 }
1795  
1796 0 ▶ if ( grep { defined && length } $xml->{productCodes}{item} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{"productCodes"}{"item"}) 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1797 0 foreach my $pc (@{$xml->{productCodes}{item}}) {
1798 my $product_code = Net::Amazon::EC2::ProductCode->new(
1799 product_code => $pc->{productCode},
1800 0 );
1801
1802 0 push @$product_codes, $product_code;
1803 }
1804 }
1805
1806 0 ▶ if ( grep { defined && length } $xml->{blockDeviceMapping}{item} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{"blockDeviceMapping"}{"item"}) 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1807 0 foreach my $bd (@{$xml->{blockDeviceMapping}{item}}) {
1808 my $block_device_mapping = Net::Amazon::EC2::BlockDeviceMapping->new(
1809 virtual_name => $bd->{virtualName},
1810 device_name => $bd->{deviceName},
1811 0 );
1812
1813 0 push @$block_device_mappings, $block_device_mapping;
1814 }
1815 }
1816
1817 my $describe_image_attribute = Net::Amazon::EC2::DescribeImageAttribute->new(
1818 image_id => $xml->{imageId},
1819 launch_permissions => $launch_permissions,
1820 product_codes => $product_codes,
1821 kernel => $xml->{kernel},
1822 ramdisk => $xml->{ramdisk},
1823 blockDeviceMapping => $block_device_mappings,
1824 platform => $xml->{platform},
1825 0 );
1826  
1827 0 return $describe_image_attribute;
1828 }
1829 }
1830  
1831 =head2 describe_images(%params)
1832  
1833 This method pulls a list of the AMIs which can be run. The list can be modified by passing in some of the following parameters:
1834  
1835 =over
1836  
1837 =item ImageId (optional)
1838  
1839 Either a scalar or an array ref can be passed in, will cause just these AMIs to be 'described'
1840  
1841 =item Owner (optional)
1842  
1843 Either a scalar or an array ref can be passed in, will cause AMIs owned by the Owner's provided will be 'described'. Pass either account ids, or 'amazon' for all amazon-owned AMIs, or 'self' for your own AMIs.
1844  
1845 =item ExecutableBy (optional)
1846  
1847 Either a scalar or an array ref can be passed in, will cause AMIs executable by the account id's specified. Or 'self' for your own AMIs.
1848  
1849 =back
1850  
1851 Returns an array ref of Net::Amazon::EC2::DescribeImagesResponse objects
1852  
1853 =cut
1854  
1855 0 ▶sub describe_images {
Subroutine describe_images: not called CC=22 SCAR=62.3
Pod documented
1856 0 my $self = shift;
1857 0 my %args = validate( @_, {
1858 ImageId => { type => SCALAR | ARRAYREF, optional => 1 },
1859 Owner => { type => SCALAR | ARRAYREF, optional => 1 },
1860 ExecutableBy => { type => SCALAR | ARRAYREF, optional => 1 },
1861 });
1862
1863 # If we have a array ref of instances lets split them out into their ImageId.n format
1864 0 ▶ if (ref ($args{ImageId}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"ImageId"} eq "ARRAY") 0 0 0
1865 0 my $image_ids = delete $args{ImageId};
1866 0 _split_into_args('ImageId.%s',\%args,$image_ids);
1867 }
1868
1869 # If we have a array ref of instances lets split them out into their Owner.n format
1870 0 ▶ if (ref ($args{Owner}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"Owner"} eq "ARRAY") 0 0 0
1871 0 my $owners = delete $args{Owner};
1872 0 _split_into_args('Owner.%s',\%args,$owners);
1873 }
1874  
1875 # If we have a array ref of instances lets split them out into their ExecutableBy.n format
1876 0 ▶ if (ref ($args{ExecutableBy}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"ExecutableBy"} eq "ARRAY") 0 0 0
1877 0 my $executors = delete $args{ExecutableBy};
1878 0 _split_into_args('ExecutableBy.%s',\%args,$executors);
1879 }
1880  
1881 0 my $xml = $self->_sign(Action => 'DescribeImages', %args);
1882
1883 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1884 0 return $self->_parse_errors($xml);
1885 }
1886 else {
1887 0 my $images;
1888
1889 0 foreach my $item (@{$xml->{imagesSet}{item}}) {
1890 0 my $product_codes;
1891 my $state_reason;
1892 0 my $block_device_mappings;
1893
1894 0 ▶ if ( grep { defined && length && $_->{code} && $_->{message} } $item->{stateReason} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_ and $_->{"code"} and $_->{"message"};} $item->{"stateReason"}) 0 0 0
Condition0%0/9
defined $_ && length $_ && $_->{'code'} && $_->{'message'}
!ll&&!rl&&r
000
defined $_ and length $_ and $_->{"code"}
!ll&&!rl&&r
000
defined $_ and length $_
!ll&&!rl&&r
000
MC/DC0%0/4
defined $_ && length $_ && $_->{'code'} && $_->{'message'}
defined $_ length $_ $_->{"code"} $_->{'message'}
Truth table0%0/5
A and B and C && D
A= defined $_B= length $_C= $_->{"code"}D= $_->{'message'}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1895 $state_reason = Net::Amazon::EC2::StateReason->new(
1896 code => $item->{stateReason}{code},
1897 message => $item->{stateReason}{message},
1898 0 );
1899 }
1900  
1901 0 ▶ if ( grep { defined && length } $item->{blockDeviceMapping} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $item->{"blockDeviceMapping"}) 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1902 0 foreach my $bdm ( @{$item->{blockDeviceMapping}{item}} ) {
1903 0 my $virtual_name;
1904 my $no_device;
1905 0 my $ebs_block_device_mapping;
1906
1907 0 ▶ if ( grep { defined && length } $bdm->{ebs} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $bdm->{"ebs"}) 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1908 $ebs_block_device_mapping = Net::Amazon::EC2::EbsBlockDevice->new(
1909 snapshot_id => $bdm->{ebs}{snapshotId},
1910 volume_size => $bdm->{ebs}{volumeSize},
1911 delete_on_termination => $bdm->{ebs}{deleteOnTermination},
1912 0 );
1913 }
1914
1915
1916 my $block_device_mapping = Net::Amazon::EC2::BlockDeviceMapping->new(
1917 device_name => $bdm->{deviceName},
1918 0 virtual_name => $virtual_name,
1919 ebs => $ebs_block_device_mapping,
1920 no_device => $no_device,
1921 );
1922 0 push @$block_device_mappings, $block_device_mapping;
1923 }
1924 }
1925 0 ▶ $item->{description} = undef if ref ($item->{description});
Branch: 1 branch
BranchTrueFalseTotal
if ref $item->{"description"} 0 0 0
1926  
1927 0 my $tag_sets;
1928 0 foreach my $tag_arr (@{$item->{tagSet}{item}}) {
1929 0 ▶ if ( ref $tag_arr->{value} eq "HASH" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $tag_arr->{"value"} eq "HASH") 0 0 0
1930 0 $tag_arr->{value} = "";
1931 }
1932 my $tag = Net::Amazon::EC2::TagSet->new(
1933 key => $tag_arr->{key},
1934 value => $tag_arr->{value},
1935 0 );
1936 0 push @$tag_sets, $tag;
1937 }
1938  
1939 my $image = Net::Amazon::EC2::DescribeImagesResponse->new(
1940 image_id => $item->{imageId},
1941 image_owner_id => $item->{imageOwnerId},
1942 image_state => $item->{imageState},
1943 is_public => $item->{isPublic},
1944 image_location => $item->{imageLocation},
1945 architecture => $item->{architecture},
1946 image_type => $item->{imageType},
1947 kernel_id => $item->{kernelId},
1948 ramdisk_id => $item->{ramdiskId},
1949 platform => $item->{platform},
1950 state_reason => $state_reason,
1951 image_owner_alias => $item->{imageOwnerAlias},
1952 name => $item->{name},
1953 description => $item->{description},
1954 root_device_type => $item->{rootDeviceType},
1955 root_device_name => $item->{rootDeviceName},
1956 0 block_device_mapping => $block_device_mappings,
1957 tag_set => $tag_sets,
1958 );
1959
1960 0 ▶ if (grep { defined && length } $item->{productCodes} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $item->{"productCodes"}) 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
1961 0 foreach my $pc (@{$item->{productCodes}{item}}) {
1962 0 my $product_code = Net::Amazon::EC2::ProductCode->new( product_code => $pc->{productCode} );
1963 0 push @$product_codes, $product_code;
1964 }
1965
1966 0 $image->product_codes($product_codes);
1967 }
1968  
1969
1970 0 push @$images, $image;
1971 }
1972
1973 0 return $images;
1974 }
1975 }
1976  
1977 =head2 describe_instances(%params)
1978  
1979 This method pulls a list of the instances which are running or were just running. The list can be modified by passing in some of the following parameters:
1980  
1981 =over
1982  
1983 =item InstanceId (optional)
1984  
1985 Either a scalar or an array ref can be passed in, will cause just these instances to be 'described'
1986  
1987 =item Filter (optional)
1988  
1989 The filters for only the matching instances to be 'described'.
1990 A filter tuple is an arrayref constsing one key and one or more values.
1991 The option takes one filter tuple, or an arrayref of multiple filter tuples.
1992  
1993 =back
1994  
1995 Returns an array ref of Net::Amazon::EC2::ReservationInfo objects
1996  
1997 =cut
1998  
1999 3 ▶sub describe_instances {
Subroutine describe_instances: called CC=40 SCAR=71.8
Pod documented
2000 3 my $self = shift;
2001 3 my %args = validate( @_, {
2002 InstanceId => { type => SCALAR | ARRAYREF, optional => 1 },
2003 Filter => { type => ARRAYREF, optional => 1 },
2004 });
2005
2006 # If we have a array ref of instances lets split them out into their InstanceId.n format
2007 3 ▶ if (ref ($args{InstanceId}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"InstanceId"} eq "ARRAY") 0 3 3
2008 0 my $instance_ids = delete $args{InstanceId};
2009 0 _split_into_args('InstanceId.%s',\%args,$instance_ids);
2010 }
2011  
2012 3 $self->_build_filters(\%args);
2013 3 my $xml = $self->_sign(Action => 'DescribeInstances', %args);
2014 3 my $reservations;
2015
2016 3 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 3 0 3
Condition33%1/3
defined $_ && length $_
!ll&&!rl&&r
003
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table33%1/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2017 3 return $self->_parse_errors($xml);
2018 }
2019 else {
2020 0 foreach my $reservation_set (@{$xml->{reservationSet}{item}}) {
2021 0 my $group_sets=[];
2022 0 foreach my $group_arr (@{$reservation_set->{groupSet}{item}}) {
2023 my $group = Net::Amazon::EC2::GroupSet->new(
2024 group_id => $group_arr->{groupId},
2025 group_name => $group_arr->{groupName},
2026 0 );
2027 0 push @$group_sets, $group;
2028 }
2029
2030 0 my $running_instances;
2031 0 foreach my $instance_elem (@{$reservation_set->{instancesSet}{item}}) {
2032 my $instance_state_type = Net::Amazon::EC2::InstanceState->new(
2033 code => $instance_elem->{instanceState}{code},
2034 name => $instance_elem->{instanceState}{name},
2035 0 );
2036
2037 0 my $product_codes;
2038 my $block_device_mappings;
2039 0 my $state_reason;
2040 0 my $network_interfaces_set;
2041
2042 0 ▶ if (grep { defined && length } $instance_elem->{productCodes} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $instance_elem->{"productCodes"}) 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2043 0 foreach my $pc (@{$instance_elem->{productCodes}{item}}) {
2044 0 my $product_code = Net::Amazon::EC2::ProductCode->new( product_code => $pc->{productCode} );
2045 0 push @$product_codes, $product_code;
2046 }
2047 }
2048  
2049 0 ▶ if ( grep { defined && length } $instance_elem->{networkInterfaceSet} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $instance_elem->{"networkInterfaceSet"}) 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2050 0 foreach my $interface( @{$instance_elem->{networkInterfaceSet}{item}} ) {
2051 my $network_interface = Net::Amazon::EC2::NetworkInterfaceSet->new(
2052 network_interface_id => $interface->{networkInterfaceId},
2053 subnet_id => $interface->{subnetId},
2054 vpc_id => $interface->{vpcId},
2055 description => $interface->{description},
2056 status => $interface->{status},
2057 mac_address => $interface->{macAddress},
2058 private_ip_address => $interface->{privateIpAddress},
2059 0 );
2060  
2061 0 ▶ if ( grep { defined && length } $interface->{groupSet} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $interface->{"groupSet"}) 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2062 0 my $groups_set = [];
2063 0 foreach my $group( @{$interface->{groupSet}{item}} ) {
2064 my $group = Net::Amazon::EC2::GroupSet->new(
2065 group_id => $group->{groupId},
2066 group_name => $group->{groupName},
2067 0 );
2068 0 push @$groups_set, $group;
2069 }
2070  
2071 0 $network_interface->{group_sets} = $groups_set;
2072 }
2073  
2074 0 push @$network_interfaces_set, $network_interface;
2075 }
2076 }
2077  
2078 0 ▶ if ( grep { defined && length } $instance_elem->{blockDeviceMapping} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $instance_elem->{"blockDeviceMapping"}) 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2079 0 foreach my $bdm ( @{$instance_elem->{blockDeviceMapping}{item}} ) {
2080 my $ebs_block_device_mapping = Net::Amazon::EC2::EbsInstanceBlockDeviceMapping->new(
2081 volume_id => $bdm->{ebs}{volumeId},
2082 status => $bdm->{ebs}{status},
2083 attach_time => $bdm->{ebs}{attachTime},
2084 delete_on_termination => $bdm->{ebs}{deleteOnTermination},
2085 0 );
2086
2087 my $block_device_mapping = Net::Amazon::EC2::BlockDeviceMapping->new(
2088 ebs => $ebs_block_device_mapping,
2089 device_name => $bdm->{deviceName},
2090 0 );
2091 0 push @$block_device_mappings, $block_device_mapping;
2092 }
2093 }
2094  
2095 0 ▶ if ( grep { defined && length && $_->{code} && $_->{message} && $_->{code} && $_->{message} } $instance_elem->{stateReason} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_ and $_->{"code"} and $_->{"message"} and $_->{"code"} and $_->{"message"};} $instance_elem->{"stateReason"}) 0 0 0
Condition0%0/15
defined $_ && length $_ && $_->{'code'} && $_->{'message'} && $_->{'code'} && $_->{'message'}
!ll&&!rl&&r
000
defined $_ and length $_ and $_->{"code"} and $_->{"message"} and $_->{"code"}
!ll&&!rl&&r
000
defined $_ and length $_ and $_->{"code"} and $_->{"message"}
!ll&&!rl&&r
000
defined $_ and length $_ and $_->{"code"}
!ll&&!rl&&r
000
defined $_ and length $_
!ll&&!rl&&r
000
MC/DC0%0/6
defined $_ && length $_ && $_->{'code'} && $_->{'message'} && $_->{'code'} && $_->{'message'}
defined $_ length $_ $_->{"code"} $_->{"message"} $_->{"code"} $_->{'message'}
Truth table0%0/7
A and B and C and D and E && F
A= defined $_B= length $_C= $_->{"code"}D= $_->{"message"}E= $_->{"code"}F= $_->{'message'}
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
2096 $state_reason = Net::Amazon::EC2::StateReason->new(
2097 code => $instance_elem->{stateReason}{code},
2098 message => $instance_elem->{stateReason}{message},
2099 0 );
2100 }
2101
2102 0 ▶ unless ( grep { defined && length } $instance_elem->{reason} and ref $instance_elem->{reason} ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {defined $_ and length $_;} $instance_elem->{"reason"} and ref $instance_elem->{"reason"} ne "HASH") 0 0 0
Condition0%0/6
grep {defined $_ and length $_;} $instance_elem->{"reason"} and ref $instance_elem->{"reason"} ne "HASH"
!ll&&!rl&&r
000
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
grep {defined $_ and length $_;} $instance_elem->{"reason"} and ref $instance_elem->{"reason"} ne "HASH"
grep {defined $_ and length $_;} $instance_elem->{"reason"} ref $instance_elem->{"reason"} ne "HASH"
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A and B
A= grep {defined $_ and length $_;} $instance_elem->{"reason"}B= ref $instance_elem->{"reason"} ne "HASH"
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2103 0 $instance_elem->{reason} = undef;
2104 }
2105
2106 0 ▶ unless ( grep { defined && length } $instance_elem->{privateDnsName} and ref $instance_elem->{privateDnsName} ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {defined $_ and length $_;} $instance_elem->{"privateDnsName"} and ref $instance_elem->{"privateDnsName"} ne "HASH") 0 0 0
Condition0%0/6
grep {defined $_ and length $_;} $instance_elem->{"privateDnsName"} and ref $instance_elem->{"privateDnsName"} ne "HASH"
!ll&&!rl&&r
000
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
grep {defined $_ and length $_;} $instance_elem->{"privateDnsName"} and ref $instance_elem->{"privateDnsName"} ne "HASH"
grep {defined $_ and length $_;} $instance_elem->{"privateDnsName"} ref $instance_elem->{"privateDnsName"} ne "HASH"
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A and B
A= grep {defined $_ and length $_;} $instance_elem->{"privateDnsName"}B= ref $instance_elem->{"privateDnsName"} ne "HASH"
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2107 0 $instance_elem->{privateDnsName} = undef;
2108 }
2109
2110 0 ▶ unless ( grep { defined && length } $instance_elem->{dnsName} and ref $instance_elem->{dnsName} ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {defined $_ and length $_;} $instance_elem->{"dnsName"} and ref $instance_elem->{"dnsName"} ne "HASH") 0 0 0
Condition0%0/6
grep {defined $_ and length $_;} $instance_elem->{"dnsName"} and ref $instance_elem->{"dnsName"} ne "HASH"
!ll&&!rl&&r
000
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
grep {defined $_ and length $_;} $instance_elem->{"dnsName"} and ref $instance_elem->{"dnsName"} ne "HASH"
grep {defined $_ and length $_;} $instance_elem->{"dnsName"} ref $instance_elem->{"dnsName"} ne "HASH"
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A and B
A= grep {defined $_ and length $_;} $instance_elem->{"dnsName"}B= ref $instance_elem->{"dnsName"} ne "HASH"
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2111 0 $instance_elem->{dnsName} = undef;
2112 }
2113  
2114 0 ▶ unless ( grep { defined && length } $instance_elem->{placement}{availabilityZone} and ref $instance_elem->{placement}{availabilityZone} ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {defined $_ and length $_;} $instance_elem->{"placement"}{"availabilityZone"} and ref $instance_elem->{"placement"}{"availabilityZone"} ne "HASH") 0 0 0
Condition0%0/6
grep {defined $_ and length $_;} $instance_elem->{"placement"}{"availabilityZone"} and ref $instance_elem->{"placement"}{"availabilityZone"} ne "HASH"
!ll&&!rl&&r
000
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
grep {defined $_ and length $_;} $instance_elem->{"placement"}{"availabilityZone"} and ref $instance_elem->{"placement"}{"availabilityZone"} ne "HASH"
grep {defined $_ and length $_;} $instance_elem->{"placement"}{"availabilityZone"} ref $instance_elem->{"placement"}{"availabilityZone"} ne "HASH"
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A and B
A= grep {defined $_ and length $_;} $instance_elem->{"placement"}{"availabilityZone"}B= ref $instance_elem->{"placement"}{"availabilityZone"} ne "HASH"
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2115 0 $instance_elem->{placement}{availabilityZone} = undef;
2116 }
2117
2118 0 my $placement_response = Net::Amazon::EC2::PlacementResponse->new( availability_zone => $instance_elem->{placement}{availabilityZone} );
2119  
2120 0 my $tag_sets;
2121 0 foreach my $tag_arr (@{$instance_elem->{tagSet}{item}}) {
2122 0 ▶ if ( ref $tag_arr->{value} eq "HASH" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $tag_arr->{"value"} eq "HASH") 0 0 0
2123 0 $tag_arr->{value} = "";
2124 }
2125 my $tag = Net::Amazon::EC2::TagSet->new(
2126 key => $tag_arr->{key},
2127 value => $tag_arr->{value},
2128 0 );
2129 0 push @$tag_sets, $tag;
2130 }
2131  
2132 my $running_instance = Net::Amazon::EC2::RunningInstances->new(
2133 ami_launch_index => $instance_elem->{amiLaunchIndex},
2134 dns_name => $instance_elem->{dnsName},
2135 image_id => $instance_elem->{imageId},
2136 kernel_id => $instance_elem->{kernelId},
2137 ramdisk_id => $instance_elem->{ramdiskId},
2138 instance_id => $instance_elem->{instanceId},
2139 instance_state => $instance_state_type,
2140 instance_type => $instance_elem->{instanceType},
2141 key_name => $instance_elem->{keyName},
2142 launch_time => $instance_elem->{launchTime},
2143 placement => $placement_response,
2144 private_dns_name => $instance_elem->{privateDnsName},
2145 reason => $instance_elem->{reason},
2146 platform => $instance_elem->{platform},
2147 monitoring => $instance_elem->{monitoring}{state},
2148 subnet_id => $instance_elem->{subnetId},
2149 vpc_id => $instance_elem->{vpcId},
2150 private_ip_address => $instance_elem->{privateIpAddress},
2151 ip_address => $instance_elem->{ipAddress},
2152 architecture => $instance_elem->{architecture},
2153 root_device_name => $instance_elem->{rootDeviceName},
2154 root_device_type => $instance_elem->{rootDeviceType},
2155 0 block_device_mapping => $block_device_mappings,
2156 state_reason => $state_reason,
2157 tag_set => $tag_sets,
2158 network_interface_set => $network_interfaces_set,
2159 );
2160  
2161 0 ▶ if ($product_codes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($product_codes) 0 0 0
2162 0 $running_instance->product_codes($product_codes);
2163 }
2164
2165 0 push @$running_instances, $running_instance;
2166 }
2167
2168 my $reservation = Net::Amazon::EC2::ReservationInfo->new(
2169 reservation_id => $reservation_set->{reservationId},
2170 owner_id => $reservation_set->{ownerId},
2171 group_set => $group_sets,
2172 instances_set => $running_instances,
2173 requester_id => $reservation_set->{requesterId},
2174 0 );
2175
2176 0 push @$reservations, $reservation;
2177 }
2178
2179 }
2180  
2181 0 return $reservations;
2182 }
2183  
2184 =head2 describe_instance_status(%params)
2185  
2186 This method pulls a list of the instances based on some status filter. The list can be modified by passing in some of the following parameters:
2187  
2188 =over
2189  
2190 =item InstanceId (optional)
2191  
2192 Either a scalar or an array ref can be passed in, will cause just these instances to be 'described'
2193  
2194 =item Filter (optional)
2195  
2196 The filters for only the matching instances to be 'described'.
2197 A filter tuple is an arrayref constsing one key and one or more values.
2198 The option takes one filter tuple, or an arrayref of multiple filter tuples.
2199  
2200 =back
2201  
2202 Returns an array ref of Net::Amazon::EC2::InstanceStatuses objects
2203  
2204 =cut
2205  
2206 0 ▶sub describe_instance_status {
Subroutine describe_instance_status: not called CC=13 SCAR=52.0
Pod documented
2207 0 my $self = shift;
2208 0 my %args = validate(
2209 @_,
2210 {
2211 InstanceId => { type => SCALAR | ARRAYREF, optional => 1 },
2212 Filter => { type => ARRAYREF, optional => 1 },
2213 MaxResults => { type => SCALAR, optional => 1 },
2214 NextToken => { type => SCALAR, optional => 1 },
2215 IncludeAllInstances => { type => BOOLEAN, optional => 1 },
2216 }
2217 );
2218  
2219 # If we have a array ref of instances lets split them out into their InstanceId.n format
2220 0 ▶ if ( ref( $args{InstanceId} ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"InstanceId"} eq "ARRAY") 0 0 0
2221 0 my $instance_ids = delete $args{InstanceId};
2222 0 my $count = 1;
2223 0 foreach my $instance_id ( @{$instance_ids} ) {
2224 0 $args{ "InstanceId." . $count } = $instance_id;
2225 0 $count++;
2226 }
2227 }
2228  
2229 0 $self->_build_filters( \%args );
2230 0 my $xml = $self->_sign( Action => 'DescribeInstanceStatus', %args );
2231  
2232 0 my $instancestatuses;
2233 my $token;
2234  
2235 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2236 0 return $self->_parse_errors($xml);
2237 }
2238 else {
2239 0 foreach my $instancestatus_elem ( @{ $xml->{instanceStatusSet}{item} } )
2240 {
2241 0 my $instance_status = $self->_create_describe_instance_status( $instancestatus_elem );
2242 0 push @$instancestatuses, $instance_status;
2243 }
2244  
2245 0 ▶ if ( grep { defined && length } $xml->{nextToken} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{"nextToken"}) 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2246 0 $token = $xml->{nextToken};
2247 0 while(1) {
2248 0 $args{NextToken} = $token;
2249 0 $self->_build_filters( \%args );
2250 0 my $tmp_xml = $self->_sign( Action => 'DescribeInstanceStatus', %args );
2251 0 ▶ if ( grep { defined && length } $tmp_xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $tmp_xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2252 0 return $self->_parse_errors($tmp_xml);
2253 }
2254 else {
2255 0 foreach my $tmp_instancestatus_elem ( @{ $tmp_xml->{instanceStatusSet}{item} } )
2256 {
2257 0 my $tmp_instance_status = $self->_create_describe_instance_status( $tmp_instancestatus_elem );
2258 0 push @$instancestatuses, $tmp_instance_status;
2259 }
2260 0 ▶ if ( grep { defined && length } $tmp_xml->{nextToken} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $tmp_xml->{'nextToken'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2261 0 $token = $tmp_xml->{nextToken};
2262 }
2263 else {
2264 0 last;
2265 }
2266 }
2267 }
2268 }
2269 }
2270  
2271 0 return $instancestatuses;
2272 }
2273  
2274 =head2 _create_describe_instance_status(%instanceElement)
2275  
2276 Returns a blessed object. Used internally for wrapping describe_instance_status nextToken calls
2277  
2278 =over
2279  
2280 =item InstanceStatusElement (required)
2281  
2282 The instance status element we want to build out and return
2283  
2284 =back
2285  
2286 Returns a Net::Amazon::EC2::InstanceStatuses object
2287  
2288 =cut
2289  
2290 0 ▶sub _create_describe_instance_status {
Subroutine _create_describe_instance_status: not called CC=10 SCAR=47.0
2291 0 my $self = shift;
2292 0 my $instancestatus_elem = shift;
2293  
2294 0 my $group_sets = [];
2295  
2296 my $instancestatus_state = Net::Amazon::EC2::InstanceState->new(
2297 code => $instancestatus_elem->{instanceState}{code},
2298 name => $instancestatus_elem->{instanceState}{name},
2299 0 );
2300  
2301 0 foreach
2302 0 my $events_arr ( @{ $instancestatus_elem->{eventsSet}{item} } )
2303 {
2304 0 my $events;
2305 0 ▶ if ( grep { defined && length } $events_arr->{notAfter} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $events_arr->{'notAfter'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2306 $events = Net::Amazon::EC2::Events->new(
2307 code => $events_arr->{code},
2308 description => $events_arr->{description},
2309 not_before => $events_arr->{notBefore},
2310 not_after => $events_arr->{notAfter},
2311 0 );
2312 }
2313 else {
2314 $events = Net::Amazon::EC2::Events->new(
2315 code => $events_arr->{code},
2316 description => $events_arr->{description},
2317 not_before => $events_arr->{notBefore},
2318 0 );
2319 }
2320 0 push @$group_sets, $events;
2321 }
2322  
2323 0 my $instancestatus_istatus;
2324 0 ▶ if ( grep { defined && length }
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $instancestatus_elem->{"instanceStatus"}) 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2325 $instancestatus_elem->{instanceStatus} )
2326 {
2327 0 my $details_set = [];
2328 0 foreach my $details_arr (
2329 0 @{ $instancestatus_elem->{instanceStatus}{details}{item} } )
2330 {
2331 my $details = Net::Amazon::EC2::Details->new(
2332 status => $details_arr->{status},
2333 name => $details_arr->{name},
2334 0 );
2335 0 push @$details_set, $details;
2336 }
2337 $instancestatus_istatus =
2338 Net::Amazon::EC2::InstanceStatus->new(
2339 status => $instancestatus_elem->{instanceStatus}{status},
2340 0 details => $details_set,
2341 );
2342 }
2343  
2344 0 my $instancestatus_sstatus;
2345 0 ▶ if ( grep { defined && length }
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $instancestatus_elem->{"systemStatus"}) 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2346 $instancestatus_elem->{systemStatus} )
2347 {
2348 0 my $details_set = [];
2349 0 foreach my $details_arr (
2350 0 @{ $instancestatus_elem->{systemStatus}{details}{item} } )
2351 {
2352 my $details = Net::Amazon::EC2::Details->new(
2353 status => $details_arr->{status},
2354 name => $details_arr->{name},
2355 0 );
2356 0 push @$details_set, $details;
2357 }
2358 $instancestatus_sstatus = Net::Amazon::EC2::SystemStatus->new(
2359 status => $instancestatus_elem->{systemStatus}{status},
2360 0 details => $details_set,
2361 );
2362 }
2363  
2364 my $instance_status = Net::Amazon::EC2::InstanceStatuses->new(
2365 availability_zone => $instancestatus_elem->{availabilityZone},
2366 events => $group_sets,
2367 instance_id => $instancestatus_elem->{instanceId},
2368 0 instance_state => $instancestatus_state,
2369 instance_status => $instancestatus_istatus,
2370 system_status => $instancestatus_sstatus,
2371  
2372 );
2373  
2374 0 return $instance_status;
2375 }
2376  
2377 =head2 describe_instance_attribute(%params)
2378  
2379 Returns information about an attribute of an instance. Only one attribute can be specified per call.
2380  
2381 =over
2382  
2383 =item InstanceId (required)
2384  
2385 The instance id we want to describe the attributes of.
2386  
2387 =item Attribute (required)
2388  
2389 The attribute we want to describe. Valid values are:
2390  
2391 =over
2392  
2393 =item * instanceType
2394  
2395 =item * kernel
2396  
2397 =item * ramdisk
2398  
2399 =item * userData
2400  
2401 =item * disableApiTermination
2402  
2403 =item * ebsOptimized
2404  
2405 =item * instanceInitiatedShutdownBehavior
2406  
2407 =item * rootDeviceName
2408  
2409 =item * sourceDestCheck
2410  
2411 =item * blockDeviceMapping
2412  
2413 =back
2414  
2415 =back
2416  
2417 Returns a Net::Amazon::EC2::DescribeInstanceAttributeResponse object
2418  
2419 =cut
2420  
2421 0 ▶sub describe_instance_attribute {
Subroutine describe_instance_attribute: not called CC=14 SCAR=53.5
Pod documented
2422 0 my $self = shift;
2423 0 my %args = validate( @_, {
2424 InstanceId => { type => SCALAR },
2425 Attribute => { type => SCALAR },
2426 });
2427
2428 0 my $xml = $self->_sign(Action => 'DescribeInstanceAttribute', %args);
2429  
2430 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2431 0 return $self->_parse_errors($xml);
2432 }
2433 else {
2434 0 my $attribute_response;
2435
2436 # Test to see which type of attribute we are looking for, to dictacte
2437 # how to create the Net::Amazon::EC2::DescribeInstanceAttributeResponse object.
2438 0 ▶ if ( $args{Attribute} eq 'instanceType' ) {
Branch: 10 branches
BranchTrueFalseTotal
if ($args{'Attribute'} eq 'instanceType') { } 0 0 0
elsif ($args{'Attribute'} eq 'kernel') { } 0 0 0
elsif ($args{'Attribute'} eq 'ramdisk') { } 0 0 0
elsif ($args{'Attribute'} eq 'userData') { } 0 0 0
elsif ($args{'Attribute'} eq 'disableApiTermination') { } 0 0 0
elsif ($args{'Attribute'} eq 'ebsOptimized') { } 0 0 0
elsif ($args{'Attribute'} eq 'instanceInitiatedShutdownBehavior') { } 0 0 0
elsif ($args{'Attribute'} eq 'rootDeviceName') { } 0 0 0
elsif ($args{'Attribute'} eq 'sourceDestCheck') { } 0 0 0
elsif ($args{'Attribute'} eq 'blockDeviceMapping') { } 0 0 0
2439 $attribute_response = Net::Amazon::EC2::DescribeInstanceAttributeResponse->new(
2440 instance_id => $xml->{instanceId},
2441 instance_type => $xml->{instanceType}{value},
2442 0 );
2443 }
2444 elsif ( $args{Attribute} eq 'kernel' ) {
2445 $attribute_response = Net::Amazon::EC2::DescribeInstanceAttributeResponse->new(
2446 instance_id => $xml->{instanceId},
2447 kernel => $xml->{kernel}{value},
2448 0 );
2449 }
2450 elsif ( $args{Attribute} eq 'ramdisk' ) {
2451 $attribute_response = Net::Amazon::EC2::DescribeInstanceAttributeResponse->new(
2452 instance_id => $xml->{instanceId},
2453 ramdisk => $xml->{ramdisk}{value},
2454 0 );
2455 }
2456 elsif ( $args{Attribute} eq 'userData' ) {
2457 $attribute_response = Net::Amazon::EC2::DescribeInstanceAttributeResponse->new(
2458 instance_id => $xml->{instanceId},
2459 user_data => $xml->{userData}{value},
2460 0 );
2461 }
2462 elsif ( $args{Attribute} eq 'disableApiTermination' ) {
2463 $attribute_response = Net::Amazon::EC2::DescribeInstanceAttributeResponse->new(
2464 instance_id => $xml->{instanceId},
2465 disable_api_termination => $xml->{disableApiTermination}{value},
2466 0 );
2467 }
2468 elsif ( $args{Attribute} eq 'ebsOptimized' ) {
2469 $attribute_response = Net::Amazon::EC2::DescribeInstanceAttributeResponse->new(
2470 instance_id => $xml->{instanceId},
2471 ebs_optimized => $xml->{ebsOptimized}{value},
2472 0 );
2473 }
2474 elsif ( $args{Attribute} eq 'instanceInitiatedShutdownBehavior' ) {
2475 $attribute_response = Net::Amazon::EC2::DescribeInstanceAttributeResponse->new(
2476 instance_id => $xml->{instanceId},
2477 instance_initiated_shutdown_behavior => $xml->{instanceInitiatedShutdownBehavior}{value},
2478 0 );
2479 }
2480 elsif ( $args{Attribute} eq 'rootDeviceName' ) {
2481 $attribute_response = Net::Amazon::EC2::DescribeInstanceAttributeResponse->new(
2482 instance_id => $xml->{instanceId},
2483 root_device_name => $xml->{rootDeviceName}{value},
2484 0 );
2485 }
2486 elsif ( $args{Attribute} eq 'sourceDestCheck' ) {
2487 $attribute_response = Net::Amazon::EC2::DescribeInstanceAttributeResponse->new(
2488 instance_id => $xml->{instanceId},
2489 source_dest_check => $xml->{sourceDestCheck}{value},
2490 0 );
2491 }
2492 elsif ( $args{Attribute} eq 'blockDeviceMapping' ) {
2493 0 my $block_mappings;
2494 0 foreach my $block_item (@{$xml->{blockDeviceMapping}{item}}) {
2495 my $ebs_mapping = Net::Amazon::EC2::EbsInstanceBlockDeviceMapping->new(
2496 attach_time => $block_item->{ebs}{attachTime},
2497 delete_on_termination => $block_item->{ebs}{deleteOnTermination},
2498 status => $block_item->{ebs}{status},
2499 volume_id => $block_item->{ebs}{volumeId},
2500 0 );
2501 my $block_device_mapping = Net::Amazon::EC2::BlockDeviceMapping->new(
2502 device_name => $block_item->{deviceName},
2503 0 ebs => $ebs_mapping,
2504 );
2505
2506 0 push @$block_mappings, $block_device_mapping;
2507 }
2508  
2509 $attribute_response = Net::Amazon::EC2::DescribeInstanceAttributeResponse->new(
2510 instance_id => $xml->{instanceId},
2511 0 block_device_mapping => $block_mappings,
2512 );
2513 }
2514
2515 0 return $attribute_response;
2516 }
2517 }
2518  
2519  
2520 =head2 describe_key_pairs(%params)
2521  
2522 This method describes the keypairs available on this account. It takes the following parameter:
2523  
2524 =over
2525  
2526 =item KeyName (optional)
2527  
2528 The name of the key to be described. Can be either a scalar or an array ref.
2529  
2530 =back
2531  
2532 Returns an array ref of Net::Amazon::EC2::DescribeKeyPairsResponse objects
2533  
2534 =cut
2535  
2536 0 ▶sub describe_key_pairs {
Subroutine describe_key_pairs: not called CC=5 SCAR=34.0
Pod documented
2537 0 my $self = shift;
2538 0 my %args = validate( @_, {
2539 KeyName => { type => SCALAR | ARRAYREF, optional => 1 },
2540 });
2541
2542 # If we have a array ref of KeyNames lets split them out into their KeyName.n format
2543 0 ▶ if (ref ($args{KeyName}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"KeyName"} eq "ARRAY") 0 0 0
2544 0 my $keynames = delete $args{KeyName};
2545 0 _split_into_args('KeyName.%s',\%args,$keynames);
2546 }
2547
2548 0 my $xml = $self->_sign(Action => 'DescribeKeyPairs', %args);
2549  
2550 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2551 0 return $self->_parse_errors($xml);
2552 }
2553 else {
2554 0 my $key_pairs;
2555  
2556 0 foreach my $pair (@{$xml->{keySet}{item}}) {
2557 my $key_pair = Net::Amazon::EC2::DescribeKeyPairsResponse->new(
2558 key_name => $pair->{keyName},
2559 key_fingerprint => $pair->{keyFingerprint},
2560 0 );
2561
2562 0 push @$key_pairs, $key_pair;
2563 }
2564  
2565 0 return $key_pairs;
2566 }
2567 }
2568  
2569 =head2 describe_regions(%params)
2570  
2571 Describes EC2 regions that are currently available to launch instances in for this account.
2572  
2573 =over
2574  
2575 =item RegionName (optional)
2576  
2577 The name of the region(s) to be described. Can be either a scalar or an array ref.
2578  
2579 =back
2580  
2581 Returns an array ref of Net::Amazon::EC2::Region objects
2582  
2583 =cut
2584  
2585 0 ▶sub describe_regions {
Subroutine describe_regions: not called CC=5 SCAR=34.0
Pod documented
2586 0 my $self = shift;
2587 0 my %args = validate( @_, {
2588 RegionName => { type => ARRAYREF | SCALAR, optional => 1 },
2589 });
2590  
2591 # If we have a array ref of regions lets split them out into their RegionName.n format
2592 0 ▶ if (ref ($args{RegionName}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"RegionName"} eq "ARRAY") 0 0 0
2593 0 my $regions = delete $args{RegionName};
2594 0 _split_into_args('RegionName.%s',\%args,$regions);
2595 }
2596
2597 0 my $xml = $self->_sign(Action => 'DescribeRegions', %args);
2598
2599 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2600 0 return $self->_parse_errors($xml);
2601 }
2602 else {
2603 0 my $regions;
2604  
2605 0 foreach my $region_item (@{$xml->{regionInfo}{item}}) {
2606 my $region = Net::Amazon::EC2::Region->new(
2607 region_name => $region_item->{regionName},
2608 region_endpoint => $region_item->{regionEndpoint},
2609 0 );
2610
2611 0 push @$regions, $region;
2612 }
2613
2614 0 return $regions;
2615 }
2616 }
2617  
2618 =head2 describe_reserved_instances(%params)
2619  
2620 Describes Reserved Instances that you purchased.
2621  
2622 =over
2623  
2624 =item ReservedInstancesId (optional)
2625  
2626 The reserved instance id(s) to be described. Can be either a scalar or an array ref.
2627  
2628 =back
2629  
2630 Returns an array ref of Net::Amazon::EC2::ReservedInstance objects
2631  
2632 =cut
2633  
2634 0 ▶sub describe_reserved_instances {
Subroutine describe_reserved_instances: not called CC=5 SCAR=34.0
Pod documented
2635 0 my $self = shift;
2636 0 my %args = validate( @_, {
2637 ReservedInstancesId => { type => ARRAYREF | SCALAR, optional => 1 },
2638 });
2639  
2640 # If we have a array ref of reserved instances lets split them out into their ReservedInstancesId.n format
2641 0 ▶ if (ref ($args{ReservedInstancesId}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"ReservedInstancesId"} eq "ARRAY") 0 0 0
2642 0 my $reserved_instance_ids = delete $args{ReservedInstancesId};
2643 0 _split_into_args('ReservedInstancesId.%s',\%args,$reserved_instance_ids);
2644 }
2645
2646 0 my $xml = $self->_sign(Action => 'DescribeReservedInstances', %args);
2647
2648 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2649 0 return $self->_parse_errors($xml);
2650 }
2651 else {
2652 0 my $reserved_instances;
2653  
2654 0 foreach my $reserved_instance_item (@{$xml->{reservedInstancesSet}{item}}) {
2655 my $reserved_instance = Net::Amazon::EC2::ReservedInstance->new(
2656 reserved_instances_id => $reserved_instance_item->{reservedInstancesId},
2657 instance_type => $reserved_instance_item->{instanceType},
2658 availability_zone => $reserved_instance_item->{availabilityZone},
2659 duration => $reserved_instance_item->{duration},
2660 start => $reserved_instance_item->{start},
2661 usage_price => $reserved_instance_item->{usagePrice},
2662 fixed_price => $reserved_instance_item->{fixedPrice},
2663 instance_count => $reserved_instance_item->{instanceCount},
2664 product_description => $reserved_instance_item->{productDescription},
2665 state => $reserved_instance_item->{state},
2666 0 );
2667
2668 0 push @$reserved_instances, $reserved_instance;
2669 }
2670
2671 0 return $reserved_instances;
2672 }
2673 }
2674  
2675 =head2 describe_reserved_instances_offerings(%params)
2676  
2677 Describes Reserved Instance offerings that are available for purchase. With Amazon EC2 Reserved Instances,
2678 you purchase the right to launch Amazon EC2 instances for a period of time (without getting insufficient
2679 capacity errors) and pay a lower usage rate for the actual time used.
2680  
2681 =over
2682  
2683 =item ReservedInstancesOfferingId (optional)
2684  
2685 ID of the Reserved Instances to describe.
2686  
2687 =item InstanceType (optional)
2688  
2689 The instance type. The default is m1.small. Amazon frequently updates their instance types.
2690  
2691 See http://aws.amazon.com/ec2/instance-types
2692  
2693 =item AvailabilityZone (optional)
2694  
2695 The Availability Zone in which the Reserved Instance can be used.
2696  
2697 =item ProductDescription (optional)
2698  
2699 The Reserved Instance description.
2700  
2701 =back
2702  
2703 Returns an array ref of Net::Amazon::EC2::ReservedInstanceOffering objects
2704  
2705 =cut
2706  
2707 0 ▶sub describe_reserved_instances_offerings {
Subroutine describe_reserved_instances_offerings: not called CC=4 SCAR=30.0
Pod documented
2708 0 my $self = shift;
2709 0 my %args = validate( @_, {
2710 ReservedInstancesOfferingId => { type => SCALAR, optional => 1 },
2711 InstanceType => { type => SCALAR, optional => 1 },
2712 AvailabilityZone => { type => SCALAR, optional => 1 },
2713 ProductDescription => { type => SCALAR, optional => 1 },
2714 });
2715  
2716 0 my $xml = $self->_sign(Action => 'DescribeReservedInstancesOfferings', %args);
2717
2718 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2719 0 return $self->_parse_errors($xml);
2720 }
2721 else {
2722 0 my $reserved_instance_offerings;
2723  
2724 0 foreach my $reserved_instance_offering_item (@{$xml->{reservedInstancesOfferingsSet}{item}}) {
2725 my $reserved_instance_offering = Net::Amazon::EC2::ReservedInstanceOffering->new(
2726 reserved_instances_offering_id => $reserved_instance_offering_item->{reservedInstancesOfferingId},
2727 instance_type => $reserved_instance_offering_item->{instanceType},
2728 availability_zone => $reserved_instance_offering_item->{availabilityZone},
2729 duration => $reserved_instance_offering_item->{duration},
2730 start => $reserved_instance_offering_item->{start},
2731 usage_price => $reserved_instance_offering_item->{usagePrice},
2732 fixed_price => $reserved_instance_offering_item->{fixedPrice},
2733 instance_count => $reserved_instance_offering_item->{instanceCount},
2734 product_description => $reserved_instance_offering_item->{productDescription},
2735 state => $reserved_instance_offering_item->{state},
2736 0 );
2737
2738 0 push @$reserved_instance_offerings, $reserved_instance_offering;
2739 }
2740
2741 0 return $reserved_instance_offerings;
2742 }
2743 }
2744  
2745 =head2 describe_security_groups(%params)
2746  
2747 This method describes the security groups available to this account. It takes the following parameter:
2748  
2749 =over
2750  
2751 =item GroupName (optional)
2752  
2753 The name of the security group(s) to be described. Can be either a scalar or an array ref.
2754  
2755 =item GroupId (optional)
2756  
2757 The id of the security group(s) to be described. Can be either a scalar or an array ref.
2758  
2759 =back
2760  
2761 Returns an array ref of Net::Amazon::EC2::SecurityGroup objects
2762  
2763 =cut
2764  
2765 0 ▶sub describe_security_groups {
Subroutine describe_security_groups: not called CC=25 SCAR=64.8
Pod documented
2766 0 my $self = shift;
2767 0 my %args = validate( @_, {
2768 GroupName => { type => SCALAR | ARRAYREF, optional => 1 },
2769 GroupId => { type => SCALAR | ARRAYREF, optional => 1 },
2770 });
2771  
2772 # If we have a array ref of GroupNames lets split them out into their GroupName.n format
2773 0 ▶ if (ref ($args{GroupName}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"GroupName"} eq "ARRAY") 0 0 0
2774 0 my $groups = delete $args{GroupName};
2775 0 _split_into_args('GroupName.%s',\%args,$groups);
2776 }
2777
2778 # If we have a array ref of GroupIds lets split them out into their GroupId.n format
2779 0 ▶ if (ref ($args{GroupId}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"GroupId"} eq "ARRAY") 0 0 0
2780 0 my $groups = delete $args{GroupId};
2781 0 _split_into_args('GroupId.%s',\%args,$groups);
2782 }
2783  
2784 0 my $xml = $self->_sign(Action => 'DescribeSecurityGroups', %args);
2785
2786 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2787 0 return $self->_parse_errors($xml);
2788 }
2789 else {
2790 0 my $security_groups;
2791 0 foreach my $sec_grp (@{$xml->{securityGroupInfo}{item}}) {
2792 0 my $owner_id = $sec_grp->{ownerId};
2793 0 my $group_name = $sec_grp->{groupName};
2794 0 my $group_id = $sec_grp->{groupId};
2795 0 my $group_description = $sec_grp->{groupDescription};
2796 0 my $vpc_id = $sec_grp->{vpcId};
2797 0 my $tag_set;
2798 my $ip_permissions;
2799 0 my $ip_permissions_egress;
2800  
2801 0 foreach my $ip_perm (@{$sec_grp->{ipPermissions}{item}}) {
2802 0 my $ip_protocol = $ip_perm->{ipProtocol};
2803 0 my $from_port = $ip_perm->{fromPort};
2804 0 my $to_port = $ip_perm->{toPort};
2805 0 my $icmp_port = $ip_perm->{icmpPort};
2806 0 my $groups;
2807 my $ip_ranges;
2808
2809 0 ▶ if (grep { defined && length } $ip_perm->{groups}{item}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $ip_perm->{"groups"}{"item"}) 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2810 0 foreach my $grp (@{$ip_perm->{groups}{item}}) {
2811 my $group = Net::Amazon::EC2::UserIdGroupPair->new(
2812 user_id => $grp->{userId},
2813 group_name => $grp->{groupName},
2814 0 );
2815
2816 0 push @$groups, $group;
2817 }
2818 }
2819
2820 0 ▶ if (grep { defined && length } $ip_perm->{ipRanges}{item}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $ip_perm->{"ipRanges"}{"item"}) 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2821 0 foreach my $rng (@{$ip_perm->{ipRanges}{item}}) {
2822 my $ip_range = Net::Amazon::EC2::IpRange->new(
2823 cidr_ip => $rng->{cidrIp},
2824 0 );
2825
2826 0 push @$ip_ranges, $ip_range;
2827 }
2828 }
2829  
2830
2831 0 my $ip_permission = Net::Amazon::EC2::IpPermission->new(
2832 ip_protocol => $ip_protocol,
2833 group_name => $group_name,
2834 group_description => $group_description,
2835 from_port => $from_port,
2836 to_port => $to_port,
2837 icmp_port => $icmp_port,
2838 );
2839
2840 0 ▶ if ($ip_ranges) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ip_ranges) 0 0 0
2841 0 $ip_permission->ip_ranges($ip_ranges);
2842 }
2843  
2844 0 ▶ if ($groups) {
Branch: 1 branch
BranchTrueFalseTotal
if ($groups) 0 0 0
2845 0 $ip_permission->groups($groups);
2846 }
2847
2848 0 push @$ip_permissions, $ip_permission;
2849 }
2850
2851 0 foreach my $ip_perm (@{$sec_grp->{ipPermissionsEgress}{item}}) {
2852 0 my $ip_protocol = $ip_perm->{ipProtocol};
2853 0 my $from_port = $ip_perm->{fromPort};
2854 0 my $to_port = $ip_perm->{toPort};
2855 0 my $icmp_port = $ip_perm->{icmpPort};
2856 0 my $groups;
2857 my $ip_ranges;
2858
2859 0 ▶ if (grep { defined && length } $ip_perm->{groups}{item}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $ip_perm->{"groups"}{"item"}) 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2860 0 foreach my $grp (@{$ip_perm->{groups}{item}}) {
2861 my $group = Net::Amazon::EC2::UserIdGroupPair->new(
2862 user_id => $grp->{userId},
2863 group_name => $grp->{groupName},
2864 0 );
2865
2866 0 push @$groups, $group;
2867 }
2868 }
2869
2870 0 ▶ if (grep { defined && length } $ip_perm->{ipRanges}{item}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $ip_perm->{"ipRanges"}{"item"}) 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2871 0 foreach my $rng (@{$ip_perm->{ipRanges}{item}}) {
2872 my $ip_range = Net::Amazon::EC2::IpRange->new(
2873 cidr_ip => $rng->{cidrIp},
2874 0 );
2875
2876 0 push @$ip_ranges, $ip_range;
2877 }
2878 }
2879  
2880
2881 0 my $ip_permission = Net::Amazon::EC2::IpPermission->new(
2882 ip_protocol => $ip_protocol,
2883 group_name => $group_name,
2884 group_description => $group_description,
2885 from_port => $from_port,
2886 to_port => $to_port,
2887 icmp_port => $icmp_port,
2888 );
2889
2890 0 ▶ if ($ip_ranges) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ip_ranges) 0 0 0
2891 0 $ip_permission->ip_ranges($ip_ranges);
2892 }
2893  
2894 0 ▶ if ($groups) {
Branch: 1 branch
BranchTrueFalseTotal
if ($groups) 0 0 0
2895 0 $ip_permission->groups($groups);
2896 }
2897
2898 0 push @$ip_permissions_egress, $ip_permission;
2899 }
2900
2901
2902 0 foreach my $sec_tag (@{$sec_grp->{tagSet}{item}})
2903 {
2904 my $tag = Net::Amazon::EC2::TagSet->new(
2905 key => $sec_tag->{key},
2906 value => $sec_tag->{value},
2907 0 );
2908 0 push @$tag_set, $tag;
2909 }
2910  
2911 0 my $security_group = Net::Amazon::EC2::SecurityGroup->new(
2912 owner_id => $owner_id,
2913 group_name => $group_name,
2914 group_id => $group_id,
2915 vpc_id => $vpc_id,
2916 tag_set => $tag_set,
2917 group_description => $group_description,
2918 ip_permissions => $ip_permissions,
2919 ip_permissions_egress => $ip_permissions_egress,
2920 );
2921
2922 0 push @$security_groups, $security_group;
2923 }
2924
2925 0 return $security_groups;
2926 }
2927 }
2928  
2929 =head2 describe_snapshot_attribute(%params)
2930  
2931 Describes the snapshots attributes related to the snapshot in question. It takes the following arguments:
2932  
2933 =over
2934  
2935 =item SnapshotId (optional)
2936  
2937 Either a scalar or array ref of snapshot id's can be passed in. If this isn't passed in
2938 it will describe the attributes of all the current snapshots.
2939  
2940 =item Attribute (required)
2941  
2942 The attribute to describe, currently, the only valid attribute is createVolumePermission.
2943  
2944 =back
2945  
2946 Returns a Net::Amazon::EC2::SnapshotAttribute object.
2947  
2948 =cut
2949  
2950 0 ▶sub describe_snapshot_attribute {
Subroutine describe_snapshot_attribute: not called CC=8 SCAR=42.8
Pod documented
2951 0 my $self = shift;
2952 0 my %args = validate( @_, {
2953 SnapshotId => { type => ARRAYREF | SCALAR, optional => 1 },
2954 Attribute => { type => SCALAR },
2955 });
2956  
2957 # If we have a array ref of volumes lets split them out into their SnapshotId.n format
2958 0 ▶ if (ref ($args{SnapshotId}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"SnapshotId"} eq "ARRAY") 0 0 0
2959 0 my $snapshots = delete $args{SnapshotId};
2960 0 _split_into_args('SnapshotId.%s',\%args,$snapshots);
2961 }
2962
2963 0 my $xml = $self->_sign(Action => 'DescribeSnapshotAttribute', %args);
2964
2965 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2966 0 return $self->_parse_errors($xml);
2967 }
2968 else {
2969 0 my $perms;
2970
2971 0 ▶ unless ( grep { defined && length } $xml->{createVolumePermission} and ref $xml->{createVolumePermission} ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {defined $_ and length $_;} $xml->{"createVolumePermission"} and ref $xml->{"createVolumePermission"} ne "HASH") 0 0 0
Condition0%0/6
grep {defined $_ and length $_;} $xml->{"createVolumePermission"} and ref $xml->{"createVolumePermission"} ne "HASH"
!ll&&!rl&&r
000
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
grep {defined $_ and length $_;} $xml->{"createVolumePermission"} and ref $xml->{"createVolumePermission"} ne "HASH"
grep {defined $_ and length $_;} $xml->{"createVolumePermission"} ref $xml->{"createVolumePermission"} ne "HASH"
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A and B
A= grep {defined $_ and length $_;} $xml->{"createVolumePermission"}B= ref $xml->{"createVolumePermission"} ne "HASH"
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
2972 0 $perms = undef;
2973 }
2974  
2975 0 foreach my $perm_item (@{$xml->{createVolumePermission}{item}}) {
2976 my $perm = Net::Amazon::EC2::CreateVolumePermission->new(
2977 user_id => $perm_item->{userId},
2978 group => $perm_item->{group},
2979 0 );
2980
2981 0 push @$perms, $perm;
2982 }
2983  
2984 my $snapshot_attribute = Net::Amazon::EC2::SnapshotAttribute->new(
2985 snapshot_id => $xml->{snapshotId},
2986 0 permissions => $perms,
2987 );
2988
2989 0 return $snapshot_attribute;
2990 }
2991 }
2992  
2993  
2994 =head2 describe_snapshots(%params)
2995  
2996 Describes the snapshots available to the user. It takes the following arguments:
2997  
2998 =over
2999  
3000 =item SnapshotId (optional)
3001  
3002 Either a scalar or array ref of snapshot id's can be passed in. If this isn't passed in
3003 it will describe all the current snapshots.
3004  
3005 =item Owner (optional)
3006  
3007 The owner of the snapshot.
3008  
3009 =item RestorableBy (optional)
3010  
3011 A user who can create volumes from the snapshot.
3012  
3013 =item Filter (optional)
3014  
3015 The filters for only the matching snapshots to be 'described'. A
3016 filter tuple is an arrayref constsing one key and one or more values.
3017 The option takes one filter tuple, or an arrayref of multiple filter
3018 tuples.
3019  
3020 =back
3021  
3022 Returns an array ref of Net::Amazon::EC2::Snapshot objects.
3023  
3024 =cut
3025  
3026 0 ▶sub describe_snapshots {
Subroutine describe_snapshots: not called CC=13 SCAR=52.0
Pod documented
3027 0 my $self = shift;
3028 0 my %args = validate( @_, {
3029 SnapshotId => { type => ARRAYREF | SCALAR, optional => 1 },
3030 Owner => { type => SCALAR, optional => 1 },
3031 RestorableBy => { type => SCALAR, optional => 1 },
3032 Filter => { type => ARRAYREF, optional => 1 },
3033 });
3034  
3035 0 $self->_build_filters(\%args);
3036  
3037 # If we have a array ref of volumes lets split them out into their SnapshotId.n format
3038 0 ▶ if (ref ($args{SnapshotId}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"SnapshotId"} eq "ARRAY") 0 0 0
3039 0 my $snapshots = delete $args{SnapshotId};
3040 0 _split_into_args('SnapshotId.%s',\%args,$snapshots);
3041 }
3042
3043 0 my $xml = $self->_sign(Action => 'DescribeSnapshots', %args);
3044
3045 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3046 0 return $self->_parse_errors($xml);
3047 }
3048 else {
3049 0 my $snapshots;
3050  
3051 0 foreach my $snap (@{$xml->{snapshotSet}{item}}) {
3052 0 ▶ unless ( grep { defined && length } $snap->{description} and ref $snap->{description} ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {defined $_ and length $_;} $snap->{"description"} and ref $snap->{"description"} ne "HASH") 0 0 0
Condition0%0/6
grep {defined $_ and length $_;} $snap->{"description"} and ref $snap->{"description"} ne "HASH"
!ll&&!rl&&r
000
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
grep {defined $_ and length $_;} $snap->{"description"} and ref $snap->{"description"} ne "HASH"
grep {defined $_ and length $_;} $snap->{"description"} ref $snap->{"description"} ne "HASH"
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A and B
A= grep {defined $_ and length $_;} $snap->{"description"}B= ref $snap->{"description"} ne "HASH"
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3053 0 $snap->{description} = undef;
3054 }
3055  
3056 0 ▶ unless ( grep { defined && length } $snap->{progress} and ref $snap->{progress} ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {defined $_ and length $_;} $snap->{"progress"} and ref $snap->{"progress"} ne "HASH") 0 0 0
Condition0%0/6
grep {defined $_ and length $_;} $snap->{"progress"} and ref $snap->{"progress"} ne "HASH"
!ll&&!rl&&r
000
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
grep {defined $_ and length $_;} $snap->{"progress"} and ref $snap->{"progress"} ne "HASH"
grep {defined $_ and length $_;} $snap->{"progress"} ref $snap->{"progress"} ne "HASH"
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A and B
A= grep {defined $_ and length $_;} $snap->{"progress"}B= ref $snap->{"progress"} ne "HASH"
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3057 0 $snap->{progress} = undef;
3058 }
3059  
3060 0 my $tag_sets;
3061 0 foreach my $tag_arr (@{$snap->{tagSet}{item}}) {
3062 0 ▶ if ( ref $tag_arr->{value} eq "HASH" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $tag_arr->{"value"} eq "HASH") 0 0 0
3063 0 $tag_arr->{value} = "";
3064 }
3065 my $tag = Net::Amazon::EC2::TagSet->new(
3066 key => $tag_arr->{key},
3067 value => $tag_arr->{value},
3068 0 );
3069 0 push @$tag_sets, $tag;
3070 }
3071  
3072 my $snapshot = Net::Amazon::EC2::Snapshot->new(
3073 snapshot_id => $snap->{snapshotId},
3074 status => $snap->{status},
3075 volume_id => $snap->{volumeId},
3076 start_time => $snap->{startTime},
3077 progress => $snap->{progress},
3078 owner_id => $snap->{ownerId},
3079 volume_size => $snap->{volumeSize},
3080 description => $snap->{description},
3081 owner_alias => $snap->{ownerAlias},
3082 0 tag_set => $tag_sets,
3083 );
3084
3085 0 push @$snapshots, $snapshot;
3086 }
3087
3088 0 return $snapshots;
3089 }
3090 }
3091  
3092 =head2 describe_volumes(%params)
3093  
3094 Describes the volumes currently created. It takes the following arguments:
3095  
3096 =over
3097  
3098 =item VolumeId (optional)
3099  
3100 Either a scalar or array ref of volume id's can be passed in. If this isn't passed in
3101 it will describe all the current volumes.
3102  
3103 =back
3104  
3105 Returns an array ref of Net::Amazon::EC2::Volume objects.
3106  
3107 =cut
3108  
3109 0 ▶sub describe_volumes {
Subroutine describe_volumes: not called CC=11 SCAR=48.8
Pod documented
3110 0 my $self = shift;
3111 0 my %args = validate( @_, {
3112 VolumeId => { type => ARRAYREF | SCALAR, optional => 1 },
3113 });
3114  
3115 # If we have a array ref of VolumeIds lets split them out into their VolumeId.n format
3116 0 ▶ if (ref ($args{VolumeId}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"VolumeId"} eq "ARRAY") 0 0 0
3117 0 my $volumes = delete $args{VolumeId};
3118 0 _split_into_args('VolumeId.%s',\%args,$volumes);
3119 }
3120
3121 0 my $xml = $self->_sign(Action => 'DescribeVolumes', %args);
3122  
3123
3124 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3125 0 return $self->_parse_errors($xml);
3126 }
3127 else {
3128 0 my $volumes;
3129  
3130 0 foreach my $volume_set (@{$xml->{volumeSet}{item}}) {
3131 0 my $attachments;
3132 0 ▶ unless ( grep { defined && length } $volume_set->{snapshotId} and ref $volume_set->{snapshotId} ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {defined $_ and length $_;} $volume_set->{"snapshotId"} and ref $volume_set->{"snapshotId"} ne "HASH") 0 0 0
Condition0%0/6
grep {defined $_ and length $_;} $volume_set->{"snapshotId"} and ref $volume_set->{"snapshotId"} ne "HASH"
!ll&&!rl&&r
000
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
grep {defined $_ and length $_;} $volume_set->{"snapshotId"} and ref $volume_set->{"snapshotId"} ne "HASH"
grep {defined $_ and length $_;} $volume_set->{"snapshotId"} ref $volume_set->{"snapshotId"} ne "HASH"
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A and B
A= grep {defined $_ and length $_;} $volume_set->{"snapshotId"}B= ref $volume_set->{"snapshotId"} ne "HASH"
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3133 0 $volume_set->{snapshotId} = undef;
3134 }
3135
3136 0 foreach my $attachment_set (@{$volume_set->{attachmentSet}{item}}) {
3137 my $attachment = Net::Amazon::EC2::Attachment->new(
3138 volume_id => $attachment_set->{volumeId},
3139 status => $attachment_set->{status},
3140 instance_id => $attachment_set->{instanceId},
3141 attach_time => $attachment_set->{attachTime},
3142 device => $attachment_set->{device},
3143 delete_on_termination => $attachment_set->{deleteOnTermination},
3144 0 );
3145
3146 0 push @$attachments, $attachment;
3147 }
3148
3149 0 my $tags;
3150 0 foreach my $tag_arr (@{$volume_set->{tagSet}{item}}) {
3151 0 ▶ if ( ref $tag_arr->{value} eq "HASH" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $tag_arr->{"value"} eq "HASH") 0 0 0
3152 0 $tag_arr->{value} = "";
3153 }
3154 my $tag = Net::Amazon::EC2::TagSet->new(
3155 key => $tag_arr->{key},
3156 value => $tag_arr->{value},
3157 0 );
3158 0 push @$tags, $tag;
3159 }
3160  
3161 my $volume = Net::Amazon::EC2::Volume->new(
3162 volume_id => $volume_set->{volumeId},
3163 status => $volume_set->{status},
3164 zone => $volume_set->{availabilityZone},
3165 create_time => $volume_set->{createTime},
3166 snapshot_id => $volume_set->{snapshotId},
3167 size => $volume_set->{size},
3168 volume_type => $volume_set->{volumeType},
3169 iops => $volume_set->{iops},
3170 encrypted => $volume_set->{encrypted},
3171 0 tag_set => $tags,
3172 attachments => $attachments,
3173 );
3174
3175 0 push @$volumes, $volume;
3176 }
3177
3178 0 return $volumes;
3179 }
3180 }
3181  
3182  
3183 =head2 describe_subnets(%params)
3184  
3185 This method describes the subnets on this account. It takes the following parameters:
3186  
3187 =over
3188  
3189 =item SubnetId (optional)
3190  
3191 The id of a subnet to be described. Can either be a scalar or an array ref.
3192  
3193 =item Filter.Name (optional)
3194  
3195 The name of the Filter.Name to be described. Can be either a scalar or an array ref.
3196 See http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeSubnets.html
3197 for available filters.
3198  
3199 =item Filter.Value (optional)
3200  
3201 The name of the Filter.Value to be described. Can be either a scalar or an array ref.
3202  
3203 =back
3204  
3205 Returns an array ref of Net::Amazon::EC2::DescribeSubnetResponse objects
3206  
3207 =cut
3208  
3209 0 ▶sub describe_subnets {
Subroutine describe_subnets: not called CC=12 SCAR=50.5
Pod documented
3210 0 my $self = shift;
3211 0 my %args = validate( @_, {
3212 'SubnetId' => { type => ARRAYREF | SCALAR, optional => 1 },
3213 'Filter.Name' => { type => ARRAYREF | SCALAR, optional => 1 },
3214 'Filter.Value' => { type => ARRAYREF | SCALAR, optional => 1 },
3215 });
3216  
3217 0 ▶ if (ref ($args{'SubnetId'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"SubnetId"} eq "ARRAY") 0 0 0
3218 0 my $keys = delete $args{'SubnetId'};
3219 0 my $count = 1;
3220 0 foreach my $key (@{$keys}) {
3221 0 $args{"SubnetId." . $count } = $key;
3222 0 $count++;
3223 }
3224 }
3225 0 ▶ if (ref ($args{'Filter.Name'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"Filter.Name"} eq "ARRAY") 0 0 0
3226 0 my $keys = delete $args{'Filter.Name'};
3227 0 my $count = 1;
3228 0 foreach my $key (@{$keys}) {
3229 0 $args{"Filter." . $count . ".Name"} = $key;
3230 0 $count++;
3231 }
3232 }
3233 0 ▶ if (ref ($args{'Filter.Value'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"Filter.Value"} eq "ARRAY") 0 0 0
3234 0 my $keys = delete $args{'Filter.Value'};
3235 0 my $count = 1;
3236 0 foreach my $key (@{$keys}) {
3237 0 $args{"Filter." . $count . ".Value"} = $key;
3238 0 $count++;
3239 }
3240 }
3241  
3242 0 my $xml = $self->_sign(Action => 'DescribeSubnets', %args);
3243  
3244 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3245 0 return $self->_parse_errors($xml);
3246 }
3247 else {
3248 0 my $subnets;
3249  
3250 0 foreach my $pair (@{$xml->{subnetSet}{item}}) {
3251 0 my $tags;
3252  
3253 0 foreach my $tag_arr (@{$pair->{tagSet}{item}}) {
3254 0 ▶ if ( ref $tag_arr->{value} eq "HASH" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $tag_arr->{"value"} eq "HASH") 0 0 0
3255 0 $tag_arr->{value} = "";
3256 }
3257 my $tag = Net::Amazon::EC2::TagSet->new(
3258 key => $tag_arr->{key},
3259 value => $tag_arr->{value},
3260 0 );
3261 0 push @$tags, $tag;
3262 }
3263  
3264 my $subnet = Net::Amazon::EC2::DescribeSubnetResponse->new(
3265 subnet_id => $pair->{subnetId},
3266 state => $pair->{state},
3267 vpc_id => $pair->{vpcId},
3268 cidr_block => $pair->{cidrBlock},
3269 available_ip_address_count => $pair->{availableIpAddressCount},
3270 availability_zone => $pair->{availabilityZone},
3271 default_for_az => $pair->{defaultForAz},
3272 map_public_ip_on_launch => $pair->{mapPublicIpOnLaunch},
3273 0 tag_set => $tags,
3274 );
3275  
3276 0 push @$subnets, $subnet;
3277 }
3278 0 return $subnets;
3279 }
3280 }
3281  
3282 =head2 describe_tags(%params)
3283  
3284 This method describes the tags available on this account. It takes the following parameter:
3285  
3286 =over
3287  
3288 =item Filter.Name (optional)
3289  
3290 The name of the Filter.Name to be described. Can be either a scalar or an array ref.
3291  
3292 =item Filter.Value (optional)
3293  
3294 The name of the Filter.Value to be described. Can be either a scalar or an array ref.
3295  
3296 =back
3297  
3298 Returns an array ref of Net::Amazon::EC2::DescribeTags objects
3299  
3300 =cut
3301  
3302 0 ▶sub describe_tags {
Subroutine describe_tags: not called CC=6 SCAR=37.4
Pod documented
3303 0 my $self = shift;
3304 0 my %args = validate( @_, {
3305 'Filter.Name' => { type => ARRAYREF | SCALAR, optional => 1 },
3306 'Filter.Value' => { type => ARRAYREF | SCALAR, optional => 1 },
3307 });
3308  
3309 0 ▶ if (ref ($args{'Filter.Name'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"Filter.Name"} eq "ARRAY") 0 0 0
3310 0 my $keys = delete $args{'Filter.Name'};
3311 0 _split_into_args('Filter.%s.Name',\%args,$keys);
3312 }
3313 0 ▶ if (ref ($args{'Filter.Value'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"Filter.Value"} eq "ARRAY") 0 0 0
3314 0 my $keys = delete $args{'Filter.Value'};
3315 0 _split_into_args('Filter.%s.Value',\%args,$keys);
3316 }
3317  
3318 0 my $xml = $self->_sign(Action => 'DescribeTags', %args);
3319  
3320 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3321 0 return $self->_parse_errors($xml);
3322 }
3323 else {
3324 0 my $tags;
3325  
3326 0 foreach my $pair (@{$xml->{tagSet}{item}}) {
3327 my $tag = Net::Amazon::EC2::DescribeTags->new(
3328 resource_id => $pair->{resourceId},
3329 resource_type => $pair->{resourceType},
3330 key => $pair->{key},
3331 value => $pair->{value},
3332 0 );
3333
3334 0 push @$tags, $tag;
3335 }
3336  
3337 0 return $tags;
3338 }
3339 }
3340  
3341 =head2 detach_volume(%params)
3342  
3343 Detach a volume from an instance.
3344  
3345 =over
3346  
3347 =item VolumeId (required)
3348  
3349 The volume id you wish to detach.
3350  
3351 =item InstanceId (optional)
3352  
3353 The instance id you wish to detach from.
3354  
3355 =item Device (optional)
3356  
3357 The device the volume was attached as.
3358  
3359 =item Force (optional)
3360  
3361 A boolean for if to forcibly detach the volume from the instance.
3362 WARNING: This can lead to data loss or a corrupted file system.
3363 Use this option only as a last resort to detach a volume
3364 from a failed instance. The instance will not have an
3365 opportunity to flush file system caches nor file system
3366 meta data.
3367  
3368 =back
3369  
3370 Returns a Net::Amazon::EC2::Attachment object containing the resulting volume status.
3371  
3372 =cut
3373  
3374 0 ▶sub detach_volume {
Subroutine detach_volume: not called CC=3 SCAR=24.8
Pod documented
3375 0 my $self = shift;
3376 0 my %args = validate( @_, {
3377 VolumeId => { type => SCALAR },
3378 InstanceId => { type => SCALAR, optional => 1 },
3379 Device => { type => SCALAR, optional => 1 },
3380 Force => { type => SCALAR, optional => 1 },
3381 });
3382  
3383 0 my $xml = $self->_sign(Action => 'DetachVolume', %args);
3384  
3385
3386 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3387 0 return $self->_parse_errors($xml);
3388 }
3389 else {
3390 my $attachment = Net::Amazon::EC2::Attachment->new(
3391 volume_id => $xml->{volumeId},
3392 status => $xml->{status},
3393 instance_id => $xml->{instanceId},
3394 attach_time => $xml->{attachTime},
3395 device => $xml->{device},
3396 0 );
3397
3398 0 return $attachment;
3399 }
3400 }
3401  
3402 =head2 disassociate_address(%params)
3403  
3404 Disassociates an elastic IP address with an instance. It takes the following arguments:
3405  
3406 =over
3407  
3408 =item PublicIp (conditional)
3409  
3410 The IP address to disassociate, mandatory to remove an IP from a EC2-classic instance.
3411  
3412 =item AssociationId (conditional)
3413  
3414 The Association ID of an IP address, mandatory to remove an IP from a VPC instance.
3415  
3416 =back
3417  
3418 Returns true if the disassociation succeeded.
3419  
3420 =cut
3421  
3422 0 ▶sub disassociate_address {
Subroutine disassociate_address: not called CC=4 SCAR=30.0
Pod documented
3423 0 my $self = shift;
3424 0 my %args = validate( @_, {
3425 PublicIp => { type => SCALAR, optional => 1 },
3426 AssociationId => { type => SCALAR, optional => 1 },
3427 });
3428
3429 0 my $xml = $self->_sign(Action => 'DisassociateAddress', %args);
3430  
3431 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3432 0 return $self->_parse_errors($xml);
3433 }
3434 else {
3435 0 ▶ if ($xml->{return} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'return'} eq 'true') { } 0 0 0
3436 0 return 1;
3437 }
3438 else {
3439 0 return undef;
3440 }
3441 }
3442 }
3443  
3444 =head2 get_console_output(%params)
3445  
3446 This method gets the output from the virtual console for an instance. It takes the following parameters:
3447  
3448 =over
3449  
3450 =item InstanceId (required)
3451  
3452 A scalar containing a instance id.
3453  
3454 =back
3455  
3456 Returns a Net::Amazon::EC2::ConsoleOutput object or C<undef> if there is no
3457 new output. (This can happen in cases where the console output has not changed
3458 since the last call.)
3459  
3460 =cut
3461  
3462 0 ▶sub get_console_output {
Subroutine get_console_output: not called CC=5 SCAR=34.0
Pod documented
3463 0 my $self = shift;
3464 0 my %args = validate( @_, {
3465 InstanceId => { type => SCALAR },
3466 });
3467
3468
3469 0 my $xml = $self->_sign(Action => 'GetConsoleOutput', %args);
3470
3471 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3472 0 return $self->_parse_errors($xml);
3473 }
3474 else {
3475 0 ▶ if ( grep { defined && length } $xml->{output} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'output'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3476 my $console_output = Net::Amazon::EC2::ConsoleOutput->new(
3477 instance_id => $xml->{instanceId},
3478 timestamp => $xml->{timestamp},
3479 0 output => decode_base64($xml->{output}),
3480 );
3481 0 return $console_output;
3482 }
3483 else {
3484 0 return undef;
3485 }
3486 }
3487 }
3488  
3489 =head2 get_password_data(%params)
3490  
3491 Retrieves the encrypted administrator password for the instances running Windows. This procedure is not applicable for Linux and UNIX instances.
3492  
3493 =over
3494  
3495 =item InstanceId (required)
3496  
3497 The Instance Id for which to retrieve the password.
3498  
3499 =back
3500  
3501 Returns a Net::Amazon::EC2::InstancePassword object
3502  
3503 =cut
3504  
3505 0 ▶sub get_password_data {
Subroutine get_password_data: not called CC=3 SCAR=24.8
Pod documented
3506 0 my $self = shift;
3507 0 my %args = validate( @_, {
3508 instanceId => { type => SCALAR },
3509 });
3510  
3511 0 my $xml = $self->_sign(Action => 'GetPasswordData', %args);
3512
3513 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3514 0 return $self->_parse_errors($xml);
3515 }
3516 else {
3517 my $instance_password = Net::Amazon::EC2::InstancePassword->new(
3518 instance_id => $xml->{instanceId},
3519 timestamp => $xml->{timestamp},
3520 password_data => $xml->{passwordData},
3521 0 );
3522
3523 0 return $instance_password;
3524 }
3525 }
3526  
3527 =head2 modify_image_attribute(%params)
3528  
3529 This method modifies attributes of an machine image.
3530  
3531 =over
3532  
3533 =item ImageId (required)
3534  
3535 The AMI to modify the attributes of.
3536  
3537 =item Attribute (required)
3538  
3539 The attribute you wish to modify, right now the attributes you can modify are launchPermission and productCodes
3540  
3541 =item OperationType (required for launchPermission)
3542  
3543 The operation you wish to perform on the attribute. Right now just 'add' and 'remove' are supported.
3544  
3545 =item UserId (required for launchPermission)
3546  
3547 User Id's you wish to add/remove from the attribute.
3548  
3549 =item UserGroup (required for launchPermission)
3550  
3551 Groups you wish to add/remove from the attribute. Currently there is only one User Group available 'all' for all Amazon EC2 customers.
3552  
3553 =item ProductCode (required for productCodes)
3554  
3555 Attaches a product code to the AMI. Currently only one product code can be assigned to the AMI. Once this is set it cannot be changed or reset.
3556  
3557 =back
3558  
3559 Returns 1 if the modification succeeds.
3560  
3561 =cut
3562  
3563 0 ▶sub modify_image_attribute {
Subroutine modify_image_attribute: not called CC=4 SCAR=30.0
Pod documented
3564 0 my $self = shift;
3565 0 my %args = validate( @_, {
3566 ImageId => { type => SCALAR },
3567 Attribute => { type => SCALAR },
3568 OperationType => { type => SCALAR, optional => 1 },
3569 UserId => { type => SCALAR | ARRAYREF, optional => 1 },
3570 UserGroup => { type => SCALAR | ARRAYREF, optional => 1 },
3571 ProductCode => { type => SCALAR, optional => 1 },
3572 });
3573
3574
3575 0 my $xml = $self->_sign(Action => 'ModifyImageAttribute', %args);
3576
3577 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3578 0 return $self->_parse_errors($xml);
3579 }
3580 else {
3581 0 ▶ if ($xml->{return} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'return'} eq 'true') { } 0 0 0
3582 0 return 1;
3583 }
3584 else {
3585 0 return undef;
3586 }
3587 }
3588 }
3589  
3590 =head2 modify_instance_attribute(%params)
3591  
3592 Modify an attribute of an instance.
3593  
3594 =over
3595  
3596 =item InstanceId (required)
3597  
3598 The instance id we want to modify the attributes of.
3599  
3600 =item Attribute (required)
3601  
3602 The attribute we want to modify. Valid values are:
3603  
3604 =over
3605  
3606 =item * instanceType
3607  
3608 =item * kernel
3609  
3610 =item * ramdisk
3611  
3612 =item * userData
3613  
3614 =item * disableApiTermination
3615  
3616 =item * instanceInitiatedShutdownBehavior
3617  
3618 =item * rootDeviceName
3619  
3620 =item * blockDeviceMapping
3621  
3622 =back
3623  
3624 =item Value (required)
3625  
3626 The value to set the attribute to.
3627  
3628 You may also pass a hashref with one or more keys
3629 and values. This hashref will be flattened and
3630 passed to AWS.
3631  
3632 For example:
3633  
3634 $ec2->modify_instance_attribute(
3635 'InstanceId' => $id,
3636 'Attribute' => 'blockDeviceMapping',
3637 'Value' => {
3638 'BlockDeviceMapping.1.DeviceName' => '/dev/sdf1',
3639 'BlockDeviceMapping.1.Ebs.DeleteOnTermination' => 'true',
3640 }
3641 );
3642  
3643 =back
3644  
3645 Returns 1 if the modification succeeds.
3646  
3647 =cut
3648  
3649 0 ▶sub modify_instance_attribute {
Subroutine modify_instance_attribute: not called CC=5 SCAR=34.0
Pod documented
3650 0 my $self = shift;
3651 0 my %args = validate( @_, {
3652 InstanceId => { type => SCALAR },
3653 Attribute => { type => SCALAR },
3654 Value => { type => SCALAR | HASHREF },
3655 });
3656  
3657 0 ▶ if ( ref($args{'Value'}) eq "HASH" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"Value"} eq "HASH") 0 0 0
3658 # remove the 'Value' key and flatten the hashref
3659 0 my $href = delete $args{'Value'};
3660 0 map { $args{$_} = $href->{$_} } keys %{$href};
3661 }
3662
3663 0 my $xml = $self->_sign(Action => 'ModifyInstanceAttribute', %args);
3664  
3665 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3666 0 return $self->_parse_errors($xml);
3667 }
3668 else {
3669 0 ▶ if ($xml->{return} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'return'} eq 'true') { } 0 0 0
3670 0 return 1;
3671 }
3672 else {
3673 0 return undef;
3674 }
3675 }
3676 }
3677  
3678  
3679 =head2 modify_snapshot_attribute(%params)
3680  
3681 This method modifies attributes of a snapshot.
3682  
3683 =over
3684  
3685 =item SnapshotId (required)
3686  
3687 The snapshot id to modify the attributes of.
3688  
3689 =item UserId (optional)
3690  
3691 User Id you wish to add/remove create volume permissions for.
3692  
3693 =item UserGroup (optional)
3694  
3695 User Id you wish to add/remove create volume permissions for. To make the snapshot createable by all
3696 set the UserGroup to "all".
3697  
3698 =item Attribute (required)
3699  
3700 The attribute you wish to modify, right now the only attribute you can modify is "CreateVolumePermission"
3701  
3702 =item OperationType (required)
3703  
3704 The operation you wish to perform on the attribute. Right now just 'add' and 'remove' are supported.
3705  
3706 =back
3707  
3708 Returns 1 if the modification succeeds.
3709  
3710 =cut
3711  
3712 0 ▶sub modify_snapshot_attribute {
Subroutine modify_snapshot_attribute: not called CC=4 SCAR=30.0
Pod documented
3713 0 my $self = shift;
3714 0 my %args = validate( @_, {
3715 SnapshotId => { type => SCALAR },
3716 UserId => { type => SCALAR, optional => 1 },
3717 UserGroup => { type => SCALAR, optional => 1 },
3718 Attribute => { type => SCALAR },
3719 OperationType => { type => SCALAR },
3720 });
3721
3722
3723 0 my $xml = $self->_sign(Action => 'ModifySnapshotAttribute', %args);
3724
3725 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3726 0 return $self->_parse_errors($xml);
3727 }
3728 else {
3729 0 ▶ if ($xml->{return} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'return'} eq 'true') { } 0 0 0
3730 0 return 1;
3731 }
3732 else {
3733 0 return undef;
3734 }
3735 }
3736 }
3737  
3738 =head2 monitor_instances(%params)
3739  
3740 Enables monitoring for a running instance. For more information, refer to the Amazon CloudWatch Developer Guide.
3741  
3742 =over
3743  
3744 =item InstanceId (required)
3745  
3746 The instance id(s) to monitor. Can be a scalar or an array ref
3747  
3748 =back
3749  
3750 Returns an array ref of Net::Amazon::EC2::MonitoredInstance objects
3751  
3752 =cut
3753  
3754 0 ▶sub monitor_instances {
Subroutine monitor_instances: not called CC=5 SCAR=34.0
Pod documented
3755 0 my $self = shift;
3756 0 my %args = validate( @_, {
3757 InstanceId => { type => ARRAYREF | SCALAR, optional => 1 },
3758 });
3759  
3760 # If we have a array ref of instances lets split them out into their InstanceId.n format
3761 0 ▶ if (ref ($args{InstanceId}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"InstanceId"} eq "ARRAY") 0 0 0
3762 0 my $instance_ids = delete $args{InstanceId};
3763 0 _split_into_args('InstanceId.%s',\%args,$instance_ids);
3764 }
3765
3766 0 my $xml = $self->_sign(Action => 'MonitorInstances', %args);
3767
3768 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3769 0 return $self->_parse_errors($xml);
3770 }
3771 else {
3772 0 my $monitored_instances;
3773  
3774 0 foreach my $monitored_instance_item (@{$xml->{instancesSet}{item}}) {
3775 my $monitored_instance = Net::Amazon::EC2::ReservedInstance->new(
3776 instance_id => $monitored_instance_item->{instanceId},
3777 state => $monitored_instance_item->{monitoring}{state},
3778 0 );
3779
3780 0 push @$monitored_instances, $monitored_instance;
3781 }
3782
3783 0 return $monitored_instances;
3784 }
3785 }
3786  
3787 =head2 purchase_reserved_instances_offering(%params)
3788  
3789 Purchases a Reserved Instance for use with your account. With Amazon EC2 Reserved Instances, you purchase the right to
3790 launch Amazon EC2 instances for a period of time (without getting insufficient capacity errors) and pay a lower usage
3791 rate for the actual time used.
3792  
3793 =over
3794  
3795 =item ReservedInstancesOfferingId (required)
3796  
3797 ID of the Reserved Instances to describe. Can be either a scalar or an array ref.
3798  
3799 =item InstanceCount (optional)
3800  
3801 The number of Reserved Instances to purchase (default is 1). Can be either a scalar or an array ref.
3802  
3803 NOTE NOTE NOTE, the array ref needs to line up with the InstanceCount if you want to pass that in, so that
3804 the right number of instances are started of the right instance offering
3805  
3806 =back
3807  
3808 Returns 1 if the reservations succeeded.
3809  
3810 =cut
3811  
3812 0 ▶sub purchase_reserved_instances_offering {
Subroutine purchase_reserved_instances_offering: not called CC=6 SCAR=37.4
Pod documented
3813 0 my $self = shift;
3814 0 my %args = validate( @_, {
3815 ReservedInstancesOfferingId => { type => ARRAYREF | SCALAR },
3816 InstanceCount => { type => ARRAYREF | SCALAR, optional => 1 },
3817 });
3818
3819 # If we have a array ref of reserved instance offerings lets split them out into their ReservedInstancesOfferingId.n format
3820 0 ▶ if (ref ($args{ReservedInstancesOfferingId}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"ReservedInstancesOfferingId"} eq "ARRAY") 0 0 0
3821 0 my $reserved_instance_offering_ids = delete $args{ReservedInstancesOfferingId};
3822 0 _split_into_args('ReservedInstancesOfferingId.%s',\%args,$reserved_instance_offering_ids);
3823 }
3824  
3825 # If we have a array ref of instance counts lets split them out into their InstanceCount.n format
3826 0 ▶ if (ref ($args{InstanceCount}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"InstanceCount"} eq "ARRAY") 0 0 0
3827 0 my $instance_counts = delete $args{InstanceCount};
3828 0 _split_into_args('InstanceCount.%s',\%args,$instance_counts);
3829 }
3830
3831 0 my $xml = $self->_sign(Action => 'PurchaseReservedInstancesOffering', %args);
3832
3833 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3834 0 return $self->_parse_errors($xml);
3835 }
3836 else {
3837 0 ▶ if ($xml->{reservedInstancesId} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'reservedInstancesId'}) { } 0 0 0
3838 0 return 1;
3839 }
3840 else {
3841 0 return undef;
3842 }
3843 }
3844 }
3845  
3846 =head2 reboot_instances(%params)
3847  
3848 This method reboots an instance. It takes the following parameters:
3849  
3850 =over
3851  
3852 =item InstanceId (required)
3853  
3854 Instance Id of the instance you wish to reboot. Can be either a scalar or array ref of instances to reboot.
3855  
3856 =back
3857  
3858 Returns 1 if the reboot succeeded.
3859  
3860 =cut
3861  
3862 0 ▶sub reboot_instances {
Subroutine reboot_instances: not called CC=5 SCAR=34.0
Pod documented
3863 0 my $self = shift;
3864 0 my %args = validate( @_, {
3865 InstanceId => { type => SCALAR | ARRAYREF },
3866 });
3867
3868 # If we have a array ref of instances lets split them out into their InstanceId.n format
3869 0 ▶ if (ref ($args{InstanceId}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"InstanceId"} eq "ARRAY") 0 0 0
3870 0 my $instance_ids = delete $args{InstanceId};
3871 0 _split_into_args('InstanceId.%s',\%args,$instance_ids);
3872 }
3873
3874 0 my $xml = $self->_sign(Action => 'RebootInstances', %args);
3875
3876 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3877 0 return $self->_parse_errors($xml);
3878 }
3879 else {
3880 0 ▶ if ($xml->{return} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'return'} eq 'true') { } 0 0 0
3881 0 return 1;
3882 }
3883 else {
3884 0 return undef;
3885 }
3886 }
3887 }
3888  
3889 =head2 register_image(%params)
3890  
3891 This method registers an AMI on the EC2. It takes the following parameter:
3892  
3893 =over
3894  
3895 =item ImageLocation (optional)
3896  
3897 The location of the AMI manifest on S3
3898  
3899 =item Name (required)
3900  
3901 The name of the AMI that was provided during image creation.
3902  
3903 =item Description (optional)
3904  
3905 The description of the AMI.
3906  
3907 =item Architecture (optional)
3908  
3909 The architecture of the image. Either i386 or x86_64
3910  
3911 =item KernelId (optional)
3912  
3913 The ID of the kernel to select.
3914  
3915 =item RamdiskId (optional)
3916  
3917 The ID of the RAM disk to select. Some kernels require additional drivers at launch.
3918  
3919 =item RootDeviceName (optional)
3920  
3921 The root device name (e.g., /dev/sda1).
3922  
3923 =item BlockDeviceMapping (optional)
3924  
3925 This needs to be a data structure like this:
3926  
3927 [
3928 {
3929 deviceName => "/dev/sdh", (optional)
3930 virtualName => "ephemerel0", (optional)
3931 noDevice => "/dev/sdl", (optional),
3932 ebs => {
3933 snapshotId => "snap-0000", (optional)
3934 volumeSize => "20", (optional)
3935 deleteOnTermination => "false", (optional)
3936 },
3937 },
3938 ...
3939 ]
3940  
3941 =back
3942  
3943 Returns the image id of the new image on EC2.
3944  
3945 =cut
3946  
3947 0 ▶sub register_image {
Subroutine register_image: not called CC=11 SCAR=48.8
Pod documented
3948 0 my $self = shift;
3949 0 my %args = validate( @_, {
3950 ImageLocation => { type => SCALAR, optional => 1 },
3951 Name => { type => SCALAR },
3952 Description => { type => SCALAR, optional => 1 },
3953 Architecture => { type => SCALAR, optional => 1 },
3954 KernelId => { type => SCALAR, optional => 1 },
3955 RamdiskId => { type => SCALAR, optional => 1 },
3956 RootDeviceName => { type => SCALAR, optional => 1 },
3957 BlockDeviceMapping => { type => ARRAYREF, optional => 1 },
3958 });
3959  
3960
3961 # If we have a array ref of block devices, we need to split them up
3962 0 ▶ if (ref ($args{BlockDeviceMapping}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"BlockDeviceMapping"} eq "ARRAY") 0 0 0
3963 0 my $block_devices = delete $args{BlockDeviceMapping};
3964 0 my $count = 1;
3965 0 foreach my $block_device (@{$block_devices}) {
3966 0 ▶ $args{"BlockDeviceMapping." . $count . ".DeviceName"} = $block_device->{deviceName} if $block_device->{deviceName};
Branch: 1 branch
BranchTrueFalseTotal
if $block_device->{"deviceName"} 0 0 0
3967 0 ▶ $args{"BlockDeviceMapping." . $count . ".VirtualName"} = $block_device->{virtualName} if $block_device->{virtualName};
Branch: 1 branch
BranchTrueFalseTotal
if $block_device->{"virtualName"} 0 0 0
3968 0 ▶ $args{"BlockDeviceMapping." . $count . ".NoDevice"} = $block_device->{noDevice} if $block_device->{noDevice};
Branch: 1 branch
BranchTrueFalseTotal
if $block_device->{"noDevice"} 0 0 0
3969 0 ▶ $args{"BlockDeviceMapping." . $count . ".Ebs.SnapshotId"} = $block_device->{ebs}{snapshotId} if $block_device->{ebs}{snapshotId};
Branch: 1 branch
BranchTrueFalseTotal
if $block_device->{"ebs"}{"snapshotId"} 0 0 0
3970 0 ▶ $args{"BlockDeviceMapping." . $count . ".Ebs.VolumeSize"} = $block_device->{ebs}{volumeSize} if $block_device->{ebs}{volumeSize};
Branch: 1 branch
BranchTrueFalseTotal
if $block_device->{"ebs"}{"volumeSize"} 0 0 0
3971 0 ▶ $args{"BlockDeviceMapping." . $count . ".Ebs.DeleteOnTermination"} = $block_device->{ebs}{deleteOnTermination} if $block_device->{ebs}{deleteOnTermination};
Branch: 1 branch
BranchTrueFalseTotal
if $block_device->{"ebs"}{"deleteOnTermination"} 0 0 0
3972 0 $count++;
3973 }
3974 }
3975  
3976 0 my $xml = $self->_sign(Action => 'RegisterImage', %args);
3977  
3978 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
3979 0 return $self->_parse_errors($xml);
3980 }
3981 else {
3982 0 return $xml->{imageId};
3983 }
3984 }
3985  
3986 =head2 release_address(%params)
3987  
3988 Releases an allocated IP address. It takes the following arguments:
3989  
3990 =over
3991  
3992 =item PublicIp (required)
3993  
3994 The IP address to release
3995  
3996 =back
3997  
3998 Returns true if the releasing succeeded.
3999  
4000 =cut
4001  
4002 0 ▶sub release_address {
Subroutine release_address: not called CC=4 SCAR=30.0
Pod documented
4003 0 my $self = shift;
4004 0 my %args = validate( @_, {
4005 PublicIp => { type => SCALAR },
4006 });
4007
4008 0 my $xml = $self->_sign(Action => 'ReleaseAddress', %args);
4009  
4010 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
4011 0 return $self->_parse_errors($xml);
4012 }
4013 else {
4014 0 ▶ if ($xml->{return} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'return'} eq 'true') { } 0 0 0
4015 0 return 1;
4016 }
4017 else {
4018 0 return undef;
4019 }
4020 }
4021 }
4022  
4023 0 ▶sub release_vpc_address {
Subroutine release_vpc_address: not called CC=4 SCAR=30.0
Pod undocumented
4024 0 my $self = shift;
4025 0 my %args = validate( @_, {
4026 AllocationId => { type => SCALAR },
4027 });
4028  
4029 0 my $xml = $self->_sign(Action => 'ReleaseAddress', %args);
4030  
4031 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
4032 0 return $self->_parse_errors($xml);
4033 }
4034 else {
4035 0 ▶ if ($xml->{return} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'return'} eq 'true') { } 0 0 0
4036 0 return 1;
4037 }
4038 else {
4039 0 return undef;
4040 }
4041 }
4042 }
4043  
4044 =head2 reset_image_attribute(%params)
4045  
4046 This method resets an attribute for an AMI to its default state (NOTE: product codes cannot be reset).
4047 It takes the following parameters:
4048  
4049 =over
4050  
4051 =item ImageId (required)
4052  
4053 The image id of the AMI you wish to reset the attributes on.
4054  
4055 =item Attribute (required)
4056  
4057 The attribute you want to reset.
4058  
4059 =back
4060  
4061 Returns 1 if the attribute reset succeeds.
4062  
4063 =cut
4064  
4065 0 ▶sub reset_image_attribute {
Subroutine reset_image_attribute: not called CC=4 SCAR=30.0
Pod documented
4066 0 my $self = shift;
4067 0 my %args = validate( @_, {
4068 ImageId => { type => SCALAR },
4069 Attribute => { type => SCALAR },
4070 });
4071
4072 0 my $xml = $self->_sign(Action => 'ResetImageAttribute', %args);
4073  
4074 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
4075 0 return $self->_parse_errors($xml);
4076 }
4077 else {
4078 0 ▶ if ($xml->{return} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'return'} eq 'true') { } 0 0 0
4079 0 return 1;
4080 }
4081 else {
4082 0 return undef;
4083 }
4084 }
4085 }
4086  
4087 =head2 reset_instance_attribute(%params)
4088  
4089 Reset an attribute of an instance. Only one attribute can be specified per call.
4090  
4091 =over
4092  
4093 =item InstanceId (required)
4094  
4095 The instance id we want to reset the attributes of.
4096  
4097 =item Attribute (required)
4098  
4099 The attribute we want to reset. Valid values are:
4100  
4101 =over
4102  
4103 =item * kernel
4104  
4105 =item * ramdisk
4106  
4107 =back
4108  
4109 =back
4110  
4111 Returns 1 if the reset succeeds.
4112  
4113 =cut
4114  
4115 0 ▶sub reset_instance_attribute {
Subroutine reset_instance_attribute: not called CC=4 SCAR=30.0
Pod documented
4116 0 my $self = shift;
4117 0 my %args = validate( @_, {
4118 InstanceId => { type => SCALAR },
4119 Attribute => { type => SCALAR },
4120 });
4121
4122 0 my $xml = $self->_sign(Action => 'ResetInstanceAttribute', %args);
4123  
4124 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
4125 0 return $self->_parse_errors($xml);
4126 }
4127 else {
4128 0 ▶ if ($xml->{return} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'return'} eq 'true') { } 0 0 0
4129 0 return 1;
4130 }
4131 else {
4132 0 return undef;
4133 }
4134 }
4135 }
4136  
4137 =head2 reset_snapshot_attribute(%params)
4138  
4139 This method resets an attribute for an snapshot to its default state.
4140  
4141 It takes the following parameters:
4142  
4143 =over
4144  
4145 =item SnapshotId (required)
4146  
4147 The snapshot id of the snapshot you wish to reset the attributes on.
4148  
4149 =item Attribute (required)
4150  
4151 The attribute you want to reset (currently "CreateVolumePermission" is the only
4152 valid attribute).
4153  
4154 =back
4155  
4156 Returns 1 if the attribute reset succeeds.
4157  
4158 =cut
4159  
4160 0 ▶sub reset_snapshot_attribute {
Subroutine reset_snapshot_attribute: not called CC=4 SCAR=30.0
Pod documented
4161 0 my $self = shift;
4162 0 my %args = validate( @_, {
4163 SnapshotId => { type => SCALAR },
4164 Attribute => { type => SCALAR },
4165 });
4166
4167 0 my $xml = $self->_sign(Action => 'ResetSnapshotAttribute', %args);
4168  
4169 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
4170 0 return $self->_parse_errors($xml);
4171 }
4172 else {
4173 0 ▶ if ($xml->{return} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'return'} eq 'true') { } 0 0 0
4174 0 return 1;
4175 }
4176 else {
4177 0 return undef;
4178 }
4179 }
4180 }
4181  
4182 =head2 revoke_security_group_ingress(%params)
4183  
4184 This method revoke permissions to a security group. It takes the following parameters:
4185  
4186 =over
4187  
4188 =item GroupName (required)
4189  
4190 The name of the group to revoke security rules from.
4191  
4192 =item SourceSecurityGroupName (required when revoking a user and group together)
4193  
4194 Name of the group to revoke access from.
4195  
4196 =item SourceSecurityGroupOwnerId (required when revoking a user and group together)
4197  
4198 Owner of the group to revoke access from.
4199  
4200 =item IpProtocol (required when revoking access from a CIDR)
4201  
4202 IP Protocol of the rule you are revoking access from (TCP, UDP, or ICMP)
4203  
4204 =item FromPort (required when revoking access from a CIDR)
4205  
4206 Beginning of port range to revoke access from.
4207  
4208 =item ToPort (required when revoking access from a CIDR)
4209  
4210 End of port range to revoke access from.
4211  
4212 =item CidrIp (required when revoking access from a CIDR)
4213  
4214 The CIDR IP space we are revoking access from.
4215  
4216 =back
4217  
4218 Revoking a rule can be done in two ways: revoking a source group name + source group owner id, or, by Protocol + start port + end port + CIDR IP. The two are mutally exclusive.
4219  
4220 Returns 1 if rule is revoked successfully.
4221  
4222 =cut
4223  
4224 0 ▶sub revoke_security_group_ingress {
Subroutine revoke_security_group_ingress: not called CC=4 SCAR=30.0
Pod documented
4225 0 my $self = shift;
4226 0 my %args = validate( @_, {
4227 GroupName => { type => SCALAR, optional => 1 },
4228 GroupId => { type => SCALAR, optional => 1 },
4229 SourceSecurityGroupName => {
4230 type => SCALAR,
4231 depends => ['SourceSecurityGroupOwnerId'],
4232 optional => 1 ,
4233 },
4234 SourceSecurityGroupOwnerId => { type => SCALAR, optional => 1 },
4235 IpProtocol => {
4236 type => SCALAR,
4237 depends => ['FromPort', 'ToPort', 'CidrIp'],
4238 optional => 1
4239 },
4240 FromPort => { type => SCALAR, optional => 1 },
4241 ToPort => { type => SCALAR, optional => 1 },
4242 CidrIp => { type => SCALAR, optional => 1 },
4243 });
4244
4245
4246 0 my $xml = $self->_sign(Action => 'RevokeSecurityGroupIngress', %args);
4247  
4248 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
4249 0 return $self->_parse_errors($xml);
4250 }
4251 else {
4252 0 ▶ if ($xml->{return} eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($xml->{'return'} eq 'true') { } 0 0 0
4253 0 return 1;
4254 }
4255 else {
4256 0 return undef;
4257 }
4258 }
4259 }
4260  
4261 =head2 run_instances(%params)
4262  
4263 This method will start instance(s) of AMIs on EC2. The parameters
4264 indicate which AMI to instantiate and how many / what properties they
4265 have:
4266  
4267 =over
4268  
4269 =item ImageId (required)
4270  
4271 The image id you want to start an instance of.
4272  
4273 =item MinCount (required)
4274  
4275 The minimum number of instances to start.
4276  
4277 =item MaxCount (required)
4278  
4279 The maximum number of instances to start.
4280  
4281 =item KeyName (optional)
4282  
4283 The keypair name to associate this instance with. If omitted, will use your default keypair.
4284  
4285 =item SecurityGroup (optional)
4286  
4287 An scalar or array ref. Will associate this instance with the group names passed in. If omitted, will be associated with the default security group.
4288  
4289 =item SecurityGroupId (optional)
4290  
4291 An scalar or array ref. Will associate this instance with the group ids passed in. If omitted, will be associated with the default security group.
4292  
4293 =item AdditionalInfo (optional)
4294  
4295 Specifies additional information to make available to the instance(s).
4296  
4297 =item UserData (optional)
4298  
4299 Optional data to pass into the instance being started. Needs to be base64 encoded.
4300  
4301 =item InstanceType (optional)
4302  
4303 Specifies the type of instance to start.
4304  
4305 See http://aws.amazon.com/ec2/instance-types
4306  
4307 The options are:
4308  
4309 =over
4310  
4311 =item m1.small (default)
4312  
4313 1 EC2 Compute Unit (1 virtual core with 1 EC2 Compute Unit). 32-bit or 64-bit, 1.7GB RAM, 160GB disk
4314  
4315 =item m1.medium Medium Instance
4316  
4317 2 EC2 Compute Units (1 virtual core with 2 EC2 Compute Unit), 32-bit or 64-bit, 3.75GB RAM, 410GB disk
4318  
4319 =item m1.large: Standard Large Instance
4320  
4321 4 EC2 Compute Units (2 virtual cores with 2 EC2 Compute Units each). 64-bit, 7.5GB RAM, 850GB disk
4322  
4323 =item m1.xlarge: Standard Extra Large Instance
4324  
4325 8 EC2 Compute Units (4 virtual cores with 2 EC2 Compute Units each). 64-bit, 15GB RAM, 1690GB disk
4326  
4327 =item t1.micro Micro Instance
4328  
4329 Up to 2 EC2 Compute Units (for short periodic bursts), 32-bit or 64-bit, 613MB RAM, EBS storage only
4330  
4331 =item c1.medium: High-CPU Medium Instance
4332  
4333 5 EC2 Compute Units (2 virtual cores with 2.5 EC2 Compute Units each). 32-bit or 64-bit, 1.7GB RAM, 350GB disk
4334  
4335 =item c1.xlarge: High-CPU Extra Large Instance
4336  
4337 20 EC2 Compute Units (8 virtual cores with 2.5 EC2 Compute Units each). 64-bit, 7GB RAM, 1690GB disk
4338  
4339 =item m2.2xlarge High-Memory Double Extra Large Instance
4340  
4341 13 EC2 Compute Units (4 virtual cores with 3.25 EC2 Compute Units each). 64-bit, 34.2GB RAM, 850GB disk
4342  
4343 =item m2.4xlarge High-Memory Quadruple Extra Large Instance
4344  
4345 26 EC2 Compute Units (8 virtual cores with 3.25 EC2 Compute Units each). 64-bit, 68.4GB RAM, 1690GB disk
4346  
4347 =item cc1.4xlarge Cluster Compute Quadruple Extra Large Instance
4348  
4349 33.5 EC2 Compute Units (2 x Intel Xeon X5570, quad-core "Nehalem" architecture), 64-bit, 23GB RAM, 1690GB disk, 10Gbit Ethernet
4350  
4351 =item cc1.8xlarge Cluster Compute Eight Extra Large Instance
4352  
4353 88 EC2 Compute Units (2 x Intel Xeon E5-2670, eight-core "Sandy Bridge" architecture), 64-bit, 60.5GB RAM, 3370GB disk, 10Gbit Ethernet
4354  
4355 =item cg1.4xlarge Cluster GPU Quadruple Extra Large Instance
4356  
4357 33.5 EC2 Compute Units (2 x Intel Xeon X5570, quad-core "Nehalem" architecture), 64-bit, 22GB RAM 1690GB disk, 10Gbit Ethernet, 2 x NVIDIA Tesla "Fermi" M2050 GPUs
4358  
4359 =item hi1.4xlarge High I/O Quadruple Extra Large Instance
4360  
4361 35 EC2 Compute Units (16 virtual cores), 60.5GB RAM, 64-bit, 2 x 1024GB SSD disk, 10Gbit Ethernet
4362  
4363 =back
4364  
4365 =item Placement.AvailabilityZone (optional)
4366  
4367 The availability zone you want to run the instance in
4368  
4369 =item KernelId (optional)
4370  
4371 The id of the kernel you want to launch the instance with
4372  
4373 =item RamdiskId (optional)
4374  
4375 The id of the ramdisk you want to launch the instance with
4376  
4377 =item BlockDeviceMapping.VirtualName (optional)
4378  
4379 This is the virtual name for a blocked device to be attached, may pass in a scalar or arrayref
4380  
4381 =item BlockDeviceMapping.DeviceName (optional)
4382  
4383 This is the device name for a block device to be attached, may pass in a scalar or arrayref
4384  
4385 =item BlockDeviceMapping.Ebs.VolumeSize (optional)
4386  
4387 Specifies the size of the root block device as an integer (GB). If used, required
4388 that C<BlockDeviceMapping.DeviceName> also be specified. One may pass in a
4389 scalar or arrayref. This parameter will override the disk size settings implied
4390 by the C<InstanceType>, if used.
4391  
4392 Additional volume related parameters include,
4393  
4394 =over
4395  
4396 =item BlockDeviceMapping.Ebs.SnapshotId
4397
4398 May pass in a scalar or arrayref.
4399  
4400 =item BlockDeviceMapping.Ebs.VolumeType
4401  
4402 May pass in a scalar or arrayref.
4403  
4404 =item BlockDeviceMapping.Ebs.DeleteOnTermination
4405  
4406 May pass in a scalar or arrayref.
4407  
4408 =back
4409  
4410 =item Encoding (optional)
4411  
4412 The encoding.
4413  
4414 =item Version (optional)
4415  
4416 The version.
4417  
4418 =item Monitoring.Enabled (optional)
4419  
4420 Enables monitoring for this instance.
4421  
4422 =item SubnetId (optional)
4423  
4424 Specifies the subnet ID within which to launch the instance(s) for Amazon Virtual Private Cloud.
4425  
4426 =item ClientToken (optional)
4427  
4428 Specifies the idempotent instance id.
4429  
4430 =item EbsOptimized (optional)
4431  
4432 Whether the instance is optimized for EBS I/O.
4433  
4434 =item PrivateIpAddress (optional)
4435  
4436 Specifies the private IP address to use when launching an Amazon VPC instance.
4437  
4438 =item IamInstanceProfile.Name (optional)
4439  
4440 Specifies the IAM profile to associate with the launched instance(s). This is the name of the role.
4441  
4442 =item IamInstanceProfile.Arn (optional)
4443  
4444 Specifies the IAM profile to associate with the launched instance(s). This is the ARN of the profile.
4445  
4446  
4447 =back
4448  
4449 Returns a Net::Amazon::EC2::ReservationInfo object
4450  
4451 =cut
4452  
4453 0 ▶sub run_instances {
Subroutine run_instances: not called CC=33 SCAR=70.2
Pod documented
4454 0 my $self = shift;
4455 0 my %args = validate( @_, {
4456 ImageId => { type => SCALAR },
4457 MinCount => { type => SCALAR },
4458 MaxCount => { type => SCALAR },
4459 KeyName => { type => SCALAR, optional => 1 },
4460 SecurityGroup => { type => SCALAR | ARRAYREF, optional => 1 },
4461 SecurityGroupId => { type => SCALAR | ARRAYREF, optional => 1 },
4462 AddressingType => { type => SCALAR, optional => 1 },
4463 AdditionalInfo => { type => SCALAR, optional => 1 },
4464 UserData => { type => SCALAR, optional => 1 },
4465 InstanceType => { type => SCALAR, optional => 1 },
4466 'Placement.AvailabilityZone' => { type => SCALAR, optional => 1 },
4467 KernelId => { type => SCALAR, optional => 1 },
4468 RamdiskId => { type => SCALAR, optional => 1 },
4469 'BlockDeviceMapping.VirtualName' => { type => SCALAR | ARRAYREF, optional => 1 },
4470 'BlockDeviceMapping.DeviceName' => { type => SCALAR | ARRAYREF, optional => 1 },
4471 'BlockDeviceMapping.Ebs.SnapshotId' => { type => SCALAR | ARRAYREF, optional => 1 },
4472 'BlockDeviceMapping.Ebs.VolumeSize' => { type => SCALAR | ARRAYREF, optional => 1 },
4473 'BlockDeviceMapping.Ebs.VolumeType' => { type => SCALAR | ARRAYREF, optional => 1 },
4474 'BlockDeviceMapping.Ebs.DeleteOnTermination' => { type => SCALAR | ARRAYREF, optional => 1 },
4475 Encoding => { type => SCALAR, optional => 1 },
4476 Version => { type => SCALAR, optional => 1 },
4477 'Monitoring.Enabled' => { type => SCALAR, optional => 1 },
4478 SubnetId => { type => SCALAR, optional => 1 },
4479 DisableApiTermination => { type => SCALAR, optional => 1 },
4480 InstanceInitiatedShutdownBehavior => { type => SCALAR, optional => 1 },
4481 ClientToken => { type => SCALAR, optional => 1 },
4482 EbsOptimized => { type => SCALAR, optional => 1 },
4483 PrivateIpAddress => { type => SCALAR, optional => 1 },
4484 'IamInstanceProfile.Name' => { type => SCALAR, optional => 1 },
4485 'IamInstanceProfile.Arn' => { type => SCALAR, optional => 1 },
4486  
4487 });
4488
4489 # If we have a array ref of SecurityGroups lets split them out into their SecurityGroup.n format
4490 0 ▶ if (ref ($args{SecurityGroup}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"SecurityGroup"} eq "ARRAY") 0 0 0
4491 0 my $security_groups = delete $args{SecurityGroup};
4492 0 _split_into_args('SecurityGroup.%s',\%args,$security_groups);
4493 }
4494  
4495 # If we have a array ref of SecurityGroupIds lets split them out into their SecurityGroupId.n format
4496 0 ▶ if (ref ($args{SecurityGroupId}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"SecurityGroupId"} eq "ARRAY") 0 0 0
4497 0 my $security_groups = delete $args{SecurityGroupId};
4498 0 _split_into_args('SecurityGroupId.%s',\%args,$security_groups);
4499 }
4500  
4501 # If we have a array ref of block device virtual names lets split them out into their BlockDeviceMapping.n.VirtualName format
4502 0 ▶ if (ref ($args{'BlockDeviceMapping.VirtualName'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"BlockDeviceMapping.VirtualName"} eq "ARRAY") 0 0 0
4503 0 my $virtual_names = delete $args{'BlockDeviceMapping.VirtualName'};
4504 0 _split_into_args('BlockDeviceMapping.%s.VirtualName',\%args,$virtual_names);
4505 }
4506  
4507 # If we have a array ref of block device device names lets split them out into their BlockDeviceMapping.n.DeviceName format
4508 0 ▶ if (ref ($args{'BlockDeviceMapping.DeviceName'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"BlockDeviceMapping.DeviceName"} eq "ARRAY") 0 0 0
4509 0 my $device_names = delete $args{'BlockDeviceMapping.DeviceName'};
4510 0 _split_into_args('BlockDeviceMapping.%s.DeviceName',\%args,$device_names);
4511 }
4512  
4513 # If we have a array ref of block device EBS Snapshots lets split them out into their BlockDeviceMapping.n.Ebs.SnapshotId format
4514 0 ▶ if (ref ($args{'BlockDeviceMapping.Ebs.SnapshotId'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"BlockDeviceMapping.Ebs.SnapshotId"} eq "ARRAY") 0 0 0
4515 0 my $snapshot_ids = delete $args{'BlockDeviceMapping.Ebs.SnapshotId'};
4516 0 _split_into_args('BlockDeviceMapping.%s.Ebs.SnapshotId',\%args,$snapshot_ids);
4517 }
4518  
4519 # If we have a array ref of block device EBS VolumeSizes lets split them out into their BlockDeviceMapping.n.Ebs.VolumeSize format
4520 0 ▶ if (ref ($args{'BlockDeviceMapping.Ebs.VolumeSize'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"BlockDeviceMapping.Ebs.VolumeSize"} eq "ARRAY") 0 0 0
4521 0 my $volume_sizes = delete $args{'BlockDeviceMapping.Ebs.VolumeSize'};
4522 0 _split_into_args('BlockDeviceMapping.%s.Ebs.VolumeSize',\%args,$volume_sizes);
4523 }
4524  
4525 # If we have a array ref of block device EBS VolumeTypes lets split them out into their BlockDeviceMapping.n.Ebs.VolumeType format
4526 0 ▶ if (ref ($args{'BlockDeviceMapping.Ebs.VolumeType'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"BlockDeviceMapping.Ebs.VolumeType"} eq "ARRAY") 0 0 0
4527 0 my $volume_types = delete $args{'BlockDeviceMapping.Ebs.VolumeType'};
4528 0 _split_into_args('BlockDeviceMapping.%s.Ebs.VolumeType',\%args,$volume_types);
4529 }
4530  
4531 # If we have a array ref of block device EBS DeleteOnTerminations lets split them out into their BlockDeviceMapping.n.Ebs.DeleteOnTermination format
4532 0 ▶ if (ref ($args{'BlockDeviceMapping.Ebs.DeleteOnTermination'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"BlockDeviceMapping.Ebs.DeleteOnTermination"} eq "ARRAY") 0 0 0
4533 0 my $terminations = delete $args{'BlockDeviceMapping.Ebs.DeleteOnTermination'};
4534 0 _split_into_args('BlockDeviceMapping.%s.Ebs.DeleteOnTermination',\%args,$terminations);
4535 }
4536  
4537 0 my $xml = $self->_sign(Action => 'RunInstances', %args);
4538
4539 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
4540 0 return $self->_parse_errors($xml);
4541 }
4542 else {
4543 0 my $group_sets=[];
4544 0 foreach my $group_arr (@{$xml->{groupSet}{item}}) {
4545 my $group = Net::Amazon::EC2::GroupSet->new(
4546 group_id => $group_arr->{groupId},
4547 group_name => $group_arr->{groupName},
4548 0 );
4549 0 push @$group_sets, $group;
4550 }
4551  
4552 0 my $running_instances;
4553 0 foreach my $instance_elem (@{$xml->{instancesSet}{item}}) {
4554 my $instance_state_type = Net::Amazon::EC2::InstanceState->new(
4555 code => $instance_elem->{instanceState}{code},
4556 name => $instance_elem->{instanceState}{name},
4557 0 );
4558
4559 0 my $product_codes;
4560 my $state_reason;
4561 0 my $block_device_mappings;
4562
4563 0 ▶ if (grep { defined && length } $instance_elem->{productCodes} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $instance_elem->{"productCodes"}) 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
4564 0 foreach my $pc (@{$instance_elem->{productCodes}{item}}) {
4565 0 my $product_code = Net::Amazon::EC2::ProductCode->new( product_code => $pc->{productCode} );
4566 0 push @$product_codes, $product_code;
4567 }
4568 }
4569  
4570 0 ▶ unless ( grep { defined && length } $instance_elem->{reason} and ref $instance_elem->{reason} ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {defined $_ and length $_;} $instance_elem->{"reason"} and ref $instance_elem->{"reason"} ne "HASH") 0 0 0
Condition0%0/6
grep {defined $_ and length $_;} $instance_elem->{"reason"} and ref $instance_elem->{"reason"} ne "HASH"
!ll&&!rl&&r
000
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
grep {defined $_ and length $_;} $instance_elem->{"reason"} and ref $instance_elem->{"reason"} ne "HASH"
grep {defined $_ and length $_;} $instance_elem->{"reason"} ref $instance_elem->{"reason"} ne "HASH"
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A and B
A= grep {defined $_ and length $_;} $instance_elem->{"reason"}B= ref $instance_elem->{"reason"} ne "HASH"
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
4571 0 $instance_elem->{reason} = undef;
4572 }
4573  
4574 0 ▶ unless ( grep { defined && length } $instance_elem->{privateDnsName} and ref $instance_elem->{privateDnsName} ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {defined $_ and length $_;} $instance_elem->{"privateDnsName"} and ref $instance_elem->{"privateDnsName"} ne "HASH") 0 0 0
Condition0%0/6
grep {defined $_ and length $_;} $instance_elem->{"privateDnsName"} and ref $instance_elem->{"privateDnsName"} ne "HASH"
!ll&&!rl&&r
000
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
grep {defined $_ and length $_;} $instance_elem->{"privateDnsName"} and ref $instance_elem->{"privateDnsName"} ne "HASH"
grep {defined $_ and length $_;} $instance_elem->{"privateDnsName"} ref $instance_elem->{"privateDnsName"} ne "HASH"
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A and B
A= grep {defined $_ and length $_;} $instance_elem->{"privateDnsName"}B= ref $instance_elem->{"privateDnsName"} ne "HASH"
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
4575 0 $instance_elem->{privateDnsName} = undef;
4576 }
4577  
4578 0 ▶ unless ( grep { defined && length } $instance_elem->{dnsName} and ref $instance_elem->{dnsName} ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {defined $_ and length $_;} $instance_elem->{"dnsName"} and ref $instance_elem->{"dnsName"} ne "HASH") 0 0 0
Condition0%0/6
grep {defined $_ and length $_;} $instance_elem->{"dnsName"} and ref $instance_elem->{"dnsName"} ne "HASH"
!ll&&!rl&&r
000
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
grep {defined $_ and length $_;} $instance_elem->{"dnsName"} and ref $instance_elem->{"dnsName"} ne "HASH"
grep {defined $_ and length $_;} $instance_elem->{"dnsName"} ref $instance_elem->{"dnsName"} ne "HASH"
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A and B
A= grep {defined $_ and length $_;} $instance_elem->{"dnsName"}B= ref $instance_elem->{"dnsName"} ne "HASH"
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
4579 0 $instance_elem->{dnsName} = undef;
4580 }
4581  
4582 0 ▶ if ( grep { defined && length && $_->{code} && $_->{message} } $instance_elem->{stateReason} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_ and $_->{"code"} and $_->{"message"};} $instance_elem->{"stateReason"}) 0 0 0
Condition0%0/9
defined $_ && length $_ && $_->{'code'} && $_->{'message'}
!ll&&!rl&&r
000
defined $_ and length $_ and $_->{"code"}
!ll&&!rl&&r
000
defined $_ and length $_
!ll&&!rl&&r
000
MC/DC0%0/4
defined $_ && length $_ && $_->{'code'} && $_->{'message'}
defined $_ length $_ $_->{"code"} $_->{'message'}
Truth table0%0/5
A and B and C && D
A= defined $_B= length $_C= $_->{"code"}D= $_->{'message'}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
4583 $state_reason = Net::Amazon::EC2::StateReason->new(
4584 code => $instance_elem->{stateReason}{code},
4585 message => $instance_elem->{stateReason}{message},
4586 0 );
4587 }
4588  
4589 0 ▶ if ( grep { defined && length } $instance_elem->{blockDeviceMapping} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $instance_elem->{"blockDeviceMapping"}) 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
4590 0 foreach my $bdm ( @{$instance_elem->{blockDeviceMapping}{item}} ) {
4591 my $ebs_block_device_mapping = Net::Amazon::EC2::EbsInstanceBlockDeviceMapping->new(
4592 volume_id => $bdm->{ebs}{volumeId},
4593 status => $bdm->{ebs}{status},
4594 attach_time => $bdm->{ebs}{attachTime},
4595 delete_on_termination => $bdm->{ebs}{deleteOnTermination},
4596 0 );
4597
4598 my $block_device_mapping = Net::Amazon::EC2::BlockDeviceMapping->new(
4599 ebs => $ebs_block_device_mapping,
4600 device_name => $bdm->{deviceName},
4601 0 );
4602 0 push @$block_device_mappings, $block_device_mapping;
4603 }
4604 }
4605  
4606 0 my $placement_response = Net::Amazon::EC2::PlacementResponse->new( availability_zone => $instance_elem->{placement}{availabilityZone} );
4607
4608 my $running_instance = Net::Amazon::EC2::RunningInstances->new(
4609 ami_launch_index => $instance_elem->{amiLaunchIndex},
4610 dns_name => $instance_elem->{dnsName},
4611 image_id => $instance_elem->{imageId},
4612 kernel_id => $instance_elem->{kernelId},
4613 ramdisk_id => $instance_elem->{ramdiskId},
4614 instance_id => $instance_elem->{instanceId},
4615 instance_state => $instance_state_type,
4616 instance_type => $instance_elem->{instanceType},
4617 key_name => $instance_elem->{keyName},
4618 launch_time => $instance_elem->{launchTime},
4619 placement => $placement_response,
4620 private_dns_name => $instance_elem->{privateDnsName},
4621 reason => $instance_elem->{reason},
4622 platform => $instance_elem->{platform},
4623 monitoring => $instance_elem->{monitoring}{state},
4624 subnet_id => $instance_elem->{subnetId},
4625 vpc_id => $instance_elem->{vpcId},
4626 private_ip_address => $instance_elem->{privateIpAddress},
4627 ip_address => $instance_elem->{ipAddress},
4628 architecture => $instance_elem->{architecture},
4629 root_device_name => $instance_elem->{rootDeviceName},
4630 root_device_type => $instance_elem->{rootDeviceType},
4631 0 block_device_mapping => $block_device_mappings,
4632 state_reason => $state_reason,
4633 );
4634  
4635 0 ▶ if ($product_codes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($product_codes) 0 0 0
4636 0 $running_instance->product_codes($product_codes);
4637 }
4638
4639 0 push @$running_instances, $running_instance;
4640 }
4641
4642 my $reservation = Net::Amazon::EC2::ReservationInfo->new(
4643 reservation_id => $xml->{reservationId},
4644 owner_id => $xml->{ownerId},
4645 0 group_set => $group_sets,
4646 instances_set => $running_instances,
4647 );
4648
4649 0 return $reservation;
4650 }
4651 }
4652  
4653 =head2 start_instances(%params)
4654  
4655 Starts an instance that uses an Amazon EBS volume as its root device.
4656  
4657 =over
4658  
4659 =item InstanceId (required)
4660  
4661 Either a scalar or an array ref can be passed in (containing instance ids to be started).
4662  
4663 =back
4664  
4665 Returns an array ref of Net::Amazon::EC2::InstanceStateChange objects.
4666  
4667 =cut
4668  
4669 0 ▶sub start_instances {
Subroutine start_instances: not called CC=5 SCAR=34.0
Pod documented
4670 0 my $self = shift;
4671 0 my %args = validate( @_, {
4672 InstanceId => { type => SCALAR | ARRAYREF },
4673 });
4674
4675 # If we have a array ref of instances lets split them out into their InstanceId.n format
4676 0 ▶ if (ref ($args{InstanceId}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"InstanceId"} eq "ARRAY") 0 0 0
4677 0 my $instance_ids = delete $args{InstanceId};
4678 0 _split_into_args('InstanceId.%s',\%args,$instance_ids);
4679 }
4680
4681 0 my $xml = $self->_sign(Action => 'StartInstances', %args);
4682 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
4683 0 return $self->_parse_errors($xml);
4684 }
4685 else {
4686 0 my $started_instances;
4687
4688 0 foreach my $inst (@{$xml->{instancesSet}{item}}) {
4689 my $previous_state = Net::Amazon::EC2::InstanceState->new(
4690 code => $inst->{previousState}{code},
4691 name => $inst->{previousState}{name},
4692 0 );
4693
4694 my $current_state = Net::Amazon::EC2::InstanceState->new(
4695 code => $inst->{currentState}{code},
4696 name => $inst->{currentState}{name},
4697 0 );
4698  
4699 my $started_instance = Net::Amazon::EC2::InstanceStateChange->new(
4700 instance_id => $inst->{instanceId},
4701 0 previous_state => $previous_state,
4702 current_state => $current_state,
4703 );
4704
4705 0 push @$started_instances, $started_instance;
4706 }
4707
4708 0 return $started_instances;
4709 }
4710 }
4711  
4712 =head2 stop_instances(%params)
4713  
4714 Stops an instance that uses an Amazon EBS volume as its root device.
4715  
4716 =over
4717  
4718 =item InstanceId (required)
4719  
4720 Either a scalar or an array ref can be passed in (containing instance ids to be stopped).
4721  
4722 =item Force (optional)
4723  
4724 If set to true, forces the instance to stop. The instance will not have an opportunity to
4725 flush file system caches nor file system meta data. If you use this option, you must perform file
4726 system check and repair procedures. This option is not recommended for Windows instances.
4727  
4728 The default is false.
4729  
4730 =back
4731  
4732 Returns an array ref of Net::Amazon::EC2::InstanceStateChange objects.
4733  
4734 =cut
4735  
4736 0 ▶sub stop_instances {
Subroutine stop_instances: not called CC=5 SCAR=34.0
Pod documented
4737 0 my $self = shift;
4738 0 my %args = validate( @_, {
4739 InstanceId => { type => SCALAR | ARRAYREF },
4740 Force => { type => SCALAR, optional => 1 },
4741 });
4742
4743 # If we have a array ref of instances lets split them out into their InstanceId.n format
4744 0 ▶ if (ref ($args{InstanceId}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"InstanceId"} eq "ARRAY") 0 0 0
4745 0 my $instance_ids = delete $args{InstanceId};
4746 0 _split_into_args('InstanceId.%s',\%args,$instance_ids);
4747 }
4748
4749 0 my $xml = $self->_sign(Action => 'StopInstances', %args);
4750 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
4751 0 return $self->_parse_errors($xml);
4752 }
4753 else {
4754 0 my $stopped_instances;
4755
4756 0 foreach my $inst (@{$xml->{instancesSet}{item}}) {
4757 my $previous_state = Net::Amazon::EC2::InstanceState->new(
4758 code => $inst->{previousState}{code},
4759 name => $inst->{previousState}{name},
4760 0 );
4761
4762 my $current_state = Net::Amazon::EC2::InstanceState->new(
4763 code => $inst->{currentState}{code},
4764 name => $inst->{currentState}{name},
4765 0 );
4766  
4767 my $stopped_instance = Net::Amazon::EC2::InstanceStateChange->new(
4768 instance_id => $inst->{instanceId},
4769 0 previous_state => $previous_state,
4770 current_state => $current_state,
4771 );
4772
4773 0 push @$stopped_instances, $stopped_instance;
4774 }
4775
4776 0 return $stopped_instances;
4777 }
4778 }
4779  
4780 =head2 terminate_instances(%params)
4781  
4782 This method shuts down instance(s) passed into it. It takes the following parameter:
4783  
4784 =over
4785  
4786 =item InstanceId (required)
4787  
4788 Either a scalar or an array ref can be passed in (containing instance ids)
4789  
4790 =back
4791  
4792 Returns an array ref of Net::Amazon::EC2::InstanceStateChange objects.
4793  
4794 =cut
4795  
4796 0 ▶sub terminate_instances {
Subroutine terminate_instances: not called CC=5 SCAR=34.0
Pod documented
4797 0 my $self = shift;
4798 0 my %args = validate( @_, {
4799 InstanceId => { type => SCALAR | ARRAYREF },
4800 });
4801
4802 # If we have a array ref of instances lets split them out into their InstanceId.n format
4803 0 ▶ if (ref ($args{InstanceId}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"InstanceId"} eq "ARRAY") 0 0 0
4804 0 my $instance_ids = delete $args{InstanceId};
4805 0 _split_into_args('InstanceId.%s',\%args,$instance_ids);
4806 }
4807
4808 0 my $xml = $self->_sign(Action => 'TerminateInstances', %args);
4809 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
4810 0 return $self->_parse_errors($xml);
4811 }
4812 else {
4813 0 my $terminated_instances;
4814
4815 0 foreach my $inst (@{$xml->{instancesSet}{item}}) {
4816 my $previous_state = Net::Amazon::EC2::InstanceState->new(
4817 code => $inst->{previousState}{code},
4818 name => $inst->{previousState}{name},
4819 0 );
4820
4821 my $current_state = Net::Amazon::EC2::InstanceState->new(
4822 code => $inst->{currentState}{code},
4823 name => $inst->{currentState}{name},
4824 0 );
4825  
4826 # Note, this is a bit of a backwards incompatible change in so much as I am changing
4827 # return class for this. I hate to do it but I need to be consistent with this
4828 # now being a instance stage change object. This used to be a
4829 # Net::Amazon::EC2::TerminateInstancesResponse object.
4830 my $terminated_instance = Net::Amazon::EC2::InstanceStateChange->new(
4831 instance_id => $inst->{instanceId},
4832 0 previous_state => $previous_state,
4833 current_state => $current_state,
4834 );
4835
4836 0 push @$terminated_instances, $terminated_instance;
4837 }
4838
4839 0 return $terminated_instances;
4840 }
4841 }
4842  
4843 =head2 unmonitor_instances(%params)
4844  
4845 Disables monitoring for a running instance. For more information, refer to the Amazon CloudWatch Developer Guide.
4846  
4847 =over
4848  
4849 =item InstanceId (required)
4850  
4851 The instance id(s) to monitor. Can be a scalar or an array ref
4852  
4853 =back
4854  
4855 Returns an array ref of Net::Amazon::EC2::MonitoredInstance objects
4856  
4857 =cut
4858  
4859 0 ▶sub unmonitor_instances {
Subroutine unmonitor_instances: not called CC=5 SCAR=34.0
Pod documented
4860 0 my $self = shift;
4861 0 my %args = validate( @_, {
4862 InstanceId => { type => ARRAYREF | SCALAR, optional => 1 },
4863 });
4864  
4865 # If we have a array ref of instances lets split them out into their InstanceId.n format
4866 0 ▶ if (ref ($args{InstanceId}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"InstanceId"} eq "ARRAY") 0 0 0
4867 0 my $instance_ids = delete $args{InstanceId};
4868 0 _split_into_args('InstanceId.%s',\%args,$instance_ids);
4869 }
4870
4871 0 my $xml = $self->_sign(Action => 'UnmonitorInstances', %args);
4872
4873 0 ▶ if ( grep { defined && length } $xml->{Errors} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_ and length $_;} $xml->{'Errors'}) { } 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
4874 0 return $self->_parse_errors($xml);
4875 }
4876 else {
4877 0 my $monitored_instances;
4878  
4879 0 foreach my $monitored_instance_item (@{$xml->{instancesSet}{item}}) {
4880 my $monitored_instance = Net::Amazon::EC2::ReservedInstance->new(
4881 instance_id => $monitored_instance_item->{instanceId},
4882 state => $monitored_instance_item->{monitoring}{state},
4883 0 );
4884
4885 0 push @$monitored_instances, $monitored_instance;
4886 }
4887
4888 0 return $monitored_instances;
4889 }
4890 }
4891  
4892 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4893 1 1;
4894  
4895 __END__
↑ Summary EC2/RunningInstances.pm »