| 1 | package VM::EC2::Instance::StatusItem; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | VM::EC2::Instance::StatusItem - Object describing a instance status event | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | @status_items = $ec2->describe_instance_status(); | ||
| 10 | for my $i (@status_items) { | ||
| 11 | print $i->instance_id, | ||
| 12 | ': instance check=',$i->instance_status, | ||
| 13 | ', system check=',$i->system_status,"\n"; | ||
| 14 | if (my $e = $i->events) { | ||
| 15 | print $i->instance_id,' event = ',$e; | ||
| 16 | } | ||
| 17 | } | ||
| 18 | |||
| 19 | =head1 DESCRIPTION | ||
| 20 | |||
| 21 | This object represents an instance status returned by | ||
| 22 | $ec2->describe_instance_status(). | ||
| 23 | |||
| 24 | =head1 METHODS | ||
| 25 | |||
| 26 | These object methods are supported: | ||
| 27 | |||
| 28 | instanceId -- The ID of the affected instance. | ||
| 29 | instance -- The VM::EC2::Instance object | ||
| 30 | availabilityZone -- The availability zone of this instance. | ||
| 31 | events -- A list of VM::EC2::Instance::Status::Event objects | ||
| 32 | representing a scheduled maintenance events on this | ||
| 33 | instance (see note). | ||
| 34 | instanceState -- The state of this instance (e.g. "running") | ||
| 35 | systemStatus -- A VM::EC2::Instance::Status object indicating the | ||
| 36 | status of the system check. | ||
| 37 | instanceStatus -- A VM::EC2::Instance::Status object indicating the | ||
| 38 | status of the instance availability check. | ||
| 39 | |||
| 40 | NOTE: There is an inconsistency in the AWS documentation for this data | ||
| 41 | type. The events field is documented as being a list, but the examples | ||
| 42 | shown return a single object. At release time, I was unable to verify | ||
| 43 | which is correct and have written the code such that it will always | ||
| 44 | return a list, which may be single elementin length. | ||
| 45 | |||
| 46 | In a string context, this object will interpolate as: | ||
| 47 | |||
| 48 | "$instanceId: XX/2 tests passed" | ||
| 49 | |||
| 50 | where XX is the number of checks that passed. | ||
| 51 | |||
| 52 | In the case of an instance that is not running, the interpolation will be: | ||
| 53 | |||
| 54 | "$instanceId: $state" | ||
| 55 | |||
| 56 | Where $state is the state of the instance (e.g. "stopped"). | ||
| 57 | |||
| 58 | =head1 SEE ALSO | ||
| 59 | |||
| 60 | L<VM::EC2> | ||
| 61 | L<VM::EC2::Generic> | ||
| 62 | L<VM::EC2::Instance> | ||
| 63 | L<VM::EC2::Tag> | ||
| 64 | |||
| 65 | =head1 AUTHOR | ||
| 66 | |||
| 67 | Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>. | ||
| 68 | |||
| 69 | Copyright (c) 2012 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 | use VM::EC2::Instance::State; | ||
| 82 | use VM::EC2::Instance::Status; | ||
| 83 | use VM::EC2::Instance::Status::Event; | ||
| 84 | |||
| 85 | sub valid_fields { | ||
| 86 | my $self = shift; | ||
| 87 | return qw(instanceId availabilityZone eventsSet instanceState systemStatus instanceStatus); | ||
| 88 | } | ||
| 89 | |||
| 90 | sub events { | ||
| 91 | my $self = shift; | ||
| 92 | my $e = $self->eventsSet or return; | ||
| 93 | if (ref $e && $e->{item}) { | ||
| 94 | return map {VM::EC2::Instance::Status::Event->new($_,$self->ec2)} @{$e->{item}}; | ||
| 95 | } else { | ||
| 96 | return VM::EC2::Instance::Status::Event->new($e,$self->ec2); | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | sub instance { | ||
| 101 | my $self = shift; | ||
| 102 | return $self->ec2->describe_instances($self->instanceId); | ||
| 103 | } | ||
| 104 | |||
| 105 | sub instanceState { | ||
| 106 | my $self = shift; | ||
| 107 | my $s = $self->SUPER::instanceState or return; | ||
| 108 | return VM::EC2::Instance::State->new($s,$self->ec2); | ||
| 109 | } | ||
| 110 | |||
| 111 | sub systemStatus { | ||
| 112 | my $self = shift; | ||
| 113 | my $s = $self->SUPER::systemStatus or return; | ||
| 114 | return VM::EC2::Instance::Status->new($s,$self->ec2); | ||
| 115 | } | ||
| 116 | |||
| 117 | sub instanceStatus { | ||
| 118 | my $self = shift; | ||
| 119 | my $s = $self->SUPER::systemStatus or return; | ||
| 120 | return VM::EC2::Instance::Status->new($s,$self->ec2); | ||
| 121 | } | ||
| 122 | |||
| 123 | sub short_name { | ||
| 124 | my $self = shift; | ||
| 125 | my $instance = $self->instanceId; | ||
| 126 | my $passed = grep {$_ eq 'ok'} ($self->instanceStatus,$self->systemStatus); | ||
| 127 | my $state = $self->instance_state; | ||
| 128 | return $state eq 'running' ? "$instance: $passed/2 checks passed" : "$instance: $state"; | ||
| 129 | } | ||
| 130 | |||
| 131 | |||
| 132 | 1; | ||
| 133 |