| 1 | package VM::EC2::DB::Reserved::Instance; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | VM::EC2::DB::Reserved::Instance - An RDS Database Reserved Instance | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | use VM::EC2; | ||
| 10 | |||
| 11 | $ec2 = VM::EC2->new(...); | ||
| 12 | @i = $ec2->describe_reserved_db_instances; | ||
| 13 | print "$_\n" foreach grep { $_->State eq 'active' } @i; | ||
| 14 | |||
| 15 | =head1 DESCRIPTION | ||
| 16 | |||
| 17 | This object represents an RDS Reserved DB Instance. | ||
| 18 | |||
| 19 | =head1 STRING OVERLOADING | ||
| 20 | |||
| 21 | In string context, this object outputs | ||
| 22 | |||
| 23 | =head1 SEE ALSO | ||
| 24 | |||
| 25 | L<VM::EC2> | ||
| 26 | L<VM::EC2::Generic> | ||
| 27 | L<VM::EC2::DB::Instance> | ||
| 28 | |||
| 29 | =head1 AUTHOR | ||
| 30 | |||
| 31 | Lance Kinley E<lt>lkinley@loyaltymethods.comE<gt>. | ||
| 32 | |||
| 33 | Copyright (c) 2013 Loyalty Methods, Inc. | ||
| 34 | |||
| 35 | This package and its accompanying libraries is free software; you can | ||
| 36 | redistribute it and/or modify it under the terms of the GPL (either | ||
| 37 | version 1, or at your option, any later version) or the Artistic | ||
| 38 | License 2.0. Refer to LICENSE for the full license text. In addition, | ||
| 39 | please see DISCLAIMER.txt for disclaimers of warranty. | ||
| 40 | |||
| 41 | =cut | ||
| 42 | |||
| 43 | use strict; | ||
| 44 | use base 'VM::EC2::Generic'; | ||
| 45 | use VM::EC2::DB::Reserved::RecurringCharge; | ||
| 46 | |||
| 47 | use overload '""' => sub { shift->as_string }, | ||
| 48 | fallback => 1; | ||
| 49 | |||
| 50 | sub valid_fields { | ||
| 51 | my $self = shift; | ||
| 52 | return qw( | ||
| 53 | CurrencyCode | ||
| 54 | DBInstanceClass | ||
| 55 | DBInstanceCount | ||
| 56 | Duration | ||
| 57 | FixedPrice | ||
| 58 | MultiAZ | ||
| 59 | OfferingType | ||
| 60 | ProductDescription | ||
| 61 | RecurringCharges | ||
| 62 | ReservedDBInstanceId | ||
| 63 | ReservedDBInstancesOfferingId | ||
| 64 | StartTime | ||
| 65 | State | ||
| 66 | UsagePrice | ||
| 67 | ); | ||
| 68 | } | ||
| 69 | |||
| 70 | sub MultiAZ { | ||
| 71 | my $self = shift; | ||
| 72 | my $maz = $self->SUPER::MultiAZ; | ||
| 73 | return $maz eq 'true'; | ||
| 74 | } | ||
| 75 | |||
| 76 | sub RecurringCharges { | ||
| 77 | my $self = shift; | ||
| 78 | my $rc = $self->SUPER::RecurringCharges; | ||
| 79 | return unless $rc; | ||
| 80 | $rc = $rc->{RecurringCharge}; | ||
| 81 | return ref $rc eq 'HASH' ? | ||
| 82 | (VM::EC2::DB::Reserved::RecurringCharge->new($rc,$self->aws)) : | ||
| 83 | map { VM::EC2::DB::Reserved::RecurringCharge->new($_,$self->aws) } @$rc; | ||
| 84 | } | ||
| 85 | |||
| 86 | sub as_string { | ||
| 87 | my $self = shift; | ||
| 88 | my $delim = shift || ' '; | ||
| 89 | my @fields; | ||
| 90 | push @fields, sprintf('%3i',$self->DBInstanceCount); | ||
| 91 | push @fields, $self->ReservedDBInstanceId, | ||
| 92 | push @fields, sprintf('%25s',$self->StartTime); | ||
| 93 | push @fields, sprintf('%18s',$self->OfferingType); | ||
| 94 | push @fields, sprintf('%4i Days',$self->Duration / 86400); | ||
| 95 | push @fields, sprintf('%13s',$self->DBInstanceClass); | ||
| 96 | push @fields, sprintf('%9s',$self->MultiAZ ? 'Multi AZ' : 'Single AZ'); | ||
| 97 | push @fields, sprintf('%s%8s',$self->CurrencyCode,sprintf('%.2f',$self->FixedPrice)); | ||
| 98 | push @fields, sprintf('%s%6s/Hourly',$self->CurrencyCode,sprintf('%.3f',$self->UsagePrice)); | ||
| 99 | push @fields, $self->RecurringCharges ? sprintf('%s%6s/' . $self->RecurringCharges->frequency,$self->CurrencyCode,sprintf('%.3f',$self->RecurringCharges->amount)) : ' ' x 16; | ||
| 100 | push @fields, $self->ProductDescription; | ||
| 101 | push @fields, $self->ReservedDBInstancesOfferingId; | ||
| 102 | push @fields, sprintf('%15s',$self->State); | ||
| 103 | return join($delim,@fields) | ||
| 104 | } | ||
| 105 | |||
| 106 | 1; |