| 1 | package VM::EC2::Instance::MonitoringState; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | VM::EC2::MonitoringState - Object describing the monitoring state of an EC2 instance | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | use VM::EC2; | ||
| 10 | |||
| 11 | $ec2 = VM::EC2->new(...); | ||
| 12 | $monitor = $ec2->monitor_instances('i-12345'); | ||
| 13 | $instance = $monitor->instanceId; | ||
| 14 | $monitoring = $monitor->monitoring; | ||
| 15 | |||
| 16 | $monitor->enable; | ||
| 17 | $monitor->disable; | ||
| 18 | |||
| 19 | =head1 DESCRIPTION | ||
| 20 | |||
| 21 | This object represents the monitoring state of an Amazon EC2 instance. | ||
| 22 | |||
| 23 | =head1 METHODS | ||
| 24 | |||
| 25 | These object methods are supported: | ||
| 26 | |||
| 27 | instanceId -- The instance that is being reported | ||
| 28 | monitoring -- The monitoring state: one of "disabled", "enabled", "pending" | ||
| 29 | |||
| 30 | To turn monitoring of an instance on, call: | ||
| 31 | |||
| 32 | $monitor->enable(); | ||
| 33 | |||
| 34 | to unmonitor an instance, call: | ||
| 35 | |||
| 36 | $monitor>disable(); | ||
| 37 | |||
| 38 | It is probably easier to control this using the Instance object's monitoring() method. | ||
| 39 | |||
| 40 | =head1 STRING OVERLOADING | ||
| 41 | |||
| 42 | When used in a string context, this object will interpolate the | ||
| 43 | string "$instanceId monitoring is $monitoring". | ||
| 44 | |||
| 45 | =head1 SEE ALSO | ||
| 46 | |||
| 47 | L<VM::EC2> | ||
| 48 | L<VM::EC2::Generic> | ||
| 49 | L<VM::EC2::Instance> | ||
| 50 | |||
| 51 | =head1 AUTHOR | ||
| 52 | |||
| 53 | Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>. | ||
| 54 | |||
| 55 | Copyright (c) 2011 Ontario Institute for Cancer Research | ||
| 56 | |||
| 57 | This package and its accompanying libraries is free software; you can | ||
| 58 | redistribute it and/or modify it under the terms of the GPL (either | ||
| 59 | version 1, or at your option, any later version) or the Artistic | ||
| 60 | License 2.0. Refer to LICENSE for the full license text. In addition, | ||
| 61 | please see DISCLAIMER.txt for disclaimers of warranty. | ||
| 62 | |||
| 63 | =cut | ||
| 64 | |||
| 65 | use strict; | ||
| 66 | use base 'VM::EC2::Generic'; | ||
| 67 | use overload '""' => sub { | ||
| 68 | my $self = shift; | ||
| 69 | my $instance = $self->instanceId; | ||
| 70 | my $monitoring = $self->monitoring; | ||
| 71 | return "$instance monitoring is $monitoring"; | ||
| 72 | }, | ||
| 73 | fallback => 1; | ||
| 74 | |||
| 75 | sub valid_fields { | ||
| 76 | return qw(instanceId monitoring); | ||
| 77 | } | ||
| 78 | |||
| 79 | sub monitoring { | ||
| 80 | my $self = shift; | ||
| 81 | my $m = $self->SUPER::monitoring; | ||
| 82 | return $m->{state}; | ||
| 83 | } | ||
| 84 | |||
| 85 | sub enable { | ||
| 86 | my $self = shift; | ||
| 87 | return $self->aws->monitor_instances($self->instanceId); | ||
| 88 | } | ||
| 89 | |||
| 90 | sub disable { | ||
| 91 | my $self = shift; | ||
| 92 | return $self->aws->unmonitor_instances($self->instanceId); | ||
| 93 | } | ||
| 94 | |||
| 95 | 1; |