{"action":"created","comment":{"url":"https://api.github.com/repos/allegro/ralph/pulls/comments/57145475","id":57145475,"diff_hunk":"@@ -0,0 +1,172 @@\n+# -*- coding: utf-8 -*-\n+import logging\n+from urllib.parse import urlencode, urljoin\n+\n+import requests\n+from django.conf import settings\n+from django.utils.translation import ugettext_lazy as _\n+\n+from ralph.dns.forms import RecordType\n+from ralph.helpers import cache\n+\n+logger = logging.getLogger(__name__)\n+\n+\n+class DNSaaS:\n+\n+    def __init__(self, headers=None):\n+        self.session = requests.Session()\n+        _headers = {\n+            'Authorization': 'Token {}'.format(settings.DNSAAS_TOKEN)\n+        }\n+        if headers is not None:\n+            _headers.update(headers)\n+        self.session.headers.update(_headers)\n+\n+    def get_api_result(self, url):\n+        \"\"\"\n+        Returns 'results' from DNSAAS API.\n+\n+        Args:\n+            url: Url to API\n+\n+        Returns:\n+            list of records\n+        \"\"\"\n+        request = self.session.get(url)\n+        json_data = request.json()\n+        api_results = json_data.get('results', [])\n+        if json_data.get('next', None):\n+            _api_results = self.get_api_result(json_data['next'])\n+            api_results.extend(_api_results)\n+        return api_results\n+\n+    def get_dns_records(self, ipaddresses):\n+        \"\"\"Gets DNS Records for `ipaddresses` by API call\"\"\"\n+        dns_records = []\n+        ipaddresses = [('ip', i) for i in ipaddresses]\n+        url = urljoin(\n+            settings.DNSAAS_URL,\n+            'api/records/?{}'.format(\n+                urlencode([\n+                    ('limit', 100),\n+                    ('offset', 0)\n+                ] + ipaddresses)\n+            )\n+        )\n+        api_results = self.get_api_result(url)\n+        ptr_list = set(","path":"src/ralph/dns/dnsaas.py","position":58,"original_position":58,"commit_id":"57bb7290c0f4a90eb99f430245dfcdebb7f7061a","original_commit_id":"57bb7290c0f4a90eb99f430245dfcdebb7f7061a","user":{"login":"mkurek","id":107437,"avatar_url":"https://avatars.githubusercontent.com/u/107437?v=3","gravatar_id":"","url":"https://api.github.com/users/mkurek","html_url":"https://github.com/mkurek","followers_url":"https://api.github.com/users/mkurek/followers","following_url":"https://api.github.com/users/mkurek/following{/other_user}","gists_url":"https://api.github.com/users/mkurek/gists{/gist_id}","starred_url":"https://api.github.com/users/mkurek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkurek/subscriptions","organizations_url":"https://api.github.com/users/mkurek/orgs","repos_url":"https://api.github.com/users/mkurek/repos","events_url":"https://api.github.com/users/mkurek/events{/privacy}","received_events_url":"https://api.github.com/users/mkurek/received_events","type":"User","site_admin":false},"body":"list suggests that this is a list - maybe `ptrs`?","created_at":"2016-03-23T11:40:40Z","updated_at":"2016-03-23T11:40:40Z","html_url":"https://github.com/allegro/ralph/pull/2289#discussion_r57145475","pull_request_url":"https://api.github.com/repos/allegro/ralph/pulls/2289","_links":{"self":{"href":"https://api.github.com/repos/allegro/ralph/pulls/comments/57145475"},"html":{"href":"https://github.com/allegro/ralph/pull/2289#discussion_r57145475"},"pull_request":{"href":"https://api.github.com/repos/allegro/ralph/pulls/2289"}}},"pull_request":{"url":"https://api.github.com/repos/allegro/ralph/pulls/2289","id":62906931,"html_url":"https://github.com/allegro/ralph/pull/2289","diff_url":"https://github.com/allegro/ralph/pull/2289.diff","patch_url":"https://github.com/allegro/ralph/pull/2289.patch","issue_url":"https://api.github.com/repos/allegro/ralph/issues/2289","number":2289,"state":"open","locked":false,"title":"DNS records from DNSAAS.","user":{"login":"szok","id":2209581,"avatar_url":"https://avatars.githubusercontent.com/u/2209581?v=3","gravatar_id":"","url":"https://api.github.com/users/szok","html_url":"https://github.com/szok","followers_url":"https://api.github.com/users/szok/followers","following_url":"https://api.github.com/users/szok/following{/other_user}","gists_url":"https://api.github.com/users/szok/gists{/gist_id}","starred_url":"https://api.github.com/users/szok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szok/subscriptions","organizations_url":"https://api.github.com/users/szok/orgs","repos_url":"https://api.github.com/users/szok/repos","events_url":"https://api.github.com/users/szok/events{/privacy}","received_events_url":"https://api.github.com/users/szok/received_events","type":"User","site_admin":false},"body":"Added optional DNS feature to data center assets.\r\nSee: https://github.com/allegro/django-powerdns-dnssec","created_at":"2016-03-15T13:42:56Z","updated_at":"2016-03-23T11:40:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ebd30419845313b0d76e09c03130fff9f3acb0b5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/allegro/ralph/pulls/2289/commits","review_comments_url":"https://api.github.com/repos/allegro/ralph/pulls/2289/comments","review_comment_url":"https://api.github.com/repos/allegro/ralph/pulls/comments{/number}","comments_url":"https://api.github.com/repos/allegro/ralph/issues/2289/comments","statuses_url":"https://api.github.com/repos/allegro/ralph/statuses/57bb7290c0f4a90eb99f430245dfcdebb7f7061a","head":{"label":"allegro:feature/dns","ref":"feature/dns","sha":"57bb7290c0f4a90eb99f430245dfcdebb7f7061a","user":{"login":"allegro","id":562236,"avatar_url":"https://avatars.githubusercontent.com/u/562236?v=3","gravatar_id":"","url":"https://api.github.com/users/allegro","html_url":"https://github.com/allegro","followers_url":"https://api.github.com/users/allegro/followers","following_url":"https://api.github.com/users/allegro/following{/other_user}","gists_url":"https://api.github.com/users/allegro/gists{/gist_id}","starred_url":"https://api.github.com/users/allegro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allegro/subscriptions","organizations_url":"https://api.github.com/users/allegro/orgs","repos_url":"https://api.github.com/users/allegro/repos","events_url":"https://api.github.com/users/allegro/events{/privacy}","received_events_url":"https://api.github.com/users/allegro/received_events","type":"Organization","site_admin":false},"repo":{"id":4359038,"name":"ralph","full_name":"allegro/ralph","owner":{"login":"allegro","id":562236,"avatar_url":"https://avatars.githubusercontent.com/u/562236?v=3","gravatar_id":"","url":"https://api.github.com/users/allegro","html_url":"https://github.com/allegro","followers_url":"https://api.github.com/users/allegro/followers","following_url":"https://api.github.com/users/allegro/following{/other_user}","gists_url":"https://api.github.com/users/allegro/gists{/gist_id}","starred_url":"https://api.github.com/users/allegro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allegro/subscriptions","organizations_url":"https://api.github.com/users/allegro/orgs","repos_url":"https://api.github.com/users/allegro/repos","events_url":"https://api.github.com/users/allegro/events{/privacy}","received_events_url":"https://api.github.com/users/allegro/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/allegro/ralph","description":"Ralph is an asset management system for your data center.","fork":false,"url":"https://api.github.com/repos/allegro/ralph","forks_url":"https://api.github.com/repos/allegro/ralph/forks","keys_url":"https://api.github.com/repos/allegro/ralph/keys{/key_id}","collaborators_url":"https://api.github.com/repos/allegro/ralph/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/allegro/ralph/teams","hooks_url":"https://api.github.com/repos/allegro/ralph/hooks","issue_events_url":"https://api.github.com/repos/allegro/ralph/issues/events{/number}","events_url":"https://api.github.com/repos/allegro/ralph/events","assignees_url":"https://api.github.com/repos/allegro/ralph/assignees{/user}","branches_url":"https://api.github.com/repos/allegro/ralph/branches{/branch}","tags_url":"https://api.github.com/repos/allegro/ralph/tags","blobs_url":"https://api.github.com/repos/allegro/ralph/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/allegro/ralph/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/allegro/ralph/git/refs{/sha}","trees_url":"https://api.github.com/repos/allegro/ralph/git/trees{/sha}","statuses_url":"https://api.github.com/repos/allegro/ralph/statuses/{sha}","languages_url":"https://api.github.com/repos/allegro/ralph/languages","stargazers_url":"https://api.github.com/repos/allegro/ralph/stargazers","contributors_url":"https://api.github.com/repos/allegro/ralph/contributors","subscribers_url":"https://api.github.com/repos/allegro/ralph/subscribers","subscription_url":"https://api.github.com/repos/allegro/ralph/subscription","commits_url":"https://api.github.com/repos/allegro/ralph/commits{/sha}","git_commits_url":"https://api.github.com/repos/allegro/ralph/git/commits{/sha}","comments_url":"https://api.github.com/repos/allegro/ralph/comments{/number}","issue_comment_url":"https://api.github.com/repos/allegro/ralph/issues/comments{/number}","contents_url":"https://api.github.com/repos/allegro/ralph/contents/{+path}","compare_url":"https://api.github.com/repos/allegro/ralph/compare/{base}...{head}","merges_url":"https://api.github.com/repos/allegro/ralph/merges","archive_url":"https://api.github.com/repos/allegro/ralph/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/allegro/ralph/downloads","issues_url":"https://api.github.com/repos/allegro/ralph/issues{/number}","pulls_url":"https://api.github.com/repos/allegro/ralph/pulls{/number}","milestones_url":"https://api.github.com/repos/allegro/ralph/milestones{/number}","notifications_url":"https://api.github.com/repos/allegro/ralph/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/allegro/ralph/labels{/name}","releases_url":"https://api.github.com/repos/allegro/ralph/releases{/id}","deployments_url":"https://api.github.com/repos/allegro/ralph/deployments","created_at":"2012-05-17T14:04:57Z","updated_at":"2016-03-21T16:33:21Z","pushed_at":"2016-03-23T11:34:24Z","git_url":"git://github.com/allegro/ralph.git","ssh_url":"git@github.com:allegro/ralph.git","clone_url":"https://github.com/allegro/ralph.git","svn_url":"https://github.com/allegro/ralph","homepage":"http://allegro.tech/ralph/","size":33469,"stargazers_count":381,"watchers_count":381,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":99,"mirror_url":null,"open_issues_count":78,"forks":99,"open_issues":78,"watchers":381,"default_branch":"ng"}},"base":{"label":"allegro:ng","ref":"ng","sha":"47bc4f49f23b537d60db16375e5e00b78194649f","user":{"login":"allegro","id":562236,"avatar_url":"https://avatars.githubusercontent.com/u/562236?v=3","gravatar_id":"","url":"https://api.github.com/users/allegro","html_url":"https://github.com/allegro","followers_url":"https://api.github.com/users/allegro/followers","following_url":"https://api.github.com/users/allegro/following{/other_user}","gists_url":"https://api.github.com/users/allegro/gists{/gist_id}","starred_url":"https://api.github.com/users/allegro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allegro/subscriptions","organizations_url":"https://api.github.com/users/allegro/orgs","repos_url":"https://api.github.com/users/allegro/repos","events_url":"https://api.github.com/users/allegro/events{/privacy}","received_events_url":"https://api.github.com/users/allegro/received_events","type":"Organization","site_admin":false},"repo":{"id":4359038,"name":"ralph","full_name":"allegro/ralph","owner":{"login":"allegro","id":562236,"avatar_url":"https://avatars.githubusercontent.com/u/562236?v=3","gravatar_id":"","url":"https://api.github.com/users/allegro","html_url":"https://github.com/allegro","followers_url":"https://api.github.com/users/allegro/followers","following_url":"https://api.github.com/users/allegro/following{/other_user}","gists_url":"https://api.github.com/users/allegro/gists{/gist_id}","starred_url":"https://api.github.com/users/allegro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allegro/subscriptions","organizations_url":"https://api.github.com/users/allegro/orgs","repos_url":"https://api.github.com/users/allegro/repos","events_url":"https://api.github.com/users/allegro/events{/privacy}","received_events_url":"https://api.github.com/users/allegro/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/allegro/ralph","description":"Ralph is an asset management system for your data center.","fork":false,"url":"https://api.github.com/repos/allegro/ralph","forks_url":"https://api.github.com/repos/allegro/ralph/forks","keys_url":"https://api.github.com/repos/allegro/ralph/keys{/key_id}","collaborators_url":"https://api.github.com/repos/allegro/ralph/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/allegro/ralph/teams","hooks_url":"https://api.github.com/repos/allegro/ralph/hooks","issue_events_url":"https://api.github.com/repos/allegro/ralph/issues/events{/number}","events_url":"https://api.github.com/repos/allegro/ralph/events","assignees_url":"https://api.github.com/repos/allegro/ralph/assignees{/user}","branches_url":"https://api.github.com/repos/allegro/ralph/branches{/branch}","tags_url":"https://api.github.com/repos/allegro/ralph/tags","blobs_url":"https://api.github.com/repos/allegro/ralph/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/allegro/ralph/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/allegro/ralph/git/refs{/sha}","trees_url":"https://api.github.com/repos/allegro/ralph/git/trees{/sha}","statuses_url":"https://api.github.com/repos/allegro/ralph/statuses/{sha}","languages_url":"https://api.github.com/repos/allegro/ralph/languages","stargazers_url":"https://api.github.com/repos/allegro/ralph/stargazers","contributors_url":"https://api.github.com/repos/allegro/ralph/contributors","subscribers_url":"https://api.github.com/repos/allegro/ralph/subscribers","subscription_url":"https://api.github.com/repos/allegro/ralph/subscription","commits_url":"https://api.github.com/repos/allegro/ralph/commits{/sha}","git_commits_url":"https://api.github.com/repos/allegro/ralph/git/commits{/sha}","comments_url":"https://api.github.com/repos/allegro/ralph/comments{/number}","issue_comment_url":"https://api.github.com/repos/allegro/ralph/issues/comments{/number}","contents_url":"https://api.github.com/repos/allegro/ralph/contents/{+path}","compare_url":"https://api.github.com/repos/allegro/ralph/compare/{base}...{head}","merges_url":"https://api.github.com/repos/allegro/ralph/merges","archive_url":"https://api.github.com/repos/allegro/ralph/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/allegro/ralph/downloads","issues_url":"https://api.github.com/repos/allegro/ralph/issues{/number}","pulls_url":"https://api.github.com/repos/allegro/ralph/pulls{/number}","milestones_url":"https://api.github.com/repos/allegro/ralph/milestones{/number}","notifications_url":"https://api.github.com/repos/allegro/ralph/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/allegro/ralph/labels{/name}","releases_url":"https://api.github.com/repos/allegro/ralph/releases{/id}","deployments_url":"https://api.github.com/repos/allegro/ralph/deployments","created_at":"2012-05-17T14:04:57Z","updated_at":"2016-03-21T16:33:21Z","pushed_at":"2016-03-23T11:34:24Z","git_url":"git://github.com/allegro/ralph.git","ssh_url":"git@github.com:allegro/ralph.git","clone_url":"https://github.com/allegro/ralph.git","svn_url":"https://github.com/allegro/ralph","homepage":"http://allegro.tech/ralph/","size":33469,"stargazers_count":381,"watchers_count":381,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":99,"mirror_url":null,"open_issues_count":78,"forks":99,"open_issues":78,"watchers":381,"default_branch":"ng"}},"_links":{"self":{"href":"https://api.github.com/repos/allegro/ralph/pulls/2289"},"html":{"href":"https://github.com/allegro/ralph/pull/2289"},"issue":{"href":"https://api.github.com/repos/allegro/ralph/issues/2289"},"comments":{"href":"https://api.github.com/repos/allegro/ralph/issues/2289/comments"},"review_comments":{"href":"https://api.github.com/repos/allegro/ralph/pulls/2289/comments"},"review_comment":{"href":"https://api.github.com/repos/allegro/ralph/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/allegro/ralph/pulls/2289/commits"},"statuses":{"href":"https://api.github.com/repos/allegro/ralph/statuses/57bb7290c0f4a90eb99f430245dfcdebb7f7061a"}}}}