Skip to content

Commit

Permalink
Support multiple DBSecurityGroups for DBInstance. Fixes #1086.
Browse files Browse the repository at this point in the history
  • Loading branch information
garnaat committed Oct 29, 2012
1 parent 2a5df0b commit 2bdebc4
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions boto/rds/dbinstance.py
Expand Up @@ -21,6 +21,7 @@

from boto.rds.dbsecuritygroup import DBSecurityGroup
from boto.rds.parametergroup import ParameterGroup
from boto.resultset import ResultSet


class DBInstance(object):
Expand All @@ -43,9 +44,9 @@ class DBInstance(object):
capacity class of the DB Instance.
:ivar master_username: The username that is set as master username
at creation time.
:ivar parameter_group: Provides the list of DB Parameter Groups
:ivar parameter_groups: Provides the list of DB Parameter Groups
applied to this DB Instance.
:ivar security_group: Provides List of DB Security Group elements
:ivar security_groups: Provides List of DB Security Group elements
containing only DBSecurityGroup.Name and DBSecurityGroup.Status
subelements.
:ivar availability_zone: Specifies the name of the Availability Zone
Expand Down Expand Up @@ -78,8 +79,8 @@ def __init__(self, connection=None, id=None):
self.endpoint = None
self.instance_class = None
self.master_username = None
self.parameter_group = None
self.security_group = None
self.parameter_groups = []
self.security_groups = []
self.availability_zone = None
self.backup_retention_period = None
self.preferred_backup_window = None
Expand All @@ -98,12 +99,14 @@ def __repr__(self):
def startElement(self, name, attrs, connection):
if name == 'Endpoint':
self._in_endpoint = True
elif name == 'DBParameterGroup':
self.parameter_group = ParameterGroup(self.connection)
return self.parameter_group
elif name == 'DBSecurityGroup':
self.security_group = DBSecurityGroup(self.connection)
return self.security_group
elif name == 'DBParameterGroups':
self.parameter_groups = ResultSet([('DBParameterGroup',
ParameterGroup)])
return self.parameter_groups
elif name == 'DBSecurityGroups':
self.security_groups = ResultSet([('DBSecurityGroup',
DBSecurityGroup)])
return self.security_groups
elif name == 'PendingModifiedValues':
self.pending_modified_values = PendingModifiedValues()
return self.pending_modified_values
Expand Down Expand Up @@ -153,6 +156,28 @@ def endElement(self, name, value, connection):
else:
setattr(self, name, value)

@property
def security_group(self):
"""
Provide backward compatibility for previous security_group
attribute.
"""
if len(self.security_groups) > 0:
return self.security_groups[-1]
else:
return None

@property
def parameter_group(self):
"""
Provide backward compatibility for previous parameter_group
attribute.
"""
if len(self.parameter_groups) > 0:
return self.parameter_groups[-1]
else:
return None

def snapshot(self, snapshot_id):
"""
Create a new DB snapshot of this DBInstance.
Expand Down

0 comments on commit 2bdebc4

Please sign in to comment.