PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/boto-2.5.2/boto/rds/__init__.py

#
Python | 1019 lines | 737 code | 20 blank | 262 comment | 36 complexity | db968f3407b7177dacf6e4eae95f4959 MD5 | raw file
  1. # Copyright (c) 2009 Mitch Garnaat http://garnaat.org/
  2. #
  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-
  9. # lowing conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included
  12. # in all copies or substantial portions of the Software.
  13. #
  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
  20. # IN THE SOFTWARE.
  21. #
  22. import boto.utils
  23. import urllib
  24. from boto.connection import AWSQueryConnection
  25. from boto.rds.dbinstance import DBInstance
  26. from boto.rds.dbsecuritygroup import DBSecurityGroup
  27. from boto.rds.parametergroup import ParameterGroup
  28. from boto.rds.dbsnapshot import DBSnapshot
  29. from boto.rds.event import Event
  30. from boto.rds.regioninfo import RDSRegionInfo
  31. def regions():
  32. """
  33. Get all available regions for the RDS service.
  34. :rtype: list
  35. :return: A list of :class:`boto.rds.regioninfo.RDSRegionInfo`
  36. """
  37. return [RDSRegionInfo(name='us-east-1',
  38. endpoint='rds.us-east-1.amazonaws.com'),
  39. RDSRegionInfo(name='eu-west-1',
  40. endpoint='rds.eu-west-1.amazonaws.com'),
  41. RDSRegionInfo(name='us-west-1',
  42. endpoint='rds.us-west-1.amazonaws.com'),
  43. RDSRegionInfo(name='us-west-2',
  44. endpoint='rds.us-west-2.amazonaws.com'),
  45. RDSRegionInfo(name='sa-east-1',
  46. endpoint='rds.sa-east-1.amazonaws.com'),
  47. RDSRegionInfo(name='ap-northeast-1',
  48. endpoint='rds.ap-northeast-1.amazonaws.com'),
  49. RDSRegionInfo(name='ap-southeast-1',
  50. endpoint='rds.ap-southeast-1.amazonaws.com')
  51. ]
  52. def connect_to_region(region_name, **kw_params):
  53. """
  54. Given a valid region name, return a
  55. :class:`boto.ec2.connection.EC2Connection`.
  56. Any additional parameters after the region_name are passed on to
  57. the connect method of the region object.
  58. :type: str
  59. :param region_name: The name of the region to connect to.
  60. :rtype: :class:`boto.ec2.connection.EC2Connection` or ``None``
  61. :return: A connection to the given region, or None if an invalid region
  62. name is given
  63. """
  64. for region in regions():
  65. if region.name == region_name:
  66. return region.connect(**kw_params)
  67. return None
  68. #boto.set_stream_logger('rds')
  69. class RDSConnection(AWSQueryConnection):
  70. DefaultRegionName = 'us-east-1'
  71. DefaultRegionEndpoint = 'rds.us-east-1.amazonaws.com'
  72. APIVersion = '2011-04-01'
  73. def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
  74. is_secure=True, port=None, proxy=None, proxy_port=None,
  75. proxy_user=None, proxy_pass=None, debug=0,
  76. https_connection_factory=None, region=None, path='/',
  77. security_token=None):
  78. if not region:
  79. region = RDSRegionInfo(self, self.DefaultRegionName,
  80. self.DefaultRegionEndpoint)
  81. self.region = region
  82. AWSQueryConnection.__init__(self, aws_access_key_id,
  83. aws_secret_access_key,
  84. is_secure, port, proxy, proxy_port,
  85. proxy_user, proxy_pass,
  86. self.region.endpoint, debug,
  87. https_connection_factory, path,
  88. security_token)
  89. def _required_auth_capability(self):
  90. return ['rds']
  91. # DB Instance methods
  92. def get_all_dbinstances(self, instance_id=None, max_records=None,
  93. marker=None):
  94. """
  95. Retrieve all the DBInstances in your account.
  96. :type instance_id: str
  97. :param instance_id: DB Instance identifier. If supplied, only
  98. information this instance will be returned.
  99. Otherwise, info about all DB Instances will
  100. be returned.
  101. :type max_records: int
  102. :param max_records: The maximum number of records to be returned.
  103. If more results are available, a MoreToken will
  104. be returned in the response that can be used to
  105. retrieve additional records. Default is 100.
  106. :type marker: str
  107. :param marker: The marker provided by a previous request.
  108. :rtype: list
  109. :return: A list of :class:`boto.rds.dbinstance.DBInstance`
  110. """
  111. params = {}
  112. if instance_id:
  113. params['DBInstanceIdentifier'] = instance_id
  114. if max_records:
  115. params['MaxRecords'] = max_records
  116. if marker:
  117. params['Marker'] = marker
  118. return self.get_list('DescribeDBInstances', params,
  119. [('DBInstance', DBInstance)])
  120. def create_dbinstance(self, id, allocated_storage, instance_class,
  121. master_username, master_password, port=3306,
  122. engine='MySQL5.1', db_name=None, param_group=None,
  123. security_groups=None, availability_zone=None,
  124. preferred_maintenance_window=None,
  125. backup_retention_period=None,
  126. preferred_backup_window=None,
  127. multi_az=False,
  128. engine_version=None,
  129. auto_minor_version_upgrade=True):
  130. """
  131. Create a new DBInstance.
  132. :type id: str
  133. :param id: Unique identifier for the new instance.
  134. Must contain 1-63 alphanumeric characters.
  135. First character must be a letter.
  136. May not end with a hyphen or contain two consecutive hyphens
  137. :type allocated_storage: int
  138. :param allocated_storage: Initially allocated storage size, in GBs.
  139. Valid values are [5-1024]
  140. :type instance_class: str
  141. :param instance_class: The compute and memory capacity of
  142. the DBInstance. Valid values are:
  143. * db.m1.small
  144. * db.m1.large
  145. * db.m1.xlarge
  146. * db.m2.xlarge
  147. * db.m2.2xlarge
  148. * db.m2.4xlarge
  149. :type engine: str
  150. :param engine: Name of database engine. Must be MySQL5.1 for now.
  151. :type master_username: str
  152. :param master_username: Name of master user for the DBInstance.
  153. Must be 1-15 alphanumeric characters, first
  154. must be a letter.
  155. :type master_password: str
  156. :param master_password: Password of master user for the DBInstance.
  157. Must be 4-16 alphanumeric characters.
  158. :type port: int
  159. :param port: Port number on which database accepts connections.
  160. Valid values [1115-65535]. Defaults to 3306.
  161. :type db_name: str
  162. :param db_name: Name of a database to create when the DBInstance
  163. is created. Default is to create no databases.
  164. :type param_group: str
  165. :param param_group: Name of DBParameterGroup to associate with
  166. this DBInstance. If no groups are specified
  167. no parameter groups will be used.
  168. :type security_groups: list of str or list of DBSecurityGroup objects
  169. :param security_groups: List of names of DBSecurityGroup to
  170. authorize on this DBInstance.
  171. :type availability_zone: str
  172. :param availability_zone: Name of the availability zone to place
  173. DBInstance into.
  174. :type preferred_maintenance_window: str
  175. :param preferred_maintenance_window: The weekly time range (in UTC)
  176. during which maintenance can occur.
  177. Default is Sun:05:00-Sun:09:00
  178. :type backup_retention_period: int
  179. :param backup_retention_period: The number of days for which automated
  180. backups are retained. Setting this to
  181. zero disables automated backups.
  182. :type preferred_backup_window: str
  183. :param preferred_backup_window: The daily time range during which
  184. automated backups are created (if
  185. enabled). Must be in h24:mi-hh24:mi
  186. format (UTC).
  187. :type multi_az: bool
  188. :param multi_az: If True, specifies the DB Instance will be
  189. deployed in multiple availability zones.
  190. :type engine_version: str
  191. :param engine_version: Version number of the database engine to use.
  192. :type auto_minor_version_upgrade: bool
  193. :param auto_minor_version_upgrade: Indicates that minor engine
  194. upgrades will be applied
  195. automatically to the Read Replica
  196. during the maintenance window.
  197. Default is True.
  198. :rtype: :class:`boto.rds.dbinstance.DBInstance`
  199. :return: The new db instance.
  200. """
  201. params = {'DBInstanceIdentifier': id,
  202. 'AllocatedStorage': allocated_storage,
  203. 'DBInstanceClass': instance_class,
  204. 'Engine': engine,
  205. 'MasterUsername': master_username,
  206. 'MasterUserPassword': master_password,
  207. 'Port': port,
  208. 'MultiAZ': str(multi_az).lower(),
  209. 'AutoMinorVersionUpgrade':
  210. str(auto_minor_version_upgrade).lower()}
  211. if db_name:
  212. params['DBName'] = db_name
  213. if param_group:
  214. params['DBParameterGroupName'] = param_group
  215. if security_groups:
  216. l = []
  217. for group in security_groups:
  218. if isinstance(group, DBSecurityGroup):
  219. l.append(group.name)
  220. else:
  221. l.append(group)
  222. self.build_list_params(params, l, 'DBSecurityGroups.member')
  223. if availability_zone:
  224. params['AvailabilityZone'] = availability_zone
  225. if preferred_maintenance_window:
  226. params['PreferredMaintenanceWindow'] = preferred_maintenance_window
  227. if backup_retention_period is not None:
  228. params['BackupRetentionPeriod'] = backup_retention_period
  229. if preferred_backup_window:
  230. params['PreferredBackupWindow'] = preferred_backup_window
  231. if engine_version:
  232. params['EngineVersion'] = engine_version
  233. return self.get_object('CreateDBInstance', params, DBInstance)
  234. def create_dbinstance_read_replica(self, id, source_id,
  235. instance_class=None,
  236. port=3306,
  237. availability_zone=None,
  238. auto_minor_version_upgrade=None):
  239. """
  240. Create a new DBInstance Read Replica.
  241. :type id: str
  242. :param id: Unique identifier for the new instance.
  243. Must contain 1-63 alphanumeric characters.
  244. First character must be a letter.
  245. May not end with a hyphen or contain two consecutive hyphens
  246. :type source_id: str
  247. :param source_id: Unique identifier for the DB Instance for which this
  248. DB Instance will act as a Read Replica.
  249. :type instance_class: str
  250. :param instance_class: The compute and memory capacity of the
  251. DBInstance. Default is to inherit from
  252. the source DB Instance.
  253. Valid values are:
  254. * db.m1.small
  255. * db.m1.large
  256. * db.m1.xlarge
  257. * db.m2.xlarge
  258. * db.m2.2xlarge
  259. * db.m2.4xlarge
  260. :type port: int
  261. :param port: Port number on which database accepts connections.
  262. Default is to inherit from source DB Instance.
  263. Valid values [1115-65535]. Defaults to 3306.
  264. :type availability_zone: str
  265. :param availability_zone: Name of the availability zone to place
  266. DBInstance into.
  267. :type auto_minor_version_upgrade: bool
  268. :param auto_minor_version_upgrade: Indicates that minor engine
  269. upgrades will be applied
  270. automatically to the Read Replica
  271. during the maintenance window.
  272. Default is to inherit this value
  273. from the source DB Instance.
  274. :rtype: :class:`boto.rds.dbinstance.DBInstance`
  275. :return: The new db instance.
  276. """
  277. params = {'DBInstanceIdentifier': id,
  278. 'SourceDBInstanceIdentifier': source_id}
  279. if instance_class:
  280. params['DBInstanceClass'] = instance_class
  281. if port:
  282. params['Port'] = port
  283. if availability_zone:
  284. params['AvailabilityZone'] = availability_zone
  285. if auto_minor_version_upgrade is not None:
  286. if auto_minor_version_upgrade is True:
  287. params['AutoMinorVersionUpgrade'] = 'true'
  288. else:
  289. params['AutoMinorVersionUpgrade'] = 'false'
  290. return self.get_object('CreateDBInstanceReadReplica',
  291. params, DBInstance)
  292. def modify_dbinstance(self, id, param_group=None, security_groups=None,
  293. preferred_maintenance_window=None,
  294. master_password=None, allocated_storage=None,
  295. instance_class=None,
  296. backup_retention_period=None,
  297. preferred_backup_window=None,
  298. multi_az=False,
  299. apply_immediately=False):
  300. """
  301. Modify an existing DBInstance.
  302. :type id: str
  303. :param id: Unique identifier for the new instance.
  304. :type security_groups: list of str or list of DBSecurityGroup objects
  305. :param security_groups: List of names of DBSecurityGroup to authorize on
  306. this DBInstance.
  307. :type preferred_maintenance_window: str
  308. :param preferred_maintenance_window: The weekly time range (in UTC)
  309. during which maintenance can
  310. occur.
  311. Default is Sun:05:00-Sun:09:00
  312. :type master_password: str
  313. :param master_password: Password of master user for the DBInstance.
  314. Must be 4-15 alphanumeric characters.
  315. :type allocated_storage: int
  316. :param allocated_storage: The new allocated storage size, in GBs.
  317. Valid values are [5-1024]
  318. :type instance_class: str
  319. :param instance_class: The compute and memory capacity of the
  320. DBInstance. Changes will be applied at
  321. next maintenance window unless
  322. apply_immediately is True.
  323. Valid values are:
  324. * db.m1.small
  325. * db.m1.large
  326. * db.m1.xlarge
  327. * db.m2.xlarge
  328. * db.m2.2xlarge
  329. * db.m2.4xlarge
  330. :type apply_immediately: bool
  331. :param apply_immediately: If true, the modifications will be applied
  332. as soon as possible rather than waiting for
  333. the next preferred maintenance window.
  334. :type backup_retention_period: int
  335. :param backup_retention_period: The number of days for which automated
  336. backups are retained. Setting this to
  337. zero disables automated backups.
  338. :type preferred_backup_window: str
  339. :param preferred_backup_window: The daily time range during which
  340. automated backups are created (if
  341. enabled). Must be in h24:mi-hh24:mi
  342. format (UTC).
  343. :type multi_az: bool
  344. :param multi_az: If True, specifies the DB Instance will be
  345. deployed in multiple availability zones.
  346. :rtype: :class:`boto.rds.dbinstance.DBInstance`
  347. :return: The modified db instance.
  348. """
  349. params = {'DBInstanceIdentifier': id}
  350. if param_group:
  351. params['DBParameterGroupName'] = param_group
  352. if security_groups:
  353. l = []
  354. for group in security_groups:
  355. if isinstance(group, DBSecurityGroup):
  356. l.append(group.name)
  357. else:
  358. l.append(group)
  359. self.build_list_params(params, l, 'DBSecurityGroups.member')
  360. if preferred_maintenance_window:
  361. params['PreferredMaintenanceWindow'] = preferred_maintenance_window
  362. if master_password:
  363. params['MasterUserPassword'] = master_password
  364. if allocated_storage:
  365. params['AllocatedStorage'] = allocated_storage
  366. if instance_class:
  367. params['DBInstanceClass'] = instance_class
  368. if backup_retention_period is not None:
  369. params['BackupRetentionPeriod'] = backup_retention_period
  370. if preferred_backup_window:
  371. params['PreferredBackupWindow'] = preferred_backup_window
  372. if multi_az:
  373. params['MultiAZ'] = 'true'
  374. if apply_immediately:
  375. params['ApplyImmediately'] = 'true'
  376. return self.get_object('ModifyDBInstance', params, DBInstance)
  377. def delete_dbinstance(self, id, skip_final_snapshot=False,
  378. final_snapshot_id=''):
  379. """
  380. Delete an existing DBInstance.
  381. :type id: str
  382. :param id: Unique identifier for the new instance.
  383. :type skip_final_snapshot: bool
  384. :param skip_final_snapshot: This parameter determines whether a final
  385. db snapshot is created before the instance
  386. is deleted. If True, no snapshot
  387. is created. If False, a snapshot
  388. is created before deleting the instance.
  389. :type final_snapshot_id: str
  390. :param final_snapshot_id: If a final snapshot is requested, this
  391. is the identifier used for that snapshot.
  392. :rtype: :class:`boto.rds.dbinstance.DBInstance`
  393. :return: The deleted db instance.
  394. """
  395. params = {'DBInstanceIdentifier': id}
  396. if skip_final_snapshot:
  397. params['SkipFinalSnapshot'] = 'true'
  398. else:
  399. params['SkipFinalSnapshot'] = 'false'
  400. params['FinalDBSnapshotIdentifier'] = final_snapshot_id
  401. return self.get_object('DeleteDBInstance', params, DBInstance)
  402. def reboot_dbinstance(self, id):
  403. """
  404. Reboot DBInstance.
  405. :type id: str
  406. :param id: Unique identifier of the instance.
  407. :rtype: :class:`boto.rds.dbinstance.DBInstance`
  408. :return: The rebooting db instance.
  409. """
  410. params = {'DBInstanceIdentifier': id}
  411. return self.get_object('RebootDBInstance', params, DBInstance)
  412. # DBParameterGroup methods
  413. def get_all_dbparameter_groups(self, groupname=None, max_records=None,
  414. marker=None):
  415. """
  416. Get all parameter groups associated with your account in a region.
  417. :type groupname: str
  418. :param groupname: The name of the DBParameter group to retrieve.
  419. If not provided, all DBParameter groups will be returned.
  420. :type max_records: int
  421. :param max_records: The maximum number of records to be returned.
  422. If more results are available, a MoreToken will
  423. be returned in the response that can be used to
  424. retrieve additional records. Default is 100.
  425. :type marker: str
  426. :param marker: The marker provided by a previous request.
  427. :rtype: list
  428. :return: A list of :class:`boto.ec2.parametergroup.ParameterGroup`
  429. """
  430. params = {}
  431. if groupname:
  432. params['DBParameterGroupName'] = groupname
  433. if max_records:
  434. params['MaxRecords'] = max_records
  435. if marker:
  436. params['Marker'] = marker
  437. return self.get_list('DescribeDBParameterGroups', params,
  438. [('DBParameterGroup', ParameterGroup)])
  439. def get_all_dbparameters(self, groupname, source=None,
  440. max_records=None, marker=None):
  441. """
  442. Get all parameters associated with a ParameterGroup
  443. :type groupname: str
  444. :param groupname: The name of the DBParameter group to retrieve.
  445. :type source: str
  446. :param source: Specifies which parameters to return.
  447. If not specified, all parameters will be returned.
  448. Valid values are: user|system|engine-default
  449. :type max_records: int
  450. :param max_records: The maximum number of records to be returned.
  451. If more results are available, a MoreToken will
  452. be returned in the response that can be used to
  453. retrieve additional records. Default is 100.
  454. :type marker: str
  455. :param marker: The marker provided by a previous request.
  456. :rtype: :class:`boto.ec2.parametergroup.ParameterGroup`
  457. :return: The ParameterGroup
  458. """
  459. params = {'DBParameterGroupName': groupname}
  460. if source:
  461. params['Source'] = source
  462. if max_records:
  463. params['MaxRecords'] = max_records
  464. if marker:
  465. params['Marker'] = marker
  466. pg = self.get_object('DescribeDBParameters', params, ParameterGroup)
  467. pg.name = groupname
  468. return pg
  469. def create_parameter_group(self, name, engine='MySQL5.1', description=''):
  470. """
  471. Create a new dbparameter group for your account.
  472. :type name: string
  473. :param name: The name of the new dbparameter group
  474. :type engine: str
  475. :param engine: Name of database engine.
  476. :type description: string
  477. :param description: The description of the new security group
  478. :rtype: :class:`boto.rds.dbsecuritygroup.DBSecurityGroup`
  479. :return: The newly created DBSecurityGroup
  480. """
  481. params = {'DBParameterGroupName': name,
  482. 'DBParameterGroupFamily': engine,
  483. 'Description': description}
  484. return self.get_object('CreateDBParameterGroup', params, ParameterGroup)
  485. def modify_parameter_group(self, name, parameters=None):
  486. """
  487. Modify a parameter group for your account.
  488. :type name: string
  489. :param name: The name of the new parameter group
  490. :type parameters: list of :class:`boto.rds.parametergroup.Parameter`
  491. :param parameters: The new parameters
  492. :rtype: :class:`boto.rds.parametergroup.ParameterGroup`
  493. :return: The newly created ParameterGroup
  494. """
  495. params = {'DBParameterGroupName': name}
  496. for i in range(0, len(parameters)):
  497. parameter = parameters[i]
  498. parameter.merge(params, i+1)
  499. return self.get_list('ModifyDBParameterGroup', params,
  500. ParameterGroup, verb='POST')
  501. def reset_parameter_group(self, name, reset_all_params=False,
  502. parameters=None):
  503. """
  504. Resets some or all of the parameters of a ParameterGroup to the
  505. default value
  506. :type key_name: string
  507. :param key_name: The name of the ParameterGroup to reset
  508. :type parameters: list of :class:`boto.rds.parametergroup.Parameter`
  509. :param parameters: The parameters to reset. If not supplied,
  510. all parameters will be reset.
  511. """
  512. params = {'DBParameterGroupName': name}
  513. if reset_all_params:
  514. params['ResetAllParameters'] = 'true'
  515. else:
  516. params['ResetAllParameters'] = 'false'
  517. for i in range(0, len(parameters)):
  518. parameter = parameters[i]
  519. parameter.merge(params, i+1)
  520. return self.get_status('ResetDBParameterGroup', params)
  521. def delete_parameter_group(self, name):
  522. """
  523. Delete a DBSecurityGroup from your account.
  524. :type key_name: string
  525. :param key_name: The name of the DBSecurityGroup to delete
  526. """
  527. params = {'DBParameterGroupName': name}
  528. return self.get_status('DeleteDBParameterGroup', params)
  529. # DBSecurityGroup methods
  530. def get_all_dbsecurity_groups(self, groupname=None, max_records=None,
  531. marker=None):
  532. """
  533. Get all security groups associated with your account in a region.
  534. :type groupnames: list
  535. :param groupnames: A list of the names of security groups to retrieve.
  536. If not provided, all security groups will
  537. be returned.
  538. :type max_records: int
  539. :param max_records: The maximum number of records to be returned.
  540. If more results are available, a MoreToken will
  541. be returned in the response that can be used to
  542. retrieve additional records. Default is 100.
  543. :type marker: str
  544. :param marker: The marker provided by a previous request.
  545. :rtype: list
  546. :return: A list of :class:`boto.rds.dbsecuritygroup.DBSecurityGroup`
  547. """
  548. params = {}
  549. if groupname:
  550. params['DBSecurityGroupName'] = groupname
  551. if max_records:
  552. params['MaxRecords'] = max_records
  553. if marker:
  554. params['Marker'] = marker
  555. return self.get_list('DescribeDBSecurityGroups', params,
  556. [('DBSecurityGroup', DBSecurityGroup)])
  557. def create_dbsecurity_group(self, name, description=None):
  558. """
  559. Create a new security group for your account.
  560. This will create the security group within the region you
  561. are currently connected to.
  562. :type name: string
  563. :param name: The name of the new security group
  564. :type description: string
  565. :param description: The description of the new security group
  566. :rtype: :class:`boto.rds.dbsecuritygroup.DBSecurityGroup`
  567. :return: The newly created DBSecurityGroup
  568. """
  569. params = {'DBSecurityGroupName': name}
  570. if description:
  571. params['DBSecurityGroupDescription'] = description
  572. group = self.get_object('CreateDBSecurityGroup', params,
  573. DBSecurityGroup)
  574. group.name = name
  575. group.description = description
  576. return group
  577. def delete_dbsecurity_group(self, name):
  578. """
  579. Delete a DBSecurityGroup from your account.
  580. :type key_name: string
  581. :param key_name: The name of the DBSecurityGroup to delete
  582. """
  583. params = {'DBSecurityGroupName': name}
  584. return self.get_status('DeleteDBSecurityGroup', params)
  585. def authorize_dbsecurity_group(self, group_name, cidr_ip=None,
  586. ec2_security_group_name=None,
  587. ec2_security_group_owner_id=None):
  588. """
  589. Add a new rule to an existing security group.
  590. You need to pass in either src_security_group_name and
  591. src_security_group_owner_id OR a CIDR block but not both.
  592. :type group_name: string
  593. :param group_name: The name of the security group you are adding
  594. the rule to.
  595. :type ec2_security_group_name: string
  596. :param ec2_security_group_name: The name of the EC2 security group
  597. you are granting access to.
  598. :type ec2_security_group_owner_id: string
  599. :param ec2_security_group_owner_id: The ID of the owner of the EC2
  600. security group you are granting
  601. access to.
  602. :type cidr_ip: string
  603. :param cidr_ip: The CIDR block you are providing access to.
  604. See http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
  605. :rtype: bool
  606. :return: True if successful.
  607. """
  608. params = {'DBSecurityGroupName': group_name}
  609. if ec2_security_group_name:
  610. params['EC2SecurityGroupName'] = ec2_security_group_name
  611. if ec2_security_group_owner_id:
  612. params['EC2SecurityGroupOwnerId'] = ec2_security_group_owner_id
  613. if cidr_ip:
  614. params['CIDRIP'] = urllib.quote(cidr_ip)
  615. return self.get_object('AuthorizeDBSecurityGroupIngress', params,
  616. DBSecurityGroup)
  617. def revoke_dbsecurity_group(self, group_name, ec2_security_group_name=None,
  618. ec2_security_group_owner_id=None, cidr_ip=None):
  619. """
  620. Remove an existing rule from an existing security group.
  621. You need to pass in either ec2_security_group_name and
  622. ec2_security_group_owner_id OR a CIDR block.
  623. :type group_name: string
  624. :param group_name: The name of the security group you are removing
  625. the rule from.
  626. :type ec2_security_group_name: string
  627. :param ec2_security_group_name: The name of the EC2 security group
  628. from which you are removing access.
  629. :type ec2_security_group_owner_id: string
  630. :param ec2_security_group_owner_id: The ID of the owner of the EC2
  631. security from which you are
  632. removing access.
  633. :type cidr_ip: string
  634. :param cidr_ip: The CIDR block from which you are removing access.
  635. See http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
  636. :rtype: bool
  637. :return: True if successful.
  638. """
  639. params = {'DBSecurityGroupName': group_name}
  640. if ec2_security_group_name:
  641. params['EC2SecurityGroupName'] = ec2_security_group_name
  642. if ec2_security_group_owner_id:
  643. params['EC2SecurityGroupOwnerId'] = ec2_security_group_owner_id
  644. if cidr_ip:
  645. params['CIDRIP'] = cidr_ip
  646. return self.get_object('RevokeDBSecurityGroupIngress', params,
  647. DBSecurityGroup)
  648. # For backwards compatibility. This method was improperly named
  649. # in previous versions. I have renamed it to match the others.
  650. revoke_security_group = revoke_dbsecurity_group
  651. # DBSnapshot methods
  652. def get_all_dbsnapshots(self, snapshot_id=None, instance_id=None,
  653. max_records=None, marker=None):
  654. """
  655. Get information about DB Snapshots.
  656. :type snapshot_id: str
  657. :param snapshot_id: The unique identifier of an RDS snapshot.
  658. If not provided, all RDS snapshots will be returned.
  659. :type instance_id: str
  660. :param instance_id: The identifier of a DBInstance. If provided,
  661. only the DBSnapshots related to that instance will
  662. be returned.
  663. If not provided, all RDS snapshots will be returned.
  664. :type max_records: int
  665. :param max_records: The maximum number of records to be returned.
  666. If more results are available, a MoreToken will
  667. be returned in the response that can be used to
  668. retrieve additional records. Default is 100.
  669. :type marker: str
  670. :param marker: The marker provided by a previous request.
  671. :rtype: list
  672. :return: A list of :class:`boto.rds.dbsnapshot.DBSnapshot`
  673. """
  674. params = {}
  675. if snapshot_id:
  676. params['DBSnapshotIdentifier'] = snapshot_id
  677. if instance_id:
  678. params['DBInstanceIdentifier'] = instance_id
  679. if max_records:
  680. params['MaxRecords'] = max_records
  681. if marker:
  682. params['Marker'] = marker
  683. return self.get_list('DescribeDBSnapshots', params,
  684. [('DBSnapshot', DBSnapshot)])
  685. def create_dbsnapshot(self, snapshot_id, dbinstance_id):
  686. """
  687. Create a new DB snapshot.
  688. :type snapshot_id: string
  689. :param snapshot_id: The identifier for the DBSnapshot
  690. :type dbinstance_id: string
  691. :param dbinstance_id: The source identifier for the RDS instance from
  692. which the snapshot is created.
  693. :rtype: :class:`boto.rds.dbsnapshot.DBSnapshot`
  694. :return: The newly created DBSnapshot
  695. """
  696. params = {'DBSnapshotIdentifier': snapshot_id,
  697. 'DBInstanceIdentifier': dbinstance_id}
  698. return self.get_object('CreateDBSnapshot', params, DBSnapshot)
  699. def delete_dbsnapshot(self, identifier):
  700. """
  701. Delete a DBSnapshot
  702. :type identifier: string
  703. :param identifier: The identifier of the DBSnapshot to delete
  704. """
  705. params = {'DBSnapshotIdentifier': identifier}
  706. return self.get_object('DeleteDBSnapshot', params, DBSnapshot)
  707. def restore_dbinstance_from_dbsnapshot(self, identifier, instance_id,
  708. instance_class, port=None,
  709. availability_zone=None,
  710. multi_az=None,
  711. auto_minor_version_upgrade=None):
  712. """
  713. Create a new DBInstance from a DB snapshot.
  714. :type identifier: string
  715. :param identifier: The identifier for the DBSnapshot
  716. :type instance_id: string
  717. :param instance_id: The source identifier for the RDS instance from
  718. which the snapshot is created.
  719. :type instance_class: str
  720. :param instance_class: The compute and memory capacity of the
  721. DBInstance. Valid values are:
  722. db.m1.small | db.m1.large | db.m1.xlarge |
  723. db.m2.2xlarge | db.m2.4xlarge
  724. :type port: int
  725. :param port: Port number on which database accepts connections.
  726. Valid values [1115-65535]. Defaults to 3306.
  727. :type availability_zone: str
  728. :param availability_zone: Name of the availability zone to place
  729. DBInstance into.
  730. :type multi_az: bool
  731. :param multi_az: If True, specifies the DB Instance will be
  732. deployed in multiple availability zones.
  733. Default is the API default.
  734. :type auto_minor_version_upgrade: bool
  735. :param auto_minor_version_upgrade: Indicates that minor engine
  736. upgrades will be applied
  737. automatically to the Read Replica
  738. during the maintenance window.
  739. Default is the API default.
  740. :rtype: :class:`boto.rds.dbinstance.DBInstance`
  741. :return: The newly created DBInstance
  742. """
  743. params = {'DBSnapshotIdentifier': identifier,
  744. 'DBInstanceIdentifier': instance_id,
  745. 'DBInstanceClass': instance_class}
  746. if port:
  747. params['Port'] = port
  748. if availability_zone:
  749. params['AvailabilityZone'] = availability_zone
  750. if multi_az is not None:
  751. params['MultiAZ'] = str(multi_az).lower()
  752. if auto_minor_version_upgrade is not None:
  753. params['AutoMinorVersionUpgrade'] = str(auto_minor_version_upgrade).lower()
  754. return self.get_object('RestoreDBInstanceFromDBSnapshot',
  755. params, DBInstance)
  756. def restore_dbinstance_from_point_in_time(self, source_instance_id,
  757. target_instance_id,
  758. use_latest=False,
  759. restore_time=None,
  760. dbinstance_class=None,
  761. port=None,
  762. availability_zone=None):
  763. """
  764. Create a new DBInstance from a point in time.
  765. :type source_instance_id: string
  766. :param source_instance_id: The identifier for the source DBInstance.
  767. :type target_instance_id: string
  768. :param target_instance_id: The identifier of the new DBInstance.
  769. :type use_latest: bool
  770. :param use_latest: If True, the latest snapshot availabile will
  771. be used.
  772. :type restore_time: datetime
  773. :param restore_time: The date and time to restore from. Only
  774. used if use_latest is False.
  775. :type instance_class: str
  776. :param instance_class: The compute and memory capacity of the
  777. DBInstance. Valid values are:
  778. db.m1.small | db.m1.large | db.m1.xlarge |
  779. db.m2.2xlarge | db.m2.4xlarge
  780. :type port: int
  781. :param port: Port number on which database accepts connections.
  782. Valid values [1115-65535]. Defaults to 3306.
  783. :type availability_zone: str
  784. :param availability_zone: Name of the availability zone to place
  785. DBInstance into.
  786. :rtype: :class:`boto.rds.dbinstance.DBInstance`
  787. :return: The newly created DBInstance
  788. """
  789. params = {'SourceDBInstanceIdentifier': source_instance_id,
  790. 'TargetDBInstanceIdentifier': target_instance_id}
  791. if use_latest:
  792. params['UseLatestRestorableTime'] = 'true'
  793. elif restore_time:
  794. params['RestoreTime'] = restore_time.isoformat()
  795. if dbinstance_class:
  796. params['DBInstanceClass'] = dbinstance_class
  797. if port:
  798. params['Port'] = port
  799. if availability_zone:
  800. params['AvailabilityZone'] = availability_zone
  801. return self.get_object('RestoreDBInstanceToPointInTime',
  802. params, DBInstance)
  803. # Events
  804. def get_all_events(self, source_identifier=None, source_type=None,
  805. start_time=None, end_time=None,
  806. max_records=None, marker=None):
  807. """
  808. Get information about events related to your DBInstances,
  809. DBSecurityGroups and DBParameterGroups.
  810. :type source_identifier: str
  811. :param source_identifier: If supplied, the events returned will be
  812. limited to those that apply to the identified
  813. source. The value of this parameter depends
  814. on the value of source_type. If neither
  815. parameter is specified, all events in the time
  816. span will be returned.
  817. :type source_type: str
  818. :param source_type: Specifies how the source_identifier should
  819. be interpreted. Valid values are:
  820. b-instance | db-security-group |
  821. db-parameter-group | db-snapshot
  822. :type start_time: datetime
  823. :param start_time: The beginning of the time interval for events.
  824. If not supplied, all available events will
  825. be returned.
  826. :type end_time: datetime
  827. :param end_time: The ending of the time interval for events.
  828. If not supplied, all available events will
  829. be returned.
  830. :type max_records: int
  831. :param max_records: The maximum number of records to be returned.
  832. If more results are available, a MoreToken will
  833. be returned in the response that can be used to
  834. retrieve additional records. Default is 100.
  835. :type marker: str
  836. :param marker: The marker provided by a previous request.
  837. :rtype: list
  838. :return: A list of class:`boto.rds.event.Event`
  839. """
  840. params = {}
  841. if source_identifier and source_type:
  842. params['SourceIdentifier'] = source_identifier
  843. params['SourceType'] = source_type
  844. if start_time:
  845. params['StartTime'] = start_time.isoformat()
  846. if end_time:
  847. params['EndTime'] = end_time.isoformat()
  848. if max_records:
  849. params['MaxRecords'] = max_records
  850. if marker:
  851. params['Marker'] = marker
  852. return self.get_list('DescribeEvents', params, [('Event', Event)])