| 1 | package VM::EC2::DB::Instance; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | VM::EC2::DB::Instance - Object describing an Amazon RDS instance | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | use VM::EC2; | ||
| 10 | |||
| 11 | $ec2 = VM::EC2->new(...); | ||
| 12 | $db = $ec2->describe_db_instances('mydbinstance'); | ||
| 13 | |||
| 14 | $auto_upgrade = $db->AutoMinorVersionUpgrade; | ||
| 15 | $az = $db->AvailabilityZone; | ||
| 16 | $bkup_days = $db->BackupRetentionPeriod; | ||
| 17 | $charset = $db->CharacterSetName; | ||
| 18 | $class = $db->DBInstanceClass; | ||
| 19 | $status = $db->DBInstanceStatus; | ||
| 20 | $db_name = $db->DBName; | ||
| 21 | @parm_grps = $db->DBParameterGroups; | ||
| 22 | @sec_grps = $db->DBSecurityGroups; | ||
| 23 | @subnet_grps = $db->DBSecurityGroups; | ||
| 24 | $endpt = $db->Endpoint; | ||
| 25 | $engine = $db->Engine; | ||
| 26 | $version = $db->EngineVersion; | ||
| 27 | $create_time = $db->InstanceCreateTime; | ||
| 28 | $iops = $db->Iops; | ||
| 29 | $latest_restorable_time = $db->LatestRestorableTime; | ||
| 30 | $license = $db->LicenseModel; | ||
| 31 | $user = $db->MasterUsername; | ||
| 32 | $multi_az = $db->MultiAZ; | ||
| 33 | @option_grp_memberships = $db->OptionGroupMemberships; | ||
| 34 | @pending_vals = $db->PendingModifiedValues; | ||
| 35 | $backup_window = $db->PreferredBackupWindow; | ||
| 36 | $maint_window = $db->PreferredMaintenanceWindow; | ||
| 37 | $publicly_accessible = $db->PubliclyAccessible; | ||
| 38 | @ids = $db->ReadReplicaDBInstanceIdentifiers; | ||
| 39 | $id = $db->ReadReplicaSourceDBInstanceIdentifier; | ||
| 40 | $sec_zone = $db->SecondaryAvailabilityZone; | ||
| 41 | @vpc_grps = $db->VpcSecurityGroups; | ||
| 42 | |||
| 43 | =head1 DESCRIPTION | ||
| 44 | |||
| 45 | This object represents an Amazon RDS DB instance, and is returned by | ||
| 46 | VM::EC2->describe_db_instances(). In addition to methods to query the | ||
| 47 | instance's attributes, there are methods that allow you to manage the | ||
| 48 | instance's lifecycle, including start, stopping, and terminating it. | ||
| 49 | |||
| 50 | =head1 METHODS | ||
| 51 | |||
| 52 | =head1 LIFECYCLE METHODS | ||
| 53 | |||
| 54 | There is no concept of 'stopping' an RDS instance other than deletion. | ||
| 55 | In this sense an RDS instance is much different than an EC2 instance. | ||
| 56 | Rebooting is possible and the only means to apply some changes to the | ||
| 57 | database. | ||
| 58 | |||
| 59 | =head1 STRING OVERLOADING | ||
| 60 | |||
| 61 | When used in a string context, this object will interpolate the | ||
| 62 | DBInstanceIdentifier. | ||
| 63 | |||
| 64 | =head1 SEE ALSO | ||
| 65 | |||
| 66 | L<VM::EC2> | ||
| 67 | L<VM::EC2::Generic> | ||
| 68 | |||
| 69 | =head1 AUTHOR | ||
| 70 | |||
| 71 | Lance Kinley E<lt>lkinley@loyaltymethods.comE<gt>. | ||
| 72 | |||
| 73 | Copyright (c) 2013 Loyalty Methods, Inc. | ||
| 74 | |||
| 75 | This package and its accompanying libraries is free software; you can | ||
| 76 | redistribute it and/or modify it under the terms of the GPL (either | ||
| 77 | version 1, or at your option, any later version) or the Artistic | ||
| 78 | License 2.0. Refer to LICENSE for the full license text. In addition, | ||
| 79 | please see DISCLAIMER.txt for disclaimers of warranty. | ||
| 80 | |||
| 81 | =cut | ||
| 82 | |||
| 83 | use strict; | ||
| 84 | use base 'VM::EC2::Generic'; | ||
| 85 | use Carp 'croak'; | ||
| 86 | use VM::EC2::DB::Parameter::Group::Status; | ||
| 87 | use VM::EC2::DB::SecurityGroup::Membership; | ||
| 88 | use VM::EC2::DB::Endpoint; | ||
| 89 | use VM::EC2::DB::PendingModifiedValues; | ||
| 90 | |||
| 91 | use overload '""' => sub { shift->DBInstanceIdentifier }, | ||
| 92 | fallback => 1; | ||
| 93 | |||
| 94 | sub valid_fields { | ||
| 95 | my $self = shift; | ||
| 96 | return qw(AllocatedStorage | ||
| 97 | AutoMinorVersionUpgrade | ||
| 98 | AvailabilityZone | ||
| 99 | BackupRetentionPeriod | ||
| 100 | CharacterSetName | ||
| 101 | DBInstanceClass | ||
| 102 | DBInstanceIdentifier | ||
| 103 | DBInstanceStatus | ||
| 104 | DBName | ||
| 105 | DBParameterGroups | ||
| 106 | DBSecurityGroups | ||
| 107 | DBSubnetGroup | ||
| 108 | Endpoint | ||
| 109 | Engine | ||
| 110 | EngineVersion | ||
| 111 | InstanceCreateTime | ||
| 112 | Iops | ||
| 113 | LatestRestorableTime | ||
| 114 | LicenseModel | ||
| 115 | MasterUsername | ||
| 116 | MultiAZ | ||
| 117 | OptionGroupMemberships | ||
| 118 | PendingModifiedValues | ||
| 119 | PreferredBackupWindow | ||
| 120 | PreferredMaintenanceWindow | ||
| 121 | PubliclyAccessible | ||
| 122 | ReadReplicaDBInstanceIdentifiers | ||
| 123 | ReadReplicaSourceDBInstanceIdentifier | ||
| 124 | SecondaryAvailabilityZone | ||
| 125 | VpcSecurityGroups | ||
| 126 | ); | ||
| 127 | } | ||
| 128 | |||
| 129 | sub AutoMinorVersionUpgrade { | ||
| 130 | my $self = shift; | ||
| 131 | my $auto = $self->SUPER::AutoMinorVersionUpgrade; | ||
| 132 | return $auto eq 'true'; | ||
| 133 | } | ||
| 134 | |||
| 135 | sub MultiAZ { | ||
| 136 | my $self = shift; | ||
| 137 | my $multi = $self->SUPER::MultiAZ; | ||
| 138 | return $multi eq 'true'; | ||
| 139 | } | ||
| 140 | |||
| 141 | sub DBParameterGroups { | ||
| 142 | my $self = shift; | ||
| 143 | my $groups = $self->SUPER::DBParameterGroups; | ||
| 144 | return unless $groups; | ||
| 145 | $groups = $groups->{DBParameterGroup}; | ||
| 146 | return ref $groups eq 'HASH' ? | ||
| 147 | (VM::EC2::DB::Parameter::Group::Status->new($groups,$self->aws)) : | ||
| 148 | map { VM::EC2::DB::Parameter::Group::Status->new($_,$self->aws) } @$groups; | ||
| 149 | } | ||
| 150 | |||
| 151 | sub DBSecurityGroups { | ||
| 152 | my $self = shift; | ||
| 153 | my $groups = $self->SUPER::DBSecurityGroups; | ||
| 154 | return unless $groups; | ||
| 155 | $groups = $groups->{DBSecurityGroup}; | ||
| 156 | return ref $groups eq 'HASH' ? | ||
| 157 | (VM::EC2::DB::SecurityGroup::Membership->new($groups,$self->aws)) : | ||
| 158 | map { VM::EC2::DB::SecurityGroup::Membership->new($_,$self->aws) } @$groups; | ||
| 159 | } | ||
| 160 | |||
| 161 | sub DBSubnetGroup { | ||
| 162 | my $self = shift; | ||
| 163 | my $group = $self->SUPER::DBSubnetGroup; | ||
| 164 | return unless $group; | ||
| 165 | return VM::EC2::DB::Subnet::Group->new($group->{DBSubnetGroup},$self->aws); | ||
| 166 | } | ||
| 167 | |||
| 168 | sub Endpoint { | ||
| 169 | my $self = shift; | ||
| 170 | my $endpoint = $self->SUPER::Endpoint; | ||
| 171 | return VM::EC2::DB::EndPoint->new($endpoint,$self->aws); | ||
| 172 | } | ||
| 173 | |||
| 174 | sub OptionGroupMemberships { | ||
| 175 | my $self = shift; | ||
| 176 | my $groups = $self->SUPER::OptionGroupMemberships; | ||
| 177 | return unless $groups; | ||
| 178 | $groups = $groups->{OptionGroupMembership}; | ||
| 179 | return ref $groups eq 'HASH' ? | ||
| 180 | (VM::EC2::DB::Option::Group::Membership->new($groups,$self->aws)) : | ||
| 181 | map { VM::EC2::DB::Option::Group::Membership->new($_,$self->aws) } @$groups; | ||
| 182 | } | ||
| 183 | |||
| 184 | sub PendingModifiedValues { | ||
| 185 | my $self = shift; | ||
| 186 | my $values = $self->SUPER::PendingModifiedValues; | ||
| 187 | return VM::EC2::DB::PendingModifiedValues->new($values,$self->aws); | ||
| 188 | } | ||
| 189 | |||
| 190 | sub PubliclyAccessible { | ||
| 191 | my $self = shift; | ||
| 192 | my $public = $self->SUPER::PubliclyAccessible; | ||
| 193 | return $public eq 'true'; | ||
| 194 | } | ||
| 195 | |||
| 196 | sub VpcSecurityGroups { | ||
| 197 | my $self = shift; | ||
| 198 | my $groups = $self->SUPER::VpcSecurityGroups; | ||
| 199 | return unless $groups; | ||
| 200 | $groups = $groups->{VpcSecurityGroup}; | ||
| 201 | return ref $groups eq 'HASH' ? | ||
| 202 | (VM::EC2::DB::VpcSecurityGroup::Membership->new($groups,$self->aws)) : | ||
| 203 | map { VM::EC2::DB::VpcSecurityGroup::Membership->new($_,$self->aws) } @$groups; | ||
| 204 | } | ||
| 205 | |||
| 206 | 1; |