| 1 | package VM::EC2::ReservedInstance; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | VM::EC2::ReservedInstance - Object describing an Amazon EC2 reserved instance | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | use VM::EC2; | ||
| 10 | |||
| 11 | $ec2 = VM::EC2->new(...); | ||
| 12 | @offerings = $ec2->describe_reserved_instances(); | ||
| 13 | for my $o (@offerings) { | ||
| 14 | print $o->reservedInstancesId,"\n"; | ||
| 15 | print $o->instanceType,"\n"; | ||
| 16 | print $o->availabilityZone,"\n"; | ||
| 17 | print $o->start,"\n"; | ||
| 18 | print $o->duration,"\n"; | ||
| 19 | print $o->fixedPrice,"\n"; | ||
| 20 | print $o->usagePrice,"\n"; | ||
| 21 | print $o->instanceCount,"\n"; | ||
| 22 | print $o->productDescription,"\n"; | ||
| 23 | print $o->state,"\n"; | ||
| 24 | print $o->instanceTenancy,"\n"; | ||
| 25 | print $o->currencyCode,"\n"; | ||
| 26 | $tags = $o->tags; | ||
| 27 | } | ||
| 28 | =head1 DESCRIPTION | ||
| 29 | |||
| 30 | This object represents an Amazon EC2 reserved instance reservation | ||
| 31 | that you have purchased, as returned by | ||
| 32 | VM::EC2->describe_reserved_instances(). | ||
| 33 | |||
| 34 | =head1 METHODS | ||
| 35 | |||
| 36 | These object methods are supported: | ||
| 37 | |||
| 38 | reservedInstancesId -- ID of this reserved instance contract | ||
| 39 | |||
| 40 | instanceType -- The instance type on which these reserved | ||
| 41 | instance can be used. | ||
| 42 | |||
| 43 | availabilityZone -- The availability zone in which these reserved | ||
| 44 | instances can be used. | ||
| 45 | |||
| 46 | start -- The date and time that this contract was established. | ||
| 47 | |||
| 48 | duration -- The duration of this contract, in seconds. | ||
| 49 | |||
| 50 | fixedPrice -- The purchase price of the reserved instance for the indicated | ||
| 51 | version. | ||
| 52 | |||
| 53 | usagePrice -- The usage price of the reserved instance, per hour. | ||
| 54 | |||
| 55 | instanceCount -- The number of instances that were purchased under this contract. | ||
| 56 | |||
| 57 | productDescription -- The reserved instance description. One of "Linux/UNIX", | ||
| 58 | "Linux/UNIX (Amazon VPC)", "Windows", and "Windows (Amazon VPC)" | ||
| 59 | |||
| 60 | state -- The state of the reserved instance purchase. One of "payment-pending", | ||
| 61 | "active", "payment-failed", and "retired". | ||
| 62 | |||
| 63 | tagSet -- Tags for this reserved instance set. More conveniently accessed via | ||
| 64 | the tags(), add_tags() and delete_tags() methods. | ||
| 65 | |||
| 66 | instanceTenancy -- The tenancy of the reserved instance (VPC only). | ||
| 67 | |||
| 68 | currencyCode -- The currency of the reserved instance offering prices. | ||
| 69 | |||
| 70 | This object supports the various tag manipulation methods described in | ||
| 71 | L<VM::EC2::Generic>. In addition it supports the following methods: | ||
| 72 | |||
| 73 | =head2 $status = $reserved_instance->current_status | ||
| 74 | |||
| 75 | Refreshes the object and returns its state, one of "payment-pending", | ||
| 76 | "active", "payment-failed", and "retired". You can use this to monitor | ||
| 77 | the progress of a purchase. | ||
| 78 | |||
| 79 | =head2 $reserved_instance->refresh | ||
| 80 | |||
| 81 | Calls VM::EC2->describe_reserved_instances() to refresh the object | ||
| 82 | against current information in Amazon. | ||
| 83 | |||
| 84 | =head1 STRING OVERLOADING | ||
| 85 | |||
| 86 | When used in a string context, this object will interpolate the | ||
| 87 | reservedInstancesId. | ||
| 88 | |||
| 89 | =head1 SEE ALSO | ||
| 90 | |||
| 91 | L<VM::EC2> | ||
| 92 | L<VM::EC2::Generic> | ||
| 93 | L<VM::EC2::ReservedInstances::Offering> | ||
| 94 | |||
| 95 | =head1 AUTHOR | ||
| 96 | |||
| 97 | Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>. | ||
| 98 | |||
| 99 | Copyright (c) 2011 Ontario Institute for Cancer Research | ||
| 100 | |||
| 101 | This package and its accompanying libraries is free software; you can | ||
| 102 | redistribute it and/or modify it under the terms of the GPL (either | ||
| 103 | version 1, or at your option, any later version) or the Artistic | ||
| 104 | License 2.0. Refer to LICENSE for the full license text. In addition, | ||
| 105 | please see DISCLAIMER.txt for disclaimers of warranty. | ||
| 106 | |||
| 107 | =cut | ||
| 108 | |||
| 109 | use strict; | ||
| 110 | use base 'VM::EC2::Generic'; | ||
| 111 | |||
| 112 | sub primary_id {shift->reservedInstancesId} | ||
| 113 | |||
| 114 | sub valid_fields { | ||
| 115 | my $self = shift; | ||
| 116 | return qw(reservedInstancesId instanceType availabilityZone | ||
| 117 | start duration fixedPrice usagePrice instanceCount | ||
| 118 | productDescription state tagSet instanceTenancy | ||
| 119 | currencyCode); | ||
| 120 | } | ||
| 121 | |||
| 122 | sub current_status { | ||
| 123 | my $self = shift; | ||
| 124 | $self->refresh; | ||
| 125 | return $self->state; | ||
| 126 | } | ||
| 127 | |||
| 128 | sub current_state { shift->current_status } # alias | ||
| 129 | |||
| 130 | sub refresh { | ||
| 131 | my $self = shift; | ||
| 132 | my $i = $self->ec2->describe_reserved_instances($self->reservedInstancesId); | ||
| 133 | %$self = %$i if $i; | ||
| 134 | return defined $i; | ||
| 135 | } | ||
| 136 | |||
| 137 | |||
| 138 | 1; |