1
# Copyright (c) 2009 Mitch Garnaat http://garnaat.org/
3
# Permission is hereby granted, free of charge, to any person obtaining a
4
# copy of this software and associated documentation files (the
5
# "Software"), to deal in the Software without restriction, including
6
# without limitation the rights to use, copy, modify, merge, publish, dis-
7
# tribute, sublicense, and/or sell copies of the Software, and to permit
8
# persons to whom the Software is furnished to do so, subject to the fol-
11
# The above copyright notice and this permission notice shall be included
12
# in all copies or substantial portions of the Software.
14
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23
Represents an DBSecurityGroup
25
from boto.ec2.securitygroup import SecurityGroup
27
class DBSecurityGroup(object):
29
def __init__(self, connection=None, owner_id=None,
30
name=None, description=None):
31
self.connection = connection
32
self.owner_id = owner_id
34
self.description = description
39
return 'DBSecurityGroup:%s' % self.name
41
def startElement(self, name, attrs, connection):
44
self.ip_ranges.append(cidr)
46
elif name == 'EC2SecurityGroup':
47
ec2_grp = EC2SecurityGroup(self)
48
self.ec2_groups.append(ec2_grp)
53
def endElement(self, name, value, connection):
56
elif name == 'DBSecurityGroupName':
58
elif name == 'DBSecurityGroupDescription':
59
self.description = value
60
elif name == 'IPRanges':
63
setattr(self, name, value)
66
return self.connection.delete_dbsecurity_group(self.name)
68
def authorize(self, cidr_ip=None, ec2_group=None):
70
Add a new rule to this DBSecurity group.
71
You need to pass in either a CIDR block to authorize or
72
and EC2 SecurityGroup.
75
@param cidr_ip: A valid CIDR IP range to authorize
77
@type ec2_group: :class:`boto.ec2.securitygroup.SecurityGroup>`
80
@return: True if successful.
82
if isinstance(ec2_group, SecurityGroup):
83
group_name = ec2_group.name
84
group_owner_id = ec2_group.owner_id
88
return self.connection.authorize_dbsecurity_group(self.name,
93
def revoke(self, cidr_ip=None, ec2_group=None):
95
Revoke access to a CIDR range or EC2 SecurityGroup
96
You need to pass in either a CIDR block to authorize or
97
and EC2 SecurityGroup.
100
@param cidr_ip: A valid CIDR IP range to authorize
102
@type ec2_group: :class:`boto.ec2.securitygroup.SecurityGroup>`
105
@return: True if successful.
107
if isinstance(ec2_group, SecurityGroup):
108
group_name = ec2_group.name
109
group_owner_id = ec2_group.owner_id
112
group_owner_id = None
113
return self.connection.revoke_dbsecurity_group(self.name,
118
class IPRange(object):
120
def __init__(self, parent=None):
126
return 'IPRange:%s' % self.cidr_ip
128
def startElement(self, name, attrs, connection):
131
def endElement(self, name, value, connection):
134
elif name == 'Status':
137
setattr(self, name, value)
139
class EC2SecurityGroup(object):
141
def __init__(self, parent=None):
147
return 'EC2SecurityGroup:%s' % self.name
149
def startElement(self, name, attrs, connection):
152
def endElement(self, name, value, connection):
153
if name == 'EC2SecurityGroupName':
155
elif name == 'EC2SecurityGroupOwnerId':
156
self.owner_id = value
158
setattr(self, name, value)