Repository: libcloud Updated Branches: refs/heads/trunk a4d6a9dda -> c3fd03c65
[google dns] LIBCLOUD-681: Allow for multiple record changes in one call Closes #526 Signed-off-by: Eric Johnson <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/c3fd03c6 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/c3fd03c6 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/c3fd03c6 Branch: refs/heads/trunk Commit: c3fd03c658a37772f61ebc42c414f3e88d59f4e3 Parents: a4d6a9d Author: Steven Stone <[email protected]> Authored: Thu May 14 10:57:57 2015 -0400 Committer: Eric Johnson <[email protected]> Committed: Fri May 22 15:59:40 2015 +0000 ---------------------------------------------------------------------- libcloud/dns/drivers/google.py | 36 ++++++++++++++++++++ .../dns/fixtures/google/record_changes.json | 28 +++++++++++++++ libcloud/test/dns/test_google.py | 15 ++++++++ 3 files changed, 79 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/c3fd03c6/libcloud/dns/drivers/google.py ---------------------------------------------------------------------- diff --git a/libcloud/dns/drivers/google.py b/libcloud/dns/drivers/google.py index 93fee58..63be61f 100644 --- a/libcloud/dns/drivers/google.py +++ b/libcloud/dns/drivers/google.py @@ -266,6 +266,42 @@ class GoogleDNSDriver(DNSDriver): data=data) return response.success() + def ex_bulk_record_changes(self, zone, records): + """ + Bulk add and delete records. + + :param zone: Zone where the requested record changes are done. + :type zone: :class:`Zone` + + :param records: Dictionary of additions list or deletions list, or both + of resourceRecordSets. For example: + {'additions': [{'rrdatas': ['127.0.0.1'], + 'kind': 'dns#resourceRecordSet', + 'type': 'A', + 'name': 'www.example.com.', + 'ttl': '300'}], + 'deletions': [{'rrdatas': ['127.0.0.1'], + 'kind': 'dns#resourceRecordSet', + 'type': 'A', + 'name': 'www2.example.com.', + 'ttl': '300'}]} + :type records: ``dict`` + + :return: A dictionary of Record additions and deletions. + :rtype: ``dict`` of additions and deletions of :class:`Record` + """ + + request = '/managedZones/%s/changes' % (zone.id) + response = self.connection.request(request, method='POST', + data=records).object + + response_data = { + 'additions': self._to_records(response.get('additions', []), zone), + 'deletions': self._to_records(response.get('deletions', []), zone), + } + + return response_data + def _get_more(self, rtype, **kwargs): last_key = None exhausted = False http://git-wip-us.apache.org/repos/asf/libcloud/blob/c3fd03c6/libcloud/test/dns/fixtures/google/record_changes.json ---------------------------------------------------------------------- diff --git a/libcloud/test/dns/fixtures/google/record_changes.json b/libcloud/test/dns/fixtures/google/record_changes.json new file mode 100644 index 0000000..03994ad --- /dev/null +++ b/libcloud/test/dns/fixtures/google/record_changes.json @@ -0,0 +1,28 @@ +{ + "kind": "dns#change", + "additions": [ + { + "kind": "dns#resourceRecordSet", + "name": "foo.example.com.", + "type": "A", + "ttl": 300, + "rrdatas": [ + "127.0.0.1" + ] + } + ], + "deletions": [ + { + "kind": "dns#resourceRecordSet", + "name": "bar.example.com.", + "type": "A", + "ttl": 300, + "rrdatas": [ + "127.0.0.1" + ] + } + ], + "startTime": "2015-05-20T19:49:16.974Z", + "id": "37", + "status": "pending" +} http://git-wip-us.apache.org/repos/asf/libcloud/blob/c3fd03c6/libcloud/test/dns/test_google.py ---------------------------------------------------------------------- diff --git a/libcloud/test/dns/test_google.py b/libcloud/test/dns/test_google.py index a074300..1584a59 100644 --- a/libcloud/test/dns/test_google.py +++ b/libcloud/test/dns/test_google.py @@ -116,6 +116,16 @@ class GoogleTests(LibcloudTestCase): res = self.driver.delete_zone(zone) self.assertTrue(res) + def test_ex_bulk_record_changes(self): + zone = self.driver.get_zone('example-com') + records = self.driver.ex_bulk_record_changes(zone, {}) + + self.assertEqual(records['additions'][0].name, 'foo.example.com.') + self.assertEqual(records['additions'][0].type, 'A') + + self.assertEqual(records['deletions'][0].name, 'bar.example.com.') + self.assertEqual(records['deletions'][0].type, 'A') + class GoogleDNSMockHttp(MockHttpTestCase): fixtures = DNSFileFixtures('google') @@ -151,6 +161,11 @@ class GoogleDNSMockHttp(MockHttpTestCase): body = None return (httplib.OK, body, {}, httplib.responses[httplib.OK]) + def _dns_v1beta1_projects_project_name_managedZones_example_com_changes( + self, method, url, body, headers): + body = self.fixtures.load('record_changes.json') + return (httplib.OK, body, {}, httplib.responses[httplib.OK]) + def _dns_v1beta1_projects_project_name_managedZones_example_com_ZONE_DOES_NOT_EXIST( self, method, url, body, headers): body = self.fixtures.load('get_zone_does_not_exists.json')
