| 1 | package VM::EC2::Spot::InstanceRequest; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | VM::EC2::Spot::InstanceRequest - Object describing an Amazon EC2 spot instance request | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | See L<VM::EC2/SPOT INSTANCES>. | ||
| 10 | |||
| 11 | =head1 DESCRIPTION | ||
| 12 | |||
| 13 | This object represents an Amazon EC2 spot instance request, which is | ||
| 14 | returned by VM::EC2->request_spot_instances() and | ||
| 15 | VM::EC2->describe_spot_instance_requests(). | ||
| 16 | |||
| 17 | =head1 METHODS | ||
| 18 | |||
| 19 | These object methods are supported: | ||
| 20 | |||
| 21 | spotInstanceRequestId -- ID of this spot instance request | ||
| 22 | |||
| 23 | spotPrice -- The maximum hourly price for any spot | ||
| 24 | instance launched under this request, | ||
| 25 | in USD. | ||
| 26 | |||
| 27 | type -- The spot instance request type, one of | ||
| 28 | 'one-time' or 'persistent'. | ||
| 29 | |||
| 30 | state -- The state of this request, one of 'open', | ||
| 31 | 'closed', 'fulfilled', 'cancelled' or 'failed'. | ||
| 32 | |||
| 33 | fault -- Fault code for the request, if any, an | ||
| 34 | instance of VM::EC2::Error. | ||
| 35 | |||
| 36 | status -- The status code and status message describing the | ||
| 37 | Spot Instance request. | ||
| 38 | |||
| 39 | validFrom -- Start date and time of the request. | ||
| 40 | |||
| 41 | validUntil -- Date and time that the request expires. | ||
| 42 | |||
| 43 | launchGroup -- Launch group of the instances run under this request. | ||
| 44 | Instances in the same launch group are launched | ||
| 45 | and terminated together. | ||
| 46 | |||
| 47 | launchedAvailabilityZone -- Availability zone of launched instance. | ||
| 48 | |||
| 49 | availabilityZoneGroup -- Availability zone group of the instances | ||
| 50 | run under this request. Instances in the same | ||
| 51 | availability zone group will always be launched | ||
| 52 | into the same availability zone. | ||
| 53 | |||
| 54 | launchSpecification -- Additional information for launching | ||
| 55 | instances, represented as a VM::EC2::Spot::LaunchSpecificaton | ||
| 56 | object. | ||
| 57 | |||
| 58 | instanceId -- The instance ID, if an instance has been launched as a | ||
| 59 | result of this request. | ||
| 60 | |||
| 61 | createTime -- The time and date when the spot instance request was | ||
| 62 | created. | ||
| 63 | |||
| 64 | productDescription -- The product description associated with this spot | ||
| 65 | instance request. | ||
| 66 | |||
| 67 | =head1 Convenience Methods | ||
| 68 | |||
| 69 | This class supports the standard tagging interface. In addition it | ||
| 70 | provides the following convenience method: | ||
| 71 | |||
| 72 | =head2 $instance = $request->instance | ||
| 73 | |||
| 74 | If an instance was launched as a result of this request, the | ||
| 75 | instance() method will return the corresponding VM::EC2::Instance | ||
| 76 | object. | ||
| 77 | |||
| 78 | =head2 $state = $request->current_status | ||
| 79 | |||
| 80 | Refreshes the request information and returns its status as a | ||
| 81 | VM::EC2::Spot::Status. This will string interpolate as the status | ||
| 82 | code, such as "fulfilled". You may also call its object methods to | ||
| 83 | get the time of the last update and full message. | ||
| 84 | |||
| 85 | =head2 $state = $request->current_state | ||
| 86 | |||
| 87 | Refreshes the request information and returns its state, such as "open". | ||
| 88 | |||
| 89 | =head2 $request->refresh | ||
| 90 | |||
| 91 | Refreshes the request information. | ||
| 92 | |||
| 93 | =head1 SEE ALSO | ||
| 94 | |||
| 95 | L<VM::EC2> | ||
| 96 | L<VM::EC2::Generic> | ||
| 97 | L<VM::EC2::Spot::LaunchSpecification> | ||
| 98 | L<VM::EC2::Error> | ||
| 99 | |||
| 100 | =head1 AUTHOR | ||
| 101 | |||
| 102 | Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>. | ||
| 103 | |||
| 104 | Copyright (c) 2011 Ontario Institute for Cancer Research | ||
| 105 | |||
| 106 | This package and its accompanying libraries is free software; you can | ||
| 107 | redistribute it and/or modify it under the terms of the GPL (either | ||
| 108 | version 1, or at your option, any later version) or the Artistic | ||
| 109 | License 2.0. Refer to LICENSE for the full license text. In addition, | ||
| 110 | please see DISCLAIMER.txt for disclaimers of warranty. | ||
| 111 | |||
| 112 | =cut | ||
| 113 | |||
| 114 | use strict; | ||
| 115 | use VM::EC2::Spot::LaunchSpecification; | ||
| 116 | use VM::EC2::Spot::Status; | ||
| 117 | use base 'VM::EC2::Generic'; | ||
| 118 | |||
| 119 | sub valid_fields { | ||
| 120 | my $self = shift; | ||
| 121 | return qw(spotInstanceRequestId spotPrice type state fault status | ||
| 122 | validFrom validUntil launchGroup availabilityZoneGroup | ||
| 123 | launchedAvailabilityZone launchSpecification instanceId | ||
| 124 | createTime productDescription); | ||
| 125 | } | ||
| 126 | |||
| 127 | sub primary_id { | ||
| 128 | shift->spotInstanceRequestId; | ||
| 129 | } | ||
| 130 | |||
| 131 | sub status { | ||
| 132 | my $self = shift; | ||
| 133 | my $status = $self->SUPER::status; | ||
| 134 | return VM::EC2::Spot::Status->new($status,$self->ec2,$self->xmlns,$self->requestId); | ||
| 135 | } | ||
| 136 | |||
| 137 | sub launchSpecification { | ||
| 138 | my $self = shift; | ||
| 139 | my $spec = $self->SUPER::launchSpecification; | ||
| 140 | return VM::EC2::Spot::LaunchSpecification->new($spec,$self->ec2,$self->xmlns,$self->requestId); | ||
| 141 | } | ||
| 142 | |||
| 143 | sub instance { | ||
| 144 | my $self = shift; | ||
| 145 | my $instanceId = $self->instanceId or return; | ||
| 146 | return $self->ec2->describe_instances($instanceId); | ||
| 147 | } | ||
| 148 | |||
| 149 | sub fault { | ||
| 150 | my $self = shift; | ||
| 151 | my $f = $self->SUPER::fault or return; | ||
| 152 | return VM::EC2::Error->new($f,$self->ec2); | ||
| 153 | } | ||
| 154 | |||
| 155 | sub refresh { | ||
| 156 | my $self = shift; | ||
| 157 | local $self->ec2->{raise_error} = 1; | ||
| 158 | my $r = $self->ec2->describe_spot_instance_requests($self->spotInstanceRequestId); | ||
| 159 | %$self = %$r if $r; | ||
| 160 | return defined $r; | ||
| 161 | } | ||
| 162 | |||
| 163 | sub current_status { | ||
| 164 | my $self = shift; | ||
| 165 | $self->refresh; | ||
| 166 | return $self->status; | ||
| 167 | } | ||
| 168 | |||
| 169 | sub current_state { | ||
| 170 | my $self = shift; | ||
| 171 | $self->refresh; | ||
| 172 | return $self->state; | ||
| 173 | } | ||
| 174 | |||
| 175 | 1; |