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

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 69 CC 5 SCAR 19.0
CC
5
Cov
0%
as_string
20.0
ebs
6.0
valid_fields
2.0
CRAP 6.7
1 package VM::EC2::BlockDevice;
2  
3 =head1 NAME
4  
5 VM::EC2::BlockDevice - Object describing how to construct an EC2 block device when launching an image
6  
7 =head1 SYNOPSIS
8  
9 use VM::EC2;
10  
11 $ec2 = VM::EC2->new(...);
12 $image = $ec2->describe_images(-image_id=>'ami-123456');
13 my @devices = $image->blockDeviceMapping;
14 for my $d (@devices) {
15 my $virtual_device = $d->deviceName;
16 my $snapshot_id = $d->snapshotId;
17 my $volume_size = $d->volumeSize;
18 my $delete = $d->deleteOnTermination;
19 }
20  
21 =head1 DESCRIPTION
22  
23 This object represents an Amazon block device associated with an AMI.
24 The information in it is used to create a new volume when the AMI is launched.
25 The object is returned by VM::EC2->describe_images().
26  
27 Please see L<VM::EC2::Generic> for methods shared by all VM::EC2
28 objects.
29  
30 =head1 METHODS
31  
32 These object methods are supported:
33  
34 deviceName -- name of the device, such as /dev/sda1
35 virtualName -- virtual device name, such as "ephemeral0"
36 noDevice -- true if no device associated
37 ebs -- parameters used to automatically set up Amazon EBS
38 volumes when an instance is booted. This returns
39 a VM::EC2::BlockDevice::EBS object.
40  
41 For your convenience, a number of the ebs() object's methods are
42 passed through:
43  
44 snapshotId -- ID of the snapshot used to create this EBS when an
45 instance is launched from this image.
46 volumeSize -- Size of the EBS volume (in gigs).
47 deleteOnTermination -- Whether this EBS will be deleted when the
48 instance terminates.
49 volumeType -- The volume type, one of "standard" or "io1"
50 iops -- The number of I/O operations per second that the volume
51 supports, an integer between 100 and 4000. Only valid for
52 volumes of type "io1".
53  
54 =head1 STRING OVERLOADING
55  
56 When used in a string context, this object will be interpolated as:
57  
58 deviceName=snapshotId:volumeSize:deleteOnTermination:volumeType:iops
59  
60 The :iops portion is only valid when the volumeType is "io1".
61  
62 e.g.
63  
64 /dev/sdg=snap-12345:20:true:standard
65  
66 This happens to be the same syntax used to specify block device
67 mappings in run_instances(). See L<VM::EC2>.
68  
69 =head1 SEE ALSO
70  
71 L<VM::EC2>
72 L<VM::EC2::Generic>
73 L<VM::EC2::BlockDevice>
74 L<VM::EC2::BlockDevice::Attachment>
75 L<VM::EC2::BlockDevice::EBS>
76 L<VM::EC2::Volume>
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 use VM::EC2::BlockDevice::EBS;
95  
96 use overload '""' => sub {shift()->as_string},
97 fallback => 1;
98  
99 sub valid_fields {
100 my $self = shift;
101 return qw(deviceName virtualName ebs);
102 }
103  
104 sub noDevice {
105 my $self = shift;
106 return exists $self->payload->{noDevice};
107 }
108  
109 sub ebs {
110 my $self = shift;
111 my $ebs = $self->SUPER::ebs;
112 return unless $ebs; # some of these devices are ephemeral
113 return $self->{ebs} ||= VM::EC2::BlockDevice::EBS->new($ebs,$self->aws);
114 }
115  
116 sub snapshotId { shift->ebs->snapshotId }
117 sub volumeSize { shift->ebs->volumeSize }
118 sub deleteOnTermination { shift->ebs->deleteOnTermination }
119 sub volumeType { shift->ebs->volumeType }
120 sub iops { shift->ebs->iops }
121  
122 sub as_string {
123 my $self = shift;
124 my $vname = $self->virtualName;
125 return $self->deviceName.'='.$vname if $vname && $vname =~ /^ephemeral/;
126 my $dot = $self->deleteOnTermination ? 'true' : 'false';
127 my $vtype = $self->volumeType;
128 my @type_iops = $vtype eq 'io1' ? ($vtype,$self->iops) : $vtype;
129 return $self->deviceName.'='.
130 join ':',$self->snapshotId,$self->volumeSize,$dot,@type_iops;
131 }
132  
133 1;
134