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

filter: Statementstmt 0.0% 0 / 22 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 42 CC 4 SCAR 14.8
CC
4
Cov
0%
associate
6.0
disassociate
6.0
refresh
6.0
CRAP 4.4
1 package VM::EC2::ElasticAddress;
2  
3 =head1 NAME
4  
5 VM::EC2::ElasticAddress - Object describing an Amazon EC2 Elastic Address
6  
7 =head1 SYNOPSIS
8  
9 use VM::EC2;
10  
11 $ec2 = VM::EC2->new(...);
12 $addr = $ec2->allocate_address;
13  
14 $ip = $addr->publicIp;
15 $domain = $addr->domain;
16 $allId = $addr->allocationId;
17  
18 =head1 DESCRIPTION
19  
20 This object represents an Amazon EC2 elastic address and is returned by
21 by VM::EC2->allocate_address().
22  
23 =head1 METHODS
24  
25 These object methods are supported:
26  
27 publicIp -- Public IP of the address
28 domain -- Type of address, either "standard" or "vpc"
29 allocationId -- For VPC addresses only, an allocation ID
30 instanceId -- If the address is associated with an instance, the
31 ID of that instance.
32 associationId -- If the address is a VPC elastic IP, and associated
33 with an instance, then the ID of the association.
34  
35 In addition, the following convenience methods are provided:
36  
37 =head2 $result = $addr->associate($instance_id)
38  
39 Associate this address with the given instance ID or
40 VM::EC2::Instance object. If successful, the result code will be
41 true for an ordinary EC2 Elastic IP,or equal to the associationId for
42 a VPC Elastic IP address.
43  
44 =head2 $result = $addr->disassociate()
45  
46 Disassociate this address with any instance it is already associated
47 with. If successful, this method will return true.
48  
49 =head2 $addr->refresh()
50  
51 This is an internal function called after associate() and
52 disassociate(), and is used to refresh the address object's contents.
53  
54 =head1 STRING OVERLOADING
55  
56 When used in a string context, this object will interpolate the
57 publicIp.
58  
59 =head1 SEE ALSO
60  
61 L<VM::EC2>
62 L<VM::EC2::Generic>
63 L<VM::EC2::Instance>
64  
65 =head1 AUTHOR
66  
67 Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>.
68  
69 Copyright (c) 2011 Ontario Institute for Cancer Research
70  
71 This package and its accompanying libraries is free software; you can
72 redistribute it and/or modify it under the terms of the GPL (either
73 version 1, or at your option, any later version) or the Artistic
74 License 2.0. Refer to LICENSE for the full license text. In addition,
75 please see DISCLAIMER.txt for disclaimers of warranty.
76  
77 =cut
78  
79 use strict;
80 use base 'VM::EC2::Generic';
81  
82 sub primary_id {shift->publicIp}
83  
84 sub valid_fields {
85 my $self = shift;
86 return qw(publicIp domain allocationId instanceId associationId);
87 }
88  
89 sub associate {
90 my $self = shift;
91 my $instance = shift or die "Usage: \$elastic_addr->associate(\$instance)";
92 my $result = $self->aws->associate_address($self,$instance);
93 $self->refresh if $result;
94 $result;
95 }
96  
97 sub disassociate {
98 my $self = shift;
99 my $result = $self->aws->disassociate_address($self);
100 $self->refresh if $result;
101 $result;
102 }
103  
104 sub refresh {
105 my $self = shift;
106 my $i = $self->aws->describe_addresses($self);
107 %$self = %$i if $i;
108 return defined $i;
109 }
110  
111 1;