| 1 | package VM::EC2::ELB::InstanceState; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | VM::EC2::ELB:InstanceState - Object describing the state of an instance | ||
| 6 | attached to a load balancer. It is the result of a DescribeInstanceHealth | ||
| 7 | API call. | ||
| 8 | |||
| 9 | =head1 SYNOPSIS | ||
| 10 | |||
| 11 | use VM::EC2; | ||
| 12 | |||
| 13 | my $ec2 = VM::EC2->new(...); | ||
| 14 | my $lb = $ec2->describe_load_balancers('my-lb'); | ||
| 15 | my @instance_ids = map { $_->InstanceId } $lb->Instances(); | ||
| 16 | my @states = $lb->describe_instance_health(-instances => \@instance_ids); | ||
| 17 | my @down_ids = map { $_->InstanceId } grep { $_->State eq 'OutOfService' } @states; | ||
| 18 | |||
| 19 | =head1 DESCRIPTION | ||
| 20 | |||
| 21 | This object is used to describe the parameters returned by a | ||
| 22 | DescribeInstanceHealth API call. | ||
| 23 | |||
| 24 | =head1 METHODS | ||
| 25 | |||
| 26 | The following object methods are supported: | ||
| 27 | |||
| 28 | InstanceId -- The Instance ID of the instance attached to the load balancer | ||
| 29 | State -- Specifies the current status of the instance | ||
| 30 | ReasonCode -- Provides information about the cause of OutOfService instances. | ||
| 31 | Specifically, it indicates whether the cause is Elastic Load Balancing | ||
| 32 | or the instance behind the load balancer | ||
| 33 | Description -- Description of why the instance is in the current state | ||
| 34 | |||
| 35 | The following convenience methods are supported: | ||
| 36 | |||
| 37 | instance -- Provides an L<VM::EC2::Instance> object | ||
| 38 | |||
| 39 | =head1 STRING OVERLOADING | ||
| 40 | |||
| 41 | When used in a string context, this object will interpolate the | ||
| 42 | instance state. | ||
| 43 | |||
| 44 | =head1 SEE ALSO | ||
| 45 | |||
| 46 | L<VM::EC2> | ||
| 47 | L<VM::EC2::Generic> | ||
| 48 | L<VM::EC2::ELB> | ||
| 49 | |||
| 50 | =head1 AUTHOR | ||
| 51 | |||
| 52 | Lance Kinley E<lt>lkinley@loyaltymethods.comE<gt>. | ||
| 53 | |||
| 54 | Copyright (c) 2012 Loyalty Methods, Inc. | ||
| 55 | |||
| 56 | This package and its accompanying libraries is free software; you can | ||
| 57 | redistribute it and/or modify it under the terms of the GPL (either | ||
| 58 | version 1, or at your option, any later version) or the Artistic | ||
| 59 | License 2.0. Refer to LICENSE for the full license text. In addition, | ||
| 60 | please see DISCLAIMER.txt for disclaimers of warranty. | ||
| 61 | |||
| 62 | =cut | ||
| 63 | |||
| 64 | use strict; | ||
| 65 | use base 'VM::EC2::Generic'; | ||
| 66 | |||
| 67 | sub valid_fields { | ||
| 68 | my $self = shift; | ||
| 69 | return qw(Description InstanceId ReasonCode State); | ||
| 70 | } | ||
| 71 | |||
| 72 | use overload | ||
| 73 | '""' => sub { | ||
| 74 | my $self = shift; | ||
| 75 | return $self->InstanceId . ': ' . | ||
| 76 | $self->State . ' (Reason: ' . | ||
| 77 | $self->ReasonCode . ')'; | ||
| 78 | }, | ||
| 79 | fallback => 1; | ||
| 80 | |||
| 81 | sub instance { | ||
| 82 | my $self = shift; | ||
| 83 | return $self->aws->describe_instances($self->InstanceId); | ||
| 84 | } | ||
| 85 | |||
| 86 | 1; |