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