blib/lib/VM/EC2/BlockDevice/Mapping/EBS.pm untested

filter: Statementstmt 0.0% 0 / 16 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 4 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 30 CC 2 SCAR 12.0
CC
2
Cov
0%
volume
6.0
valid_fields
2.0
deleteOnTermination
2.0
CRAP 3.3
1 package VM::EC2::BlockDevice::Mapping::EBS;
2  
3 =head1 NAME
4  
5 VM::EC2::BlockDevice::Mapping::EBS - Object describing an EBS volume that has been mapped onto an Amazon EC2 instance
6  
7 =head1 SYNOPSIS
8  
9 use VM::EC2;
10  
11 my $instance = $ec2->describe_instances(-instance_id=>'i-123456');
12 my @devices = $instance->blockDeviceMapping;
13 for my $d (@devices) {
14 my $ebs = $d->ebs;
15 $volume_id = $ebs->volumeId;
16 $status = $ebs->status;
17 $atime = $ebs->attachmentTime;
18 $delete = $ebs->delete;
19 $volume = $ebs->volume;
20 }
21  
22 =head1 DESCRIPTION
23  
24 This object is used to describe an Amazon EBS volume that is mapped
25 onto an EC2 block device. It is returned by
26 VM::EC2->describe_instances().
27  
28 It is easy to confuse this with VM::EC2::BlockDevice::EBS, which
29 describes the parameters needed to create the EBS volume when an image
30 is launched. This class is instead used to describe an active mapping
31 between an instance's block device and the underlying EBS volume.
32  
33 Because all the methods in this class are passed through to
34 VM::EC2::BlockDeviceMapping, it is somewhat simpler to call
35 them directly on the BlockDeviceMapping object:
36  
37 my $instance = $ec2->describe_instances(-instance_id=>'i-123456');
38 my @devices = $instance->blockDeviceMapping;
39 for my $d (@devices) {
40 $volume_id = $d->volumeId;
41 $status = $d->status;
42 $atime = $d->attachmentTime;
43 $delete = $d->delete;
44 $volume = $d->volume;
45 }
46  
47 =head1 METHODS
48  
49 The following object methods are supported:
50
51 volumeId -- ID of the volume.
52 status -- One of "attaching", "attached", "detaching", "detached"
53 attachTime -- Time this volume was attached
54 deleteOnTermination -- Whether the volume will be deleted when its attached
55 instance is deleted. Note that this returns the perl
56 0/1 booleans rather than "false"/"true" strings.
57  
58 In addition, the following convenience method is supported:
59  
60 =head2 $vol = $ebs->volume
61  
62 This returns the VM::EC2::Volume object that corresponds to this
63 EBS. The volume will provide additional information, such as
64 availabilit zone.
65  
66 =head1 STRING OVERLOADING
67  
68 NONE
69  
70 =head1 SEE ALSO
71  
72 L<VM::EC2>
73 L<VM::EC2::Generic>
74 L<VM::EC2::Snapshot>
75 L<VM::EC2::BlockDevice>
76 L<VM::EC2::BlockDevice::Attachment>
77  
78 =head1 AUTHOR
79  
80 Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>.
81  
82 Copyright (c) 2011 Ontario Institute for Cancer Research
83  
84 This package and its accompanying libraries is free software; you can
85 redistribute it and/or modify it under the terms of the GPL (either
86 version 1, or at your option, any later version) or the Artistic
87 License 2.0. Refer to LICENSE for the full license text. In addition,
88 please see DISCLAIMER.txt for disclaimers of warranty.
89  
90 =cut
91  
92 use strict;
93 use base 'VM::EC2::Generic';
94  
95 sub valid_fields {
96 my $self = shift;
97 return qw(volumeId status attachTime deleteOnTermination);
98 }
99  
100 sub volume {
101 my $self = shift;
102 return $self->{volume} if exists $self->{volume};
103 my @vols = $self->aws->describe_volumes(-volume_id=>$self->volumeId) or return;
104 @vols == 1 or die "describe_volumes(-volume_id=>",$self->volumeId,") returned more than one volume";
105 return $self->{volume} = $vols[0];
106 }
107  
108 sub deleteOnTermination {
109 my $self = shift;
110 my $dot = $self->SUPER::deleteOnTermination;
111 return $dot eq 'true';
112 }
113  
114 1;