You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by an...@apache.org on 2016/03/21 11:23:10 UTC

[01/17] libcloud git commit: fixes lint

Repository: libcloud
Updated Branches:
  refs/heads/trunk 8d012ca19 -> 1a057c9c2


fixes lint


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/fbf56cf1
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/fbf56cf1
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/fbf56cf1

Branch: refs/heads/trunk
Commit: fbf56cf1fc0d14c5697a55f65ad4fc912b657072
Parents: f052713
Author: lostbird <lostbird@lostbird.(none)>
Authored: Mon Mar 21 10:57:05 2016 +0100
Committer: anthony-shaw <an...@gmail.com>
Committed: Mon Mar 21 21:20:31 2016 +1100

----------------------------------------------------------------------
 libcloud/test/dns/test_nsone.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/fbf56cf1/libcloud/test/dns/test_nsone.py
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/test_nsone.py b/libcloud/test/dns/test_nsone.py
index ca5f4c8..ddc82b0 100644
--- a/libcloud/test/dns/test_nsone.py
+++ b/libcloud/test/dns/test_nsone.py
@@ -7,7 +7,7 @@ from libcloud.test.secrets import DNS_PARAMS_NSONE
 from libcloud.dns.drivers.nsone import NsOneDNSDriver
 from libcloud.utils.py3 import httplib
 from libcloud.dns.types import ZoneDoesNotExistError, ZoneAlreadyExistsError,\
-  RecordDoesNotExistError, RecordType
+ RecordDoesNotExistError, RecordType
 from libcloud.dns.base import Zone, Record
 
 


[13/17] libcloud git commit: removes extra space

Posted by an...@apache.org.
removes extra space


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/f0527135
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/f0527135
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/f0527135

Branch: refs/heads/trunk
Commit: f0527135abe73c617c992623f4ae0a974cceae91
Parents: f2ad154
Author: lostbird <lostbird@lostbird.(none)>
Authored: Mon Mar 21 10:52:04 2016 +0100
Committer: anthony-shaw <an...@gmail.com>
Committed: Mon Mar 21 21:20:31 2016 +1100

----------------------------------------------------------------------
 libcloud/test/dns/test_nsone.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/f0527135/libcloud/test/dns/test_nsone.py
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/test_nsone.py b/libcloud/test/dns/test_nsone.py
index 1960faa..ca5f4c8 100644
--- a/libcloud/test/dns/test_nsone.py
+++ b/libcloud/test/dns/test_nsone.py
@@ -7,7 +7,7 @@ from libcloud.test.secrets import DNS_PARAMS_NSONE
 from libcloud.dns.drivers.nsone import NsOneDNSDriver
 from libcloud.utils.py3 import httplib
 from libcloud.dns.types import ZoneDoesNotExistError, ZoneAlreadyExistsError,\
- RecordDoesNotExistError,  RecordType
+  RecordDoesNotExistError, RecordType
 from libcloud.dns.base import Zone, Record
 
 


[06/17] libcloud git commit: flake8 the code

Posted by an...@apache.org.
flake8 the code


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/1d85a2c9
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/1d85a2c9
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/1d85a2c9

Branch: refs/heads/trunk
Commit: 1d85a2c98a1ae6cd62ff25e681923f2a632c152b
Parents: 5ae1264
Author: lostbird <lostbird@lostbird.(none)>
Authored: Sat Feb 27 13:14:20 2016 +0100
Committer: anthony-shaw <an...@gmail.com>
Committed: Mon Mar 21 21:20:31 2016 +1100

----------------------------------------------------------------------
 libcloud/common/nsone.py      |  6 ++--
 libcloud/dns/drivers/nsone.py | 64 ++++++++++++++++++++++++--------------
 2 files changed, 45 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/1d85a2c9/libcloud/common/nsone.py
----------------------------------------------------------------------
diff --git a/libcloud/common/nsone.py b/libcloud/common/nsone.py
index d1f1bbd..5eb4e17 100644
--- a/libcloud/common/nsone.py
+++ b/libcloud/common/nsone.py
@@ -17,10 +17,12 @@ class NsOneResponse(JsonResponse):
     objects = []
 
     def __init__(self, response, connection):
-        super(NsOneResponse, self).__init__(response=response, connection=connection)
+        super(NsOneResponse, self).__init__(response=response,
+                                            connection=connection)
         self.errors, self.objects = self.parse_body_and_errors()
         if not self.success():
-            raise NsOneException(code=self.status, message=self.errors.pop()['message'])
+            raise NsOneException(code=self.status,
+                                 message=self.errors.pop()['message'])
 
     def parse_body_and_errors(self):
         js = super(NsOneResponse, self).parse_body()

http://git-wip-us.apache.org/repos/asf/libcloud/blob/1d85a2c9/libcloud/dns/drivers/nsone.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/nsone.py b/libcloud/dns/drivers/nsone.py
index ae45924..3b903a3 100644
--- a/libcloud/dns/drivers/nsone.py
+++ b/libcloud/dns/drivers/nsone.py
@@ -2,12 +2,13 @@ try:
     import simplejson as json
 except ImportError:
     import json
+
+from libcloud.dns.types import Provider, ZoneDoesNotExistError, \
+    ZoneAlreadyExistsError, RecordDoesNotExistError, RecordAlreadyExistsError
 from libcloud.utils.py3 import httplib
 from libcloud.dns.base import DNSDriver, Zone, Record, RecordType
-from libcloud.common.nsone import NsOneConnection, NsOneResponse, NsOneException
-from libcloud.dns.types import Provider, ZoneDoesNotExistError, ZoneAlreadyExistsError, RecordDoesNotExistError, \
-    RecordAlreadyExistsError
-
+from libcloud.common.nsone import NsOneConnection, NsOneResponse, \
+    NsOneException
 
 __all__ = [
     'NsOneDNSDriver'
@@ -57,7 +58,8 @@ class NsOneDNSDriver(DNSDriver):
             response = self.connection.request(action=action, method='GET')
         except NsOneException, e:
             if e.message == 'zone not found':
-                raise ZoneDoesNotExistError(value=e.message, driver=self, zone_id=zone_id)
+                raise ZoneDoesNotExistError(value=e.message, driver=self,
+                                            zone_id=zone_id)
             else:
                 raise e
         zone = self._to_zone(response.objects[0])
@@ -76,7 +78,8 @@ class NsOneDNSDriver(DNSDriver):
         :param ttl: TTL for new records (This is used through the extra param)
         :type ttl: ``int``
 
-        :param extra: Extra attributes that are specific to the driver such as ttl, nx_ttl. Read API docs for more.
+        :param extra: Extra attributes that are specific to the driver
+        such as ttl.
         :type extra: ``dict``
 
         :rtype: :class:`Zone`
@@ -87,10 +90,12 @@ class NsOneDNSDriver(DNSDriver):
             raw_data.update(extra)
         post_data = json.dumps(raw_data)
         try:
-            response = self.connection.request(action=action, method='PUT', data=post_data)
+            response = self.connection.request(action=action, method='PUT',
+                                               data=post_data)
         except NsOneException, e:
             if e.message == 'zone already exists':
-                raise ZoneAlreadyExistsError(value=e.message, driver=self, zone_id=domain)
+                raise ZoneAlreadyExistsError(value=e.message, driver=self,
+                                             zone_id=domain)
             else:
                 raise e
 
@@ -126,18 +131,22 @@ class NsOneDNSDriver(DNSDriver):
             response = self.connection.request(action=action, method='GET')
         except NsOneException, e:
             if e.message == 'zone not found':
-                raise ZoneDoesNotExistError(value=e.message, driver=self, zone_id=zone.id)
+                raise ZoneDoesNotExistError(value=e.message, driver=self,
+                                            zone_id=zone.id)
             else:
                 raise e
-        records = self._to_records(items=response.parse_body()['records'], zone=zone)
+        records = self._to_records(items=response.parse_body()['records'],
+                                   zone=zone)
 
         return records
 
     def get_record(self, zone_id, record_id):
         """
-        :param zone_id: The id of the zone where to search for the record (e.g. example.com)
+        :param zone_id: The id of the zone where to search for
+        the record (e.g. example.com)
         :type zone_id: ``str``
-        :param record_id: The type of record to search for (e.g. A, AAA, MX etc)
+        :param record_id: The type of record to search for
+        (e.g. A, AAA, MX etc)
 
         :return: :class:`Record`
         """
@@ -146,7 +155,8 @@ class NsOneDNSDriver(DNSDriver):
             response = self.connection.request(action=action, method='GET')
         except NsOneException, e:
             if e.message == 'record not found':
-                raise RecordDoesNotExistError(value=e.message, driver=self, record_id=record_id)
+                raise RecordDoesNotExistError(value=e.message, driver=self,
+                                              record_id=record_id)
             else:
                 raise e
         zone = self.get_zone(zone_id=zone_id)
@@ -161,12 +171,14 @@ class NsOneDNSDriver(DNSDriver):
 
         :return: Boolean
         """
-        action = '/v1/zones/%s/%s/%s' % (record.zone.domain, record.name, record.type)
+        action = '/v1/zones/%s/%s/%s' % (record.zone.domain, record.name,
+                                         record.type)
         try:
             response = self.connection.request(action=action, method='DELETE')
         except NsOneException, e:
             if e.message == 'record not found':
-                raise RecordDoesNotExistError(value=e.message, driver=self, record_id=record.id)
+                raise RecordDoesNotExistError(value=e.message, driver=self,
+                                              record_id=record.id)
             else:
                 raise e
 
@@ -186,7 +198,8 @@ class NsOneDNSDriver(DNSDriver):
         :type extra: ``dict``
         :return: :class:`Record`
         """
-        action = '/v1/zones/%s/%s/%s' % (zone.domain, '%s.%s' % (name, zone.domain), type)
+        action = '/v1/zones/%s/%s/%s' % (zone.domain, '%s.%s' %
+                                         (name, zone.domain), type)
         raw_data = {
             "answers": [
                 {
@@ -202,10 +215,12 @@ class NsOneDNSDriver(DNSDriver):
             raw_data['answers'] = extra.get('answers')
         post_data = json.dumps(raw_data)
         try:
-            response = self.connection.request(action=action, method='PUT', data=post_data)
+            response = self.connection.request(action=action, method='PUT',
+                                               data=post_data)
         except NsOneException, e:
             if e.message == 'record already exists':
-                raise RecordAlreadyExistsError(value=e.message, driver=self, record_id='')
+                raise RecordAlreadyExistsError(value=e.message, driver=self,
+                                               record_id='')
             else:
                 raise e
         record = self._to_record(item=response.parse_body(), zone=zone)
@@ -227,7 +242,8 @@ class NsOneDNSDriver(DNSDriver):
         :return: :class:`Record`
         """
         zone = record.zone
-        action = '/v1/zones/%s/%s/%s' % (zone.domain, '%s.%s' % (name, zone.domain), type)
+        action = '/v1/zones/%s/%s/%s' % (zone.domain, '%s.%s' %
+                                         (name, zone.domain), type)
         raw_data = {
             "answers": [
                 {
@@ -240,10 +256,12 @@ class NsOneDNSDriver(DNSDriver):
             raw_data['answers'] = extra.get('answers')
         post_data = json.dumps(raw_data)
         try:
-            response = self.connection.request(action=action, data=post_data, method='POST')
+            response = self.connection.request(action=action, data=post_data,
+                                               method='POST')
         except NsOneException, e:
             if e.message == 'record does not exist':
-                raise RecordDoesNotExistError(value=e.message, driver=self, id=record.id)
+                raise RecordDoesNotExistError(value=e.message, driver=self,
+                                              id=record.id)
             else:
                 raise e
         record = self._to_record(item=response.parse_body(), zone=zone)
@@ -274,8 +292,8 @@ class NsOneDNSDriver(DNSDriver):
             if key not in common_attr:
                 extra[key] = item.get(key)
 
-        zone = Zone(domain=item['zone'], id=item['id'], type=item.get('type'), extra=extra, ttl=extra.get('ttl'),
-                    driver=self)
+        zone = Zone(domain=item['zone'], id=item['id'], type=item.get('type'),
+                    extra=extra, ttl=extra.get('ttl'), driver=self)
 
         return zone
 


[14/17] libcloud git commit: fixes the lint

Posted by an...@apache.org.
fixes the lint


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/f2ad154d
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/f2ad154d
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/f2ad154d

Branch: refs/heads/trunk
Commit: f2ad154dd9856e39f88f812d2bd3e4af208574a8
Parents: 36b10f4
Author: lostbird <lostbird@lostbird.(none)>
Authored: Mon Mar 21 10:47:53 2016 +0100
Committer: anthony-shaw <an...@gmail.com>
Committed: Mon Mar 21 21:20:31 2016 +1100

----------------------------------------------------------------------
 libcloud/test/dns/test_nsone.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/f2ad154d/libcloud/test/dns/test_nsone.py
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/test_nsone.py b/libcloud/test/dns/test_nsone.py
index 8272c3f..1960faa 100644
--- a/libcloud/test/dns/test_nsone.py
+++ b/libcloud/test/dns/test_nsone.py
@@ -7,7 +7,7 @@ from libcloud.test.secrets import DNS_PARAMS_NSONE
 from libcloud.dns.drivers.nsone import NsOneDNSDriver
 from libcloud.utils.py3 import httplib
 from libcloud.dns.types import ZoneDoesNotExistError, ZoneAlreadyExistsError,\
-    RecordDoesNotExistError,  RecordType
+ RecordDoesNotExistError,  RecordType
 from libcloud.dns.base import Zone, Record
 
 


[12/17] libcloud git commit: implements delete_record method

Posted by an...@apache.org.
implements delete_record method


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/6ce9ff6b
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/6ce9ff6b
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/6ce9ff6b

Branch: refs/heads/trunk
Commit: 6ce9ff6b028e3ffa692d0ea5097cdc0cd696bd27
Parents: 0f278d9
Author: lostbird <lostbird@lostbird.(none)>
Authored: Tue Feb 23 11:33:55 2016 +0100
Committer: anthony-shaw <an...@gmail.com>
Committed: Mon Mar 21 21:20:31 2016 +1100

----------------------------------------------------------------------
 libcloud/dns/drivers/nsone.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/6ce9ff6b/libcloud/dns/drivers/nsone.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/nsone.py b/libcloud/dns/drivers/nsone.py
index 4e54491..69a38f4 100644
--- a/libcloud/dns/drivers/nsone.py
+++ b/libcloud/dns/drivers/nsone.py
@@ -142,7 +142,16 @@ class NsOneDNSDriver(DNSDriver):
         return record
 
     def delete_record(self, record):
-        pass
+        action = '/v1/zones/%s/%s/%s' % (record.zone.domain, record.name, record.type)
+        try:
+            response = self.connection.request(action=action, method='DELETE')
+        except NsOneException, e:
+            if e.message == 'record not found':
+                raise RecordDoesNotExistError(value=e.message, driver=self, record_id=record.id)
+            else:
+                raise e
+
+        return response.status == httplib.OK
 
     def create_record(self, name, zone, type, data, extra=None):
         action = '/v1/zones/%s/%s/%s' % (zone.domain, zone.domain, type)
@@ -150,13 +159,12 @@ class NsOneDNSDriver(DNSDriver):
             "answers": [
                 {
                     "answer": [
-                        10,
                         data
                     ], }
             ],
             "type": type,
             "domain": zone.domain,
-            "zone": zone
+            "zone": zone.domain
         }
 
         if extra is not None:


[17/17] libcloud git commit: Update changes for PR 710

Posted by an...@apache.org.
Update changes for PR 710


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/1a057c9c
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/1a057c9c
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/1a057c9c

Branch: refs/heads/trunk
Commit: 1a057c9c284994f97b178b3cdca30bf329a725e7
Parents: 4806a6a
Author: anthony-shaw <an...@gmail.com>
Authored: Mon Mar 21 21:22:52 2016 +1100
Committer: anthony-shaw <an...@gmail.com>
Committed: Mon Mar 21 21:22:52 2016 +1100

----------------------------------------------------------------------
 CHANGES.rst | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/1a057c9c/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index 1cc9377..c79163d 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -119,6 +119,10 @@ Loadbalancer
 DNS
 ~~~~
 
+- Added NSOne driver
+  [Oltjano Terpollari]
+  (GITHUB-710)
+
 - Fix a bug in the GoDaddy driver - make sure ``host`` attribute on the
   connection class is correctly set to the hostname.
   [Tomaz Muraus]


[02/17] libcloud git commit: fixes except syntax to suppot python3

Posted by an...@apache.org.
fixes except syntax to suppot python3


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/36b10f4b
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/36b10f4b
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/36b10f4b

Branch: refs/heads/trunk
Commit: 36b10f4bf9da0caa1d5fae033b38f898219e6645
Parents: 74e2bf7
Author: lostbird <lostbird@lostbird.(none)>
Authored: Wed Mar 16 01:28:55 2016 +0100
Committer: anthony-shaw <an...@gmail.com>
Committed: Mon Mar 21 21:20:31 2016 +1100

----------------------------------------------------------------------
 libcloud/dns/drivers/nsone.py | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/36b10f4b/libcloud/dns/drivers/nsone.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/nsone.py b/libcloud/dns/drivers/nsone.py
index 77442f2..06297e6 100644
--- a/libcloud/dns/drivers/nsone.py
+++ b/libcloud/dns/drivers/nsone.py
@@ -1,3 +1,4 @@
+import sys
 try:
     import simplejson as json
 except ImportError:
@@ -56,7 +57,8 @@ class NsOneDNSDriver(DNSDriver):
         action = '/v1/zones/%s' % zone_id
         try:
             response = self.connection.request(action=action, method='GET')
-        except NsOneException, e:
+        except NsOneException:
+            e = sys.exc_info()[1]
             if e.message == 'zone not found':
                 raise ZoneDoesNotExistError(value=e.message, driver=self,
                                             zone_id=zone_id)
@@ -92,7 +94,8 @@ class NsOneDNSDriver(DNSDriver):
         try:
             response = self.connection.request(action=action, method='PUT',
                                                data=post_data)
-        except NsOneException, e:
+        except NsOneException:
+            e = sys.exc_info()[1]
             if e.message == 'zone already exists':
                 raise ZoneAlreadyExistsError(value=e.message, driver=self,
                                              zone_id=domain)
@@ -117,7 +120,8 @@ class NsOneDNSDriver(DNSDriver):
         """
         try:
             response = self.connection.request(action=action, method='DELETE')
-        except NsOneException, e:
+        except NsOneException:
+            e = sys.exc_info()[1]
             if e.message == 'zone not found':
                 raise ZoneDoesNotExistError(value=e.message, driver=self,
                                             zone_id=zone.id)
@@ -136,7 +140,8 @@ class NsOneDNSDriver(DNSDriver):
         action = '/v1/zones/%s' % zone.domain
         try:
             response = self.connection.request(action=action, method='GET')
-        except NsOneException, e:
+        except NsOneException:
+            e = sys.exc_info()[1]
             if e.message == 'zone not found':
                 raise ZoneDoesNotExistError(value=e.message, driver=self,
                                             zone_id=zone.id)
@@ -160,7 +165,8 @@ class NsOneDNSDriver(DNSDriver):
         action = '/v1/zones/%s/%s/%s' % (zone_id, zone_id, record_id)
         try:
             response = self.connection.request(action=action, method='GET')
-        except NsOneException, e:
+        except NsOneException:
+            e = sys.exc_info()[1]
             if e.message == 'record not found':
                 raise RecordDoesNotExistError(value=e.message, driver=self,
                                               record_id=record_id)
@@ -182,7 +188,8 @@ class NsOneDNSDriver(DNSDriver):
                                          record.type)
         try:
             response = self.connection.request(action=action, method='DELETE')
-        except NsOneException, e:
+        except NsOneException:
+            e = sys.exc_info()[1]
             if e.message == 'record not found':
                 raise RecordDoesNotExistError(value=e.message, driver=self,
                                               record_id=record.id)
@@ -224,7 +231,8 @@ class NsOneDNSDriver(DNSDriver):
         try:
             response = self.connection.request(action=action, method='PUT',
                                                data=post_data)
-        except NsOneException, e:
+        except NsOneException:
+            e = sys.exc_info()[1]
             if e.message == 'record already exists':
                 raise RecordAlreadyExistsError(value=e.message, driver=self,
                                                record_id='')
@@ -265,7 +273,8 @@ class NsOneDNSDriver(DNSDriver):
         try:
             response = self.connection.request(action=action, data=post_data,
                                                method='POST')
-        except NsOneException, e:
+        except NsOneException:
+            e = sys.exc_info()[1]
             if e.message == 'record does not exist':
                 raise RecordDoesNotExistError(value=e.message, driver=self,
                                               id=record.id)


[05/17] libcloud git commit: adds dns support for ns1 provider

Posted by an...@apache.org.
adds dns support for ns1 provider


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/0f278d90
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/0f278d90
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/0f278d90

Branch: refs/heads/trunk
Commit: 0f278d9037f5c63469497c15a3ffda21503ba2ac
Parents: 8d012ca
Author: lostbird <lostbird@lostbird.(none)>
Authored: Mon Feb 22 16:15:29 2016 +0100
Committer: anthony-shaw <an...@gmail.com>
Committed: Mon Mar 21 21:20:31 2016 +1100

----------------------------------------------------------------------
 libcloud/common/nsone.py      |  60 ++++++++++
 libcloud/dns/drivers/nsone.py | 229 +++++++++++++++++++++++++++++++++++++
 libcloud/dns/types.py         |   1 +
 3 files changed, 290 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/0f278d90/libcloud/common/nsone.py
----------------------------------------------------------------------
diff --git a/libcloud/common/nsone.py b/libcloud/common/nsone.py
new file mode 100644
index 0000000..d1f1bbd
--- /dev/null
+++ b/libcloud/common/nsone.py
@@ -0,0 +1,60 @@
+from libcloud.common.base import ConnectionKey, JsonResponse
+
+
+__all__ = [
+    'API_HOST',
+    'NsOneException',
+    'NsOneResponse',
+    'NsOneConnection'
+]
+
+# Endpoint for nsone api
+API_HOST = 'api.nsone.net'
+
+
+class NsOneResponse(JsonResponse):
+    errors = []
+    objects = []
+
+    def __init__(self, response, connection):
+        super(NsOneResponse, self).__init__(response=response, connection=connection)
+        self.errors, self.objects = self.parse_body_and_errors()
+        if not self.success():
+            raise NsOneException(code=self.status, message=self.errors.pop()['message'])
+
+    def parse_body_and_errors(self):
+        js = super(NsOneResponse, self).parse_body()
+        if 'message' in js:
+            self.errors.append(js)
+        else:
+            self.objects.append(js)
+
+        return self.errors, self.objects
+
+    def success(self):
+        return len(self.errors) == 0
+
+
+class NsOneConnection(ConnectionKey):
+    host = API_HOST
+    responseCls = NsOneResponse
+
+    def add_default_headers(self, headers):
+        headers['Content-Type'] = 'application/json'
+        headers['X-NSONE-KEY'] = self.key
+
+        return headers
+
+
+class NsOneException(Exception):
+
+    def __init__(self, code, message):
+        self.code = code
+        self.message = message
+        self.args = (code, message)
+
+    def __str__(self):
+        return "%s %s" % (self.code, self.message)
+
+    def __repr__(self):
+        return "NsOneException %s %s" % (self.code, self.message)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/0f278d90/libcloud/dns/drivers/nsone.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/nsone.py b/libcloud/dns/drivers/nsone.py
new file mode 100644
index 0000000..4e54491
--- /dev/null
+++ b/libcloud/dns/drivers/nsone.py
@@ -0,0 +1,229 @@
+try:
+    import simplejson as json
+except ImportError:
+    import json
+
+from libcloud.utils.py3 import httplib
+from libcloud.dns.base import DNSDriver, Zone, Record, RecordType
+from libcloud.common.nsone import NsOneConnection, NsOneResponse, NsOneException
+from libcloud.dns.types import Provider, ZoneDoesNotExistError, ZoneAlreadyExistsError, RecordDoesNotExistError, \
+    RecordAlreadyExistsError
+
+
+__all__ = [
+    'NsOneDNSDriver'
+]
+
+
+class NsOneDNSResponse(NsOneResponse):
+    pass
+
+
+class NsOneDNSConnection(NsOneConnection):
+    responseCls = NsOneDNSResponse
+
+
+class NsOneDNSDriver(DNSDriver):
+    name = 'NS1 DNS'
+    website = 'https://ns1.com'
+    type = Provider.NSONE
+    connectionCls = NsOneDNSConnection
+
+    RECORD_TYPE_MAP = {
+        RecordType.A: 'A',
+        RecordType.AAAA: 'AAAA',
+        RecordType.CNAME: 'CNAME',
+        RecordType.MX: 'MX',
+        RecordType.NS: 'NS',
+        RecordType.PTR: 'PTR',
+        RecordType.SOA: 'SOA',
+        RecordType.SRV: 'SRV',
+        RecordType.TXT: 'TXT'
+    }
+
+    def list_zones(self):
+        action = '/v1/zones'
+        response = self.connection.request(action=action, method='GET')
+        zones = self._to_zones(items=response.parse_body())
+
+        return zones
+
+    def get_zone(self, zone_id):
+        action = '/v1/zones/%s' % zone_id
+        try:
+            response = self.connection.request(action=action, method='GET')
+        except NsOneException, e:
+            if e.message == 'zone not found':
+                raise ZoneDoesNotExistError(value=e.message, driver=self, zone_id=zone_id)
+            else:
+                raise e
+        zone = self._to_zone(response.objects[0])
+
+        return zone
+
+    def create_zone(self, domain, type='master', ttl=None, extra=None):
+        """
+        :param domain: Zone domain name (e.g. example.com)
+        :type domain: ``str``
+
+        :param type: Zone type (This is not really used. See API docs for extra
+          parameters)
+        :type type: ``str``
+
+        :param ttl: TTL for new records (This is used through the extra param)
+        :type ttl: ``int``
+
+        :param extra: Extra attributes that are specific to the driver such as ttl, nx_ttl. Read API docs for more.
+        :type extra: ``dict``
+
+        :rtype: :class:`Zone`
+        """
+        action = '/v1/zones/%s' % domain
+        raw_data = {'zone': domain}
+        if extra is not None:
+            raw_data.update(extra)
+        data = json.dumps(raw_data)
+        try:
+            response = self.connection.request(action=action, method='PUT', data=data)
+        except NsOneException, e:
+            if e.message == 'zone already exists':
+                raise ZoneAlreadyExistsError(value=e.message, driver=self, zone_id=domain)
+            else:
+                raise e
+
+        zone = self._to_zone(response.objects[0])
+
+        return zone
+
+    def delete_zone(self, zone):
+        action = '/v1/zones/%s' % zone.domain
+        zones_list = self.list_zones()
+        if not self.ex_zone_exists(zone_id=zone.id, zones_list=zones_list):
+            raise ZoneDoesNotExistError(value='', driver=self, zone_id=zone.id)
+
+        response = self.connection.request(action=action, method='DELETE')
+
+        return response.status == httplib.OK
+
+    def update_zone(self, zone, domain, type='master', ttl=None, extra=None):
+        pass
+
+    def list_records(self, zone):
+        """
+        :param zone: Zone to list records for.
+        :type zone: :class:`Zone`
+
+        :return: ``list`` of :class:`Record`
+        """
+        action = '/v1/zones/%s' % zone.domain
+        try:
+            response = self.connection.request(action=action, method='GET')
+        except NsOneException, e:
+            if e.message == 'zone not found':
+                raise ZoneDoesNotExistError(value=e.message, driver=self, zone_id=zone.id)
+            else:
+                raise e
+        records = self._to_records(items=response.parse_body()['records'], zone=zone)
+
+        return records
+
+    def get_record(self, zone_id, record_id):
+        action = '/v1/zones/%s/%s/%s' % (zone_id, zone_id, record_id)
+        try:
+            response = self.connection.request(action=action, method='GET')
+        except NsOneException, e:
+            if e.message == 'record not found':
+                raise RecordDoesNotExistError(value=e.message, driver=self, record_id=record_id)
+            else:
+                raise e
+        zone = self.get_zone(zone_id=zone_id)
+        record = self._to_record(item=response.objects[0], zone=zone)
+
+        return record
+
+    def delete_record(self, record):
+        pass
+
+    def create_record(self, name, zone, type, data, extra=None):
+        action = '/v1/zones/%s/%s/%s' % (zone.domain, zone.domain, type)
+        raw_data = {
+            "answers": [
+                {
+                    "answer": [
+                        10,
+                        data
+                    ], }
+            ],
+            "type": type,
+            "domain": zone.domain,
+            "zone": zone
+        }
+
+        if extra is not None:
+            raw_data.update(extra)
+        data = json.dumps(raw_data)
+        try:
+            response = self.connection.request(action=action, method='PUT', data=data)
+        except NsOneException, e:
+            if e.message == 'record already exists':
+                raise RecordAlreadyExistsError(value=e.message, driver=self, record_id='')
+
+        return response
+
+    def update_record(self, record, name, type, data, extra=None):
+        pass
+
+    def ex_zone_exists(self, zone_id, zones_list):
+        """
+        Function to check if a `Zone` object exists.
+        :param zone_id: ID of the `Zone` object.
+        :type zone_id: ``str``
+
+        :param zones_list: A list containing `Zone` objects.
+        :type zones_list: ``list``.
+
+        :rtype: Returns `True` or `False`.
+        """
+        zone_ids = []
+        for zone in zones_list:
+            zone_ids.append(zone.id)
+
+        return zone_id in zone_ids
+
+    def _to_zone(self, item):
+        common_attr = ['zone', 'id', 'type']
+        extra = {}
+        for key in item:
+            if key not in common_attr:
+                extra[key] = item.get(key)
+
+        zone = Zone(domain=item['zone'], id=item['id'], type=item.get('type'), extra=extra, ttl=extra.get('ttl'),
+                    driver=self)
+
+        return zone
+
+    def _to_zones(self, items):
+        zones = []
+        for item in items:
+            zones.append(self._to_zone(item))
+
+        return zones
+
+    def _to_record(self, item, zone):
+        common_attr = ['id', 'short_answers', 'domain', 'type']
+        extra = {}
+        for key in item:
+            if key not in common_attr:
+                extra[key] = item.get(key)
+        record = Record(id=item['id'], name=item['domain'], type=item['type'],
+                        data=item['short_answers'], zone=zone, driver=self,
+                        extra=extra)
+
+        return record
+
+    def _to_records(self, items, zone):
+        records = []
+        for item in items:
+            records.append(self._to_record(item, zone))
+
+        return records

http://git-wip-us.apache.org/repos/asf/libcloud/blob/0f278d90/libcloud/dns/types.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/types.py b/libcloud/dns/types.py
index dc504e4..2edd090 100644
--- a/libcloud/dns/types.py
+++ b/libcloud/dns/types.py
@@ -48,6 +48,7 @@ class Provider(object):
     DURABLEDNS = 'durabledns'
     GODADDY = 'godaddy'
     CLOUDFLARE = 'cloudflare'
+    NSONE = 'nsone'
 
     # Deprecated
     RACKSPACE_US = 'rackspace_us'


[11/17] libcloud git commit: fixes tests to pass

Posted by an...@apache.org.
fixes tests to pass


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/f5461827
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/f5461827
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/f5461827

Branch: refs/heads/trunk
Commit: f546182762dd00fc19d615a579f2be7b1026b0f5
Parents: fb10ec3
Author: lostbird <lostbird@lostbird.(none)>
Authored: Tue Mar 15 23:32:02 2016 +0100
Committer: anthony-shaw <an...@gmail.com>
Committed: Mon Mar 21 21:20:31 2016 +1100

----------------------------------------------------------------------
 libcloud/test/dns/test_nsone.py | 9 ---------
 1 file changed, 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/f5461827/libcloud/test/dns/test_nsone.py
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/test_nsone.py b/libcloud/test/dns/test_nsone.py
index 183a743..8272c3f 100644
--- a/libcloud/test/dns/test_nsone.py
+++ b/libcloud/test/dns/test_nsone.py
@@ -62,15 +62,6 @@ class NsOneTests(unittest.TestCase):
 
         self.assertTrue(status)
 
-    def test_get_zone_success(self):
-        NsOneMockHttp.type = 'GET_ZONE_SUCCESS'
-        zone = self.driver.get_zone(zone_id='getzone.com')
-
-        self.assertEqual(zone.id, '52051b2c9f782d58bb4df41b')
-        self.assertEqual(zone.domain, 'example.com')
-        self.assertEqual(zone.type, None)
-        self.assertEqual(zone.ttl, 3600)
-
     def test_get_zone_zone_does_not_exist(self):
         NsOneMockHttp.type = 'GET_ZONE_ZONE_DOES_NOT_EXIST'
         try:


[04/17] libcloud git commit: implements record methods

Posted by an...@apache.org.
implements record methods


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/5ae12642
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/5ae12642
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/5ae12642

Branch: refs/heads/trunk
Commit: 5ae12642e03e381aaa88e3c7ecd2aab21253fbc7
Parents: 6ce9ff6
Author: lostbird <lostbird@lostbird.(none)>
Authored: Thu Feb 25 11:26:07 2016 +0100
Committer: anthony-shaw <an...@gmail.com>
Committed: Mon Mar 21 21:20:31 2016 +1100

----------------------------------------------------------------------
 libcloud/dns/drivers/nsone.py | 107 +++++++++++++++++++++++++++++++------
 1 file changed, 90 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/5ae12642/libcloud/dns/drivers/nsone.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/nsone.py b/libcloud/dns/drivers/nsone.py
index 69a38f4..ae45924 100644
--- a/libcloud/dns/drivers/nsone.py
+++ b/libcloud/dns/drivers/nsone.py
@@ -2,7 +2,6 @@ try:
     import simplejson as json
 except ImportError:
     import json
-
 from libcloud.utils.py3 import httplib
 from libcloud.dns.base import DNSDriver, Zone, Record, RecordType
 from libcloud.common.nsone import NsOneConnection, NsOneResponse, NsOneException
@@ -49,6 +48,10 @@ class NsOneDNSDriver(DNSDriver):
         return zones
 
     def get_zone(self, zone_id):
+        """
+        :param zone_id: Zone domain name (e.g. example.com)
+        :return: :class:`Zone`
+        """
         action = '/v1/zones/%s' % zone_id
         try:
             response = self.connection.request(action=action, method='GET')
@@ -82,9 +85,9 @@ class NsOneDNSDriver(DNSDriver):
         raw_data = {'zone': domain}
         if extra is not None:
             raw_data.update(extra)
-        data = json.dumps(raw_data)
+        post_data = json.dumps(raw_data)
         try:
-            response = self.connection.request(action=action, method='PUT', data=data)
+            response = self.connection.request(action=action, method='PUT', data=post_data)
         except NsOneException, e:
             if e.message == 'zone already exists':
                 raise ZoneAlreadyExistsError(value=e.message, driver=self, zone_id=domain)
@@ -96,6 +99,12 @@ class NsOneDNSDriver(DNSDriver):
         return zone
 
     def delete_zone(self, zone):
+        """
+        :param zone: Zone to be deleted.
+        :type zone: :class:`Zone`
+
+        :return: Boolean
+        """
         action = '/v1/zones/%s' % zone.domain
         zones_list = self.list_zones()
         if not self.ex_zone_exists(zone_id=zone.id, zones_list=zones_list):
@@ -105,9 +114,6 @@ class NsOneDNSDriver(DNSDriver):
 
         return response.status == httplib.OK
 
-    def update_zone(self, zone, domain, type='master', ttl=None, extra=None):
-        pass
-
     def list_records(self, zone):
         """
         :param zone: Zone to list records for.
@@ -128,6 +134,13 @@ class NsOneDNSDriver(DNSDriver):
         return records
 
     def get_record(self, zone_id, record_id):
+        """
+        :param zone_id: The id of the zone where to search for the record (e.g. example.com)
+        :type zone_id: ``str``
+        :param record_id: The type of record to search for (e.g. A, AAA, MX etc)
+
+        :return: :class:`Record`
+        """
         action = '/v1/zones/%s/%s/%s' % (zone_id, zone_id, record_id)
         try:
             response = self.connection.request(action=action, method='GET')
@@ -142,6 +155,12 @@ class NsOneDNSDriver(DNSDriver):
         return record
 
     def delete_record(self, record):
+        """
+        :param record: Record to delete.
+        :type record: :class:`Record`
+
+        :return: Boolean
+        """
         action = '/v1/zones/%s/%s/%s' % (record.zone.domain, record.name, record.type)
         try:
             response = self.connection.request(action=action, method='DELETE')
@@ -154,7 +173,20 @@ class NsOneDNSDriver(DNSDriver):
         return response.status == httplib.OK
 
     def create_record(self, name, zone, type, data, extra=None):
-        action = '/v1/zones/%s/%s/%s' % (zone.domain, zone.domain, type)
+        """
+        :param name: Name of the record to create (e.g. foo).
+        :type name: ``str``
+        :param zone: Zone where the record should be created.
+        :type zone: :class:`Zone`
+        :param type: Type of record (e.g. A, MX etc)
+        :type type: ``str``
+        :param data: Data of the record (e.g. 127.0.0.1 for the A record)
+        :type data: ``str``
+        :param extra: Extra data needed to create different types of records
+        :type extra: ``dict``
+        :return: :class:`Record`
+        """
+        action = '/v1/zones/%s/%s/%s' % (zone.domain, '%s.%s' % (name, zone.domain), type)
         raw_data = {
             "answers": [
                 {
@@ -163,23 +195,60 @@ class NsOneDNSDriver(DNSDriver):
                     ], }
             ],
             "type": type,
-            "domain": zone.domain,
+            "domain": '%s.%s' % (name, zone.domain),
             "zone": zone.domain
         }
-
-        if extra is not None:
-            raw_data.update(extra)
-        data = json.dumps(raw_data)
+        if extra is not None and extra.get('answers'):
+            raw_data['answers'] = extra.get('answers')
+        post_data = json.dumps(raw_data)
         try:
-            response = self.connection.request(action=action, method='PUT', data=data)
+            response = self.connection.request(action=action, method='PUT', data=post_data)
         except NsOneException, e:
             if e.message == 'record already exists':
                 raise RecordAlreadyExistsError(value=e.message, driver=self, record_id='')
+            else:
+                raise e
+        record = self._to_record(item=response.parse_body(), zone=zone)
 
-        return response
+        return record
 
     def update_record(self, record, name, type, data, extra=None):
-        pass
+        """
+        :param record: Record to update
+        :type record: :class:`Record`
+        :param name: Name of the record to update (e.g. foo).
+        :type name: ``str``
+        :param type: Type of record (e.g. A, MX etc)
+        :type type: ``str``
+        :param data: Data of the record (e.g. 127.0.0.1 for the A record)
+        :type data: ``str``
+        :param extra: Extra data needed to create different types of records
+        :type extra: ``dict``
+        :return: :class:`Record`
+        """
+        zone = record.zone
+        action = '/v1/zones/%s/%s/%s' % (zone.domain, '%s.%s' % (name, zone.domain), type)
+        raw_data = {
+            "answers": [
+                {
+                    "answer": [
+                        data
+                    ], }
+            ]
+        }
+        if extra is not None and extra.get('answers'):
+            raw_data['answers'] = extra.get('answers')
+        post_data = json.dumps(raw_data)
+        try:
+            response = self.connection.request(action=action, data=post_data, method='POST')
+        except NsOneException, e:
+            if e.message == 'record does not exist':
+                raise RecordDoesNotExistError(value=e.message, driver=self, id=record.id)
+            else:
+                raise e
+        record = self._to_record(item=response.parse_body(), zone=zone)
+
+        return record
 
     def ex_zone_exists(self, zone_id, zones_list):
         """
@@ -218,13 +287,17 @@ class NsOneDNSDriver(DNSDriver):
         return zones
 
     def _to_record(self, item, zone):
-        common_attr = ['id', 'short_answers', 'domain', 'type']
+        common_attr = ['id', 'short_answers', 'answers', 'domain', 'type']
         extra = {}
         for key in item:
             if key not in common_attr:
                 extra[key] = item.get(key)
+        if item.get('answers') is not None:
+            data = item.get('answers')[0]['answer']
+        else:
+            data = item.get('short_answers')
         record = Record(id=item['id'], name=item['domain'], type=item['type'],
-                        data=item['short_answers'], zone=zone, driver=self,
+                        data=data, zone=zone, driver=self,
                         extra=extra)
 
         return record


[15/17] libcloud git commit: adds secrets.py

Posted by an...@apache.org.
adds secrets.py


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/da7d9bd2
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/da7d9bd2
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/da7d9bd2

Branch: refs/heads/trunk
Commit: da7d9bd212512b982d6dd8b1a329c52162f33d01
Parents: f546182
Author: lostbird <lostbird@lostbird.(none)>
Authored: Tue Mar 15 23:44:39 2016 +0100
Committer: anthony-shaw <an...@gmail.com>
Committed: Mon Mar 21 21:20:31 2016 +1100

----------------------------------------------------------------------
 libcloud/test/secrets.py | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/da7d9bd2/libcloud/test/secrets.py
----------------------------------------------------------------------
diff --git a/libcloud/test/secrets.py b/libcloud/test/secrets.py
new file mode 100644
index 0000000..5b228bc
--- /dev/null
+++ b/libcloud/test/secrets.py
@@ -0,0 +1 @@
+DNS_PARAMS_NSONE = ('key', )


[03/17] libcloud git commit: updates test/secrets-dist

Posted by an...@apache.org.
updates test/secrets-dist


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/74e2bf7d
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/74e2bf7d
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/74e2bf7d

Branch: refs/heads/trunk
Commit: 74e2bf7d6156d74828cf6254a9ce89c068973773
Parents: da7d9bd
Author: lostbird <lostbird@lostbird.(none)>
Authored: Wed Mar 16 00:00:28 2016 +0100
Committer: anthony-shaw <an...@gmail.com>
Committed: Mon Mar 21 21:20:31 2016 +1100

----------------------------------------------------------------------
 libcloud/test/secrets.py-dist | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/74e2bf7d/libcloud/test/secrets.py-dist
----------------------------------------------------------------------
diff --git a/libcloud/test/secrets.py-dist b/libcloud/test/secrets.py-dist
index 879e8d5..480ac3f 100644
--- a/libcloud/test/secrets.py-dist
+++ b/libcloud/test/secrets.py-dist
@@ -84,6 +84,7 @@ DNS_PARAMS_DURABLEDNS = ('api_user', 'api_key')
 DNS_PARAMS_GODADDY = ('customer-id', 'api_user', 'api_key')
 DNS_PARAMS_CLOUDFLARE = ('user@example.com', 'key')
 DNS_PARAMS_AURORADNS = ('apikey', 'secretkey')
+DNS_PARAMS_NSONE = ('key', )
 
 # Container
 CONTAINER_PARAMS_DOCKER = ('user', 'password')


[16/17] libcloud git commit: fixes lint Closes #710

Posted by an...@apache.org.
fixes lint
Closes #710


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/4806a6ac
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/4806a6ac
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/4806a6ac

Branch: refs/heads/trunk
Commit: 4806a6ac428a0e3405aff900ecf4dfd5b1fa584a
Parents: fbf56cf
Author: lostbird <lostbird@lostbird.(none)>
Authored: Mon Mar 21 11:15:16 2016 +0100
Committer: anthony-shaw <an...@gmail.com>
Committed: Mon Mar 21 21:20:40 2016 +1100

----------------------------------------------------------------------
 libcloud/test/dns/test_nsone.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/4806a6ac/libcloud/test/dns/test_nsone.py
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/test_nsone.py b/libcloud/test/dns/test_nsone.py
index ddc82b0..9387542 100644
--- a/libcloud/test/dns/test_nsone.py
+++ b/libcloud/test/dns/test_nsone.py
@@ -7,7 +7,7 @@ from libcloud.test.secrets import DNS_PARAMS_NSONE
 from libcloud.dns.drivers.nsone import NsOneDNSDriver
 from libcloud.utils.py3 import httplib
 from libcloud.dns.types import ZoneDoesNotExistError, ZoneAlreadyExistsError,\
- RecordDoesNotExistError, RecordType
+    RecordDoesNotExistError, RecordType
 from libcloud.dns.base import Zone, Record
 
 


[07/17] libcloud git commit: adds unittest for nsone dns driver

Posted by an...@apache.org.
adds unittest for nsone dns driver


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/7a9018b0
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/7a9018b0
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/7a9018b0

Branch: refs/heads/trunk
Commit: 7a9018b0739cc366babc64bb430291c4a7681fad
Parents: 990749b
Author: lostbird <lostbird@lostbird.(none)>
Authored: Wed Mar 2 11:49:36 2016 +0100
Committer: anthony-shaw <an...@gmail.com>
Committed: Mon Mar 21 21:20:31 2016 +1100

----------------------------------------------------------------------
 .../dns/fixtures/nsone/empty_zones_list.json    |  1 +
 .../test/dns/fixtures/nsone/list_zones.json     |  0
 libcloud/test/dns/test_nsone.py                 | 34 ++++++++++++++++++++
 3 files changed, 35 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/7a9018b0/libcloud/test/dns/fixtures/nsone/empty_zones_list.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/nsone/empty_zones_list.json b/libcloud/test/dns/fixtures/nsone/empty_zones_list.json
new file mode 100644
index 0000000..0637a08
--- /dev/null
+++ b/libcloud/test/dns/fixtures/nsone/empty_zones_list.json
@@ -0,0 +1 @@
+[]
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/7a9018b0/libcloud/test/dns/fixtures/nsone/list_zones.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/nsone/list_zones.json b/libcloud/test/dns/fixtures/nsone/list_zones.json
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/libcloud/blob/7a9018b0/libcloud/test/dns/test_nsone.py
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/test_nsone.py b/libcloud/test/dns/test_nsone.py
new file mode 100644
index 0000000..6edf09d
--- /dev/null
+++ b/libcloud/test/dns/test_nsone.py
@@ -0,0 +1,34 @@
+import sys
+import unittest
+
+from libcloud.test import MockHttp
+from libcloud.test.file_fixtures import DNSFileFixtures
+from libcloud.test.secrets import DNS_PARAMS_NSONE
+from libcloud.dns.drivers.nsone import NsOneDNSDriver
+from libcloud.utils.py3 import httplib
+
+
+class NsOneTests(unittest.TestCase):
+    def setUp(self):
+        NsOneMockHttp.type = None
+        NsOneDNSDriver.connectionCls.conn_classes = (None, NsOneMockHttp)
+        self.driver = NsOneDNSDriver(*DNS_PARAMS_NSONE)
+
+    def test_list_zones_empty(self):
+        NsOneMockHttp.type = 'EMPTY_ZONES_LIST'
+        zones = self.driver.list_zones()
+
+        self.assertEqual(zones, [])
+
+
+class NsOneMockHttp(MockHttp):
+    fixtures = DNSFileFixtures('nsone')
+
+    def _v1_zones_EMPTY_ZONES_LIST(self, method, url, body, headers):
+        body = self.fixtures.load('empty_zones_list.json')
+
+        return httplib.OK, body, {}, httplib.responses[httplib.OK]
+
+
+if __name__ == '__main__':
+    sys.exit(unittest.main())


[10/17] libcloud git commit: flake8 the tests code

Posted by an...@apache.org.
flake8 the tests code


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/fb10ec34
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/fb10ec34
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/fb10ec34

Branch: refs/heads/trunk
Commit: fb10ec34324b43ff84da5299f8043ff4bc0ee982
Parents: 2463fb8
Author: lostbird <lostbird@lostbird.(none)>
Authored: Tue Mar 15 23:03:04 2016 +0100
Committer: anthony-shaw <an...@gmail.com>
Committed: Mon Mar 21 21:20:31 2016 +1100

----------------------------------------------------------------------
 .../dns/fixtures/nsone/create_zone_success.json |  2 +-
 .../dns/fixtures/nsone/empty_zones_list.json    |  2 +-
 .../dns/fixtures/nsone/get_record_success.json  |  2 +-
 .../dns/fixtures/nsone/get_zone_success.json    |  2 +-
 .../dns/fixtures/nsone/list_records_empty.json  |  2 +-
 .../test/dns/fixtures/nsone/list_zones.json     |  2 +-
 .../fixtures/nsone/record_does_not_exist.json   |  2 +-
 .../dns/fixtures/nsone/zone_already_exists.json |  2 +-
 .../dns/fixtures/nsone/zone_does_not_exist.json |  2 +-
 libcloud/test/dns/test_nsone.py                 | 46 +++++++++++++-------
 10 files changed, 39 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/fb10ec34/libcloud/test/dns/fixtures/nsone/create_zone_success.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/nsone/create_zone_success.json b/libcloud/test/dns/fixtures/nsone/create_zone_success.json
index bc20afe..562453b 100644
--- a/libcloud/test/dns/fixtures/nsone/create_zone_success.json
+++ b/libcloud/test/dns/fixtures/nsone/create_zone_success.json
@@ -35,4 +35,4 @@
     }
   ],
   "meta": {}
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/fb10ec34/libcloud/test/dns/fixtures/nsone/empty_zones_list.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/nsone/empty_zones_list.json b/libcloud/test/dns/fixtures/nsone/empty_zones_list.json
index 0637a08..fe51488 100644
--- a/libcloud/test/dns/fixtures/nsone/empty_zones_list.json
+++ b/libcloud/test/dns/fixtures/nsone/empty_zones_list.json
@@ -1 +1 @@
-[]
\ No newline at end of file
+[]

http://git-wip-us.apache.org/repos/asf/libcloud/blob/fb10ec34/libcloud/test/dns/fixtures/nsone/get_record_success.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/nsone/get_record_success.json b/libcloud/test/dns/fixtures/nsone/get_record_success.json
index 9644017..74d3155 100644
--- a/libcloud/test/dns/fixtures/nsone/get_record_success.json
+++ b/libcloud/test/dns/fixtures/nsone/get_record_success.json
@@ -114,4 +114,4 @@
   ],
   "ttl": 60,
   "use_client_subnet": true
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/fb10ec34/libcloud/test/dns/fixtures/nsone/get_zone_success.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/nsone/get_zone_success.json b/libcloud/test/dns/fixtures/nsone/get_zone_success.json
index 25a5800..7313bd4 100644
--- a/libcloud/test/dns/fixtures/nsone/get_zone_success.json
+++ b/libcloud/test/dns/fixtures/nsone/get_zone_success.json
@@ -45,4 +45,4 @@
     }
   ],
   "meta": {}
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/fb10ec34/libcloud/test/dns/fixtures/nsone/list_records_empty.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/nsone/list_records_empty.json b/libcloud/test/dns/fixtures/nsone/list_records_empty.json
index 6d6c8c9..9abb003 100644
--- a/libcloud/test/dns/fixtures/nsone/list_records_empty.json
+++ b/libcloud/test/dns/fixtures/nsone/list_records_empty.json
@@ -21,4 +21,4 @@
   },
   "records": [],
   "meta": {}
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/fb10ec34/libcloud/test/dns/fixtures/nsone/list_zones.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/nsone/list_zones.json b/libcloud/test/dns/fixtures/nsone/list_zones.json
index 8d7433a..4eb1ed4 100644
--- a/libcloud/test/dns/fixtures/nsone/list_zones.json
+++ b/libcloud/test/dns/fixtures/nsone/list_zones.json
@@ -37,4 +37,4 @@
     "meta": {},
     "hostmaster": "hostmaster@nsone.net"
   }
-]
\ No newline at end of file
+]

http://git-wip-us.apache.org/repos/asf/libcloud/blob/fb10ec34/libcloud/test/dns/fixtures/nsone/record_does_not_exist.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/nsone/record_does_not_exist.json b/libcloud/test/dns/fixtures/nsone/record_does_not_exist.json
index 0aef49e..f1f6230 100644
--- a/libcloud/test/dns/fixtures/nsone/record_does_not_exist.json
+++ b/libcloud/test/dns/fixtures/nsone/record_does_not_exist.json
@@ -1 +1 @@
-{"message":"record not found"}
\ No newline at end of file
+{"message":"record not found"}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/fb10ec34/libcloud/test/dns/fixtures/nsone/zone_already_exists.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/nsone/zone_already_exists.json b/libcloud/test/dns/fixtures/nsone/zone_already_exists.json
index 3340a53..e556286 100644
--- a/libcloud/test/dns/fixtures/nsone/zone_already_exists.json
+++ b/libcloud/test/dns/fixtures/nsone/zone_already_exists.json
@@ -1 +1 @@
-{"message":"zone already exists"}
\ No newline at end of file
+{"message":"zone already exists"}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/fb10ec34/libcloud/test/dns/fixtures/nsone/zone_does_not_exist.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/nsone/zone_does_not_exist.json b/libcloud/test/dns/fixtures/nsone/zone_does_not_exist.json
index ffe02d2..4e95409 100644
--- a/libcloud/test/dns/fixtures/nsone/zone_does_not_exist.json
+++ b/libcloud/test/dns/fixtures/nsone/zone_does_not_exist.json
@@ -1 +1 @@
-{"message":"zone not found"}
\ No newline at end of file
+{"message":"zone not found"}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/fb10ec34/libcloud/test/dns/test_nsone.py
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/test_nsone.py b/libcloud/test/dns/test_nsone.py
index f3c16f7..183a743 100644
--- a/libcloud/test/dns/test_nsone.py
+++ b/libcloud/test/dns/test_nsone.py
@@ -7,7 +7,7 @@ from libcloud.test.secrets import DNS_PARAMS_NSONE
 from libcloud.dns.drivers.nsone import NsOneDNSDriver
 from libcloud.utils.py3 import httplib
 from libcloud.dns.types import ZoneDoesNotExistError, ZoneAlreadyExistsError,\
-    RecordDoesNotExistError, RecordAlreadyExistsError, RecordType
+    RecordDoesNotExistError,  RecordType
 from libcloud.dns.base import Zone, Record
 
 
@@ -102,7 +102,7 @@ class NsOneTests(unittest.TestCase):
             self.fail('Exception was not thrown')
 
     def test_get_record_record_does_not_exist(self):
-        NsOneMockHttp.type = 'GET_RECORD_RECORD_DOES_NOT_EXIST'
+        NsOneMockHttp.type = 'GET_RECORD_DOES_NOT_EXIST'
 
         try:
             self.driver.get_record(zone_id='getrecord.com', record_id='A')
@@ -180,72 +180,86 @@ class NsOneMockHttp(MockHttp):
 
         return httplib.OK, body, {}, httplib.responses[httplib.OK]
 
-    def _v1_zones_getzone_com_GET_ZONE_SUCCESS(self, method, url, body, headers):
+    def _v1_zones_getzone_com_GET_ZONE_SUCCESS(self, method, url, body,
+                                               headers):
         body = self.fixtures.load('get_zone_success.json')
 
         return httplib.OK, body, {}, httplib.responses[httplib.OK]
 
-    def _v1_zones_zonedoesnotexist_com_GET_ZONE_ZONE_DOES_NOT_EXIST(self, method, url, body, headers):
+    def _v1_zones_zonedoesnotexist_com_GET_ZONE_ZONE_DOES_NOT_EXIST(
+            self, method, url, body, headers):
         body = self.fixtures.load('zone_does_not_exist.json')
 
         return 404, body, {}, httplib.responses[httplib.OK]
 
-    def _v1_zones_test_com_DELETE_ZONE_SUCCESS(self, method, url, body, headers):
+    def _v1_zones_test_com_DELETE_ZONE_SUCCESS(
+            self, method, url, body, headers):
         body = self.fixtures.load('delete_zone_success.json')
 
         return httplib.OK, body, {}, httplib.responses[httplib.OK]
 
-    def _v1_zones_test_com_DELETE_ZONE_ZONE_DOES_NOT_EXIST(self, method, url, body, headers):
+    def _v1_zones_test_com_DELETE_ZONE_ZONE_DOES_NOT_EXIST(
+            self, method, url, body, headers):
         body = self.fixtures.load('zone_does_not_exist.json')
 
         return httplib.OK, body, {}, httplib.responses[httplib.OK]
 
-    def _v1_zones_newzone_com_CREATE_ZONE_SUCCESS(self, method, url, body, headers):
+    def _v1_zones_newzone_com_CREATE_ZONE_SUCCESS(self, method,
+                                                  url, body, headers):
         body = self.fixtures.load('create_zone_success.json')
 
         return httplib.OK, body, {}, httplib.responses[httplib.OK]
 
-    def _v1_zones_newzone_com_CREATE_ZONE_ZONE_ALREADY_EXISTS(self, method, url, body, headers):
+    def _v1_zones_newzone_com_CREATE_ZONE_ZONE_ALREADY_EXISTS(
+            self, method, url, body, headers):
         body = self.fixtures.load('zone_already_exists.json')
 
         return httplib.OK, body, {}, httplib.responses[httplib.OK]
 
-    def _v1_zones_test_com_LIST_RECORDS_SUCCESS(self, method, url, body, headers):
+    def _v1_zones_test_com_LIST_RECORDS_SUCCESS(
+            self, method, url, body, headers):
         body = self.fixtures.load('get_zone_success.json')
 
         return httplib.OK, body, {}, httplib.responses[httplib.OK]
 
-    def _v1_zones_test_com_LIST_RECORDS_EMPTY(self, method, url, body, headers):
+    def _v1_zones_test_com_LIST_RECORDS_EMPTY(
+            self, method, url, body, headers):
         body = self.fixtures.load('list_records_empty.json')
 
         return httplib.OK, body, {}, httplib.responses[httplib.OK]
 
-    def _v1_zones_test_com_LIST_RECORDS_ZONE_DOES_NOT_EXIST(self, method, url, body, headers):
+    def _v1_zones_test_com_LIST_RECORDS_ZONE_DOES_NOT_EXIST(
+            self, method, url, body, headers):
         body = self.fixtures.load('zone_does_not_exist.json')
 
         return httplib.OK, body, {}, httplib.responses[httplib.OK]
 
-    def _v1_zones_test_com_example_com_A_DELETE_RECORD_RECORD_DOES_NOT_EXIST(self, method, url, body, headers):
+    def _v1_zones_test_com_example_com_A_DELETE_RECORD_RECORD_DOES_NOT_EXIST(
+            self, method, url, body, headers):
         body = self.fixtures.load('record_does_not_exist.json')
 
         return 404, body, {}, httplib.responses[httplib.OK]
 
-    def _v1_zones_test_com_example_com_A_DELETE_RECORD_SUCCESS(self, method, url, body, headers):
+    def _v1_zones_test_com_example_com_A_DELETE_RECORD_SUCCESS(
+            self, method, url, body, headers):
         body = self.fixtures.load('delete_record_success.json')
 
         return httplib.OK, body, {}, httplib.responses[httplib.OK]
 
-    def _v1_zones_getrecord_com_getrecord_com_A_GET_RECORD_SUCCESS(self, method, url, body, headers):
+    def _v1_zones_getrecord_com_getrecord_com_A_GET_RECORD_SUCCESS(
+            self, method, url, body, headers):
         body = self.fixtures.load('get_record_success.json')
 
         return httplib.OK, body, {}, httplib.responses[httplib.OK]
 
-    def _v1_zones_getrecord_com_GET_RECORD_SUCCESS(self, method, url, body, headers):
+    def _v1_zones_getrecord_com_GET_RECORD_SUCCESS(
+            self, method, url, body, headers):
         body = self.fixtures.load('get_zone_success.json')
 
         return httplib.OK, body, {}, httplib.responses[httplib.OK]
 
-    def _v1_zones_getrecord_com_getrecord_com_A_GET_RECORD_RECORD_DOES_NOT_EXIST(self, method, url, body, headers):
+    def _v1_zones_getrecord_com_getrecord_com_A_GET_RECORD_DOES_NOT_EXIST(
+            self, method, url, body, headers):
         body = self.fixtures.load('record_does_not_exist.json')
 
         return httplib.OK, body, {}, httplib.responses[httplib.OK]


[09/17] libcloud git commit: adds unittests for nsone driver

Posted by an...@apache.org.
adds unittests for nsone driver


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/2463fb84
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/2463fb84
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/2463fb84

Branch: refs/heads/trunk
Commit: 2463fb84d59ac822ece432a33a83d6f97bdfcf1b
Parents: 7a9018b
Author: lostbird <lostbird@lostbird.(none)>
Authored: Wed Mar 9 01:32:03 2016 +0100
Committer: anthony-shaw <an...@gmail.com>
Committed: Mon Mar 21 21:20:31 2016 +1100

----------------------------------------------------------------------
 libcloud/dns/drivers/nsone.py                   |  15 +-
 .../dns/fixtures/nsone/create_zone_success.json |  38 ++++
 .../fixtures/nsone/delete_record_success.json   |   0
 .../dns/fixtures/nsone/delete_zone_success.json |   0
 .../dns/fixtures/nsone/get_record_success.json  | 117 ++++++++++
 .../dns/fixtures/nsone/get_zone_success.json    |  48 ++++
 .../dns/fixtures/nsone/list_records_empty.json  |  24 ++
 .../test/dns/fixtures/nsone/list_zones.json     |  40 ++++
 .../fixtures/nsone/record_does_not_exist.json   |   1 +
 .../dns/fixtures/nsone/zone_already_exists.json |   1 +
 .../dns/fixtures/nsone/zone_does_not_exist.json |   1 +
 libcloud/test/dns/test_nsone.py                 | 220 +++++++++++++++++++
 12 files changed, 501 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/2463fb84/libcloud/dns/drivers/nsone.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/nsone.py b/libcloud/dns/drivers/nsone.py
index 3de153d..77442f2 100644
--- a/libcloud/dns/drivers/nsone.py
+++ b/libcloud/dns/drivers/nsone.py
@@ -111,11 +111,18 @@ class NsOneDNSDriver(DNSDriver):
         :return: Boolean
         """
         action = '/v1/zones/%s' % zone.domain
-        zones_list = self.list_zones()
+        """zones_list = self.list_zones()
         if not self.ex_zone_exists(zone_id=zone.id, zones_list=zones_list):
             raise ZoneDoesNotExistError(value='', driver=self, zone_id=zone.id)
-
-        response = self.connection.request(action=action, method='DELETE')
+        """
+        try:
+            response = self.connection.request(action=action, method='DELETE')
+        except NsOneException, e:
+            if e.message == 'zone not found':
+                raise ZoneDoesNotExistError(value=e.message, driver=self,
+                                            zone_id=zone.id)
+            else:
+                raise e
 
         return response.status == httplib.OK
 
@@ -160,7 +167,7 @@ class NsOneDNSDriver(DNSDriver):
             else:
                 raise e
         zone = self.get_zone(zone_id=zone_id)
-        record = self._to_record(item=response.objects[0], zone=zone)
+        record = self._to_record(item=response.parse_body(), zone=zone)
 
         return record
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2463fb84/libcloud/test/dns/fixtures/nsone/create_zone_success.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/nsone/create_zone_success.json b/libcloud/test/dns/fixtures/nsone/create_zone_success.json
new file mode 100644
index 0000000..bc20afe
--- /dev/null
+++ b/libcloud/test/dns/fixtures/nsone/create_zone_success.json
@@ -0,0 +1,38 @@
+{
+  "id": "52051b2c9f782d58bb4df41b",
+  "hostmaster": "hostmaster@nsone.net",
+  "ttl": 3600,
+  "nx_ttl": 60,
+  "retry": 7200,
+  "zone": "newzone.com",
+  "refresh": 43200,
+  "expiry": 1209600,
+  "dns_servers": [
+    "dns1.p06.nsone.net",
+    "dns2.p06.nsone.net",
+    "dns3.p06.nsone.net",
+    "dns4.p06.nsone.net"
+  ],
+  "networks": [0],
+  "network_pools": ["p06"],
+  "primary": {
+    "enabled": false,
+    "secondaries": []
+  },
+  "records": [
+    {
+      "id": "52051b2c9f782d58bb4df420",
+      "type": "NS",
+      "tier": 1,
+      "ttl": 3600,
+      "short_answers": [
+        "dns1.p06.nsone.net",
+        "dns2.p06.nsone.net",
+        "dns3.p06.nsone.net",
+        "dns4.p06.nsone.net"
+      ],
+      "domain": "newzone.com"
+    }
+  ],
+  "meta": {}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2463fb84/libcloud/test/dns/fixtures/nsone/delete_record_success.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/nsone/delete_record_success.json b/libcloud/test/dns/fixtures/nsone/delete_record_success.json
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2463fb84/libcloud/test/dns/fixtures/nsone/delete_zone_success.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/nsone/delete_zone_success.json b/libcloud/test/dns/fixtures/nsone/delete_zone_success.json
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2463fb84/libcloud/test/dns/fixtures/nsone/get_record_success.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/nsone/get_record_success.json b/libcloud/test/dns/fixtures/nsone/get_record_success.json
new file mode 100644
index 0000000..9644017
--- /dev/null
+++ b/libcloud/test/dns/fixtures/nsone/get_record_success.json
@@ -0,0 +1,117 @@
+{
+  "id": "520519509f782d58bb4df419",
+  "networks": [0],
+  "type": "A",
+  "tier": 3,
+  "domain": "www.example.com",
+  "zone": "example.com",
+  "answers": [
+    {
+      "id": "520519509f782d58bb4df418",
+      "feeds": [
+        {
+          "source": "a53252f9e583c6708331a1daeb172e12",
+          "feed": "520533b89f782d5b1a10a851"
+        }
+      ],
+      "answer": [
+        "1.1.1.1"
+      ],
+      "meta": {
+        "up": { "feed": "520533b89f782d5b1a10a851" },
+        "priority": 1
+      },
+      "region": "us-east"
+    },
+    {
+      "id": "5205338e9f782d5b1a10a84e",
+      "feeds": [
+        {
+          "source": "a53252f9e583c6708331a1daeb172e12",
+          "feed": "520533c09f782d5b1a10a852"
+        }
+      ],
+      "answer": [
+        "2.2.2.2"
+      ],
+      "meta": {
+        "up": { "feed": "520533b89f782d5b1a10a852" },
+        "priority": 2
+      },
+      "region": "us-east"
+    },
+    {
+      "id": "5205338e9f782d5b1a10a84f",
+      "feeds": [
+        {
+          "source": "a53252f9e583c6708331a1daeb172e12",
+          "feed": "520533dc9f782d5b1a10a854"
+        }
+      ],
+      "answer": [
+        "8.8.8.8"
+      ],
+      "meta": {
+        "up": { "feed": "520533b89f782d5b1a10a854" },
+        "priority": 3
+      },
+      "region": "us-west"
+    },
+    {
+      "id": "5205338e9f782d5b1a10a850",
+      "feeds": [
+        {
+          "source": "a53252f9e583c6708331a1daeb172e12",
+          "feed": "520533e49f782d5b1a10a855"
+        }
+      ],
+      "answer": [
+        "9.9.9.9"
+      ],
+      "meta": {
+        "up": { "feed": "520533b89f782d5b1a10a855" },
+        "priority": 3
+      },
+      "region": "us-west"
+    }
+  ],
+  "regions": {
+    "us-east": {
+      "meta": {
+        "georegion": ["US-EAST"]
+      }
+    },
+    "us-west": {
+      "meta": {
+        "georegion": ["US-WEST"]
+      }
+    }
+  },
+  "meta": {},
+  "filters": [
+    {
+      "config": {},
+      "filter": "up"
+    },
+    {
+      "config": {},
+      "filter": "geotarget_regional"
+    },
+    {
+      "config": {},
+      "filter": "select_first_region"
+    },
+    {
+      "config": {},
+      "filter": "weighted_shuffle"
+    },
+    {
+      "config": {
+        "N": 1
+      },
+      "filter": "select_first_n"
+    }
+  ],
+  "ttl": 60,
+  "use_client_subnet": true
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2463fb84/libcloud/test/dns/fixtures/nsone/get_zone_success.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/nsone/get_zone_success.json b/libcloud/test/dns/fixtures/nsone/get_zone_success.json
new file mode 100644
index 0000000..25a5800
--- /dev/null
+++ b/libcloud/test/dns/fixtures/nsone/get_zone_success.json
@@ -0,0 +1,48 @@
+{
+  "id": "520422af9f782d37dffb588b",
+  "hostmaster": "hostmaster@nsone.net",
+  "ttl": 3600,
+  "nx_ttl": 3600,
+  "retry": 7200,
+  "zone": "example.com",
+  "refresh": 43200,
+  "expiry": 1209600,
+  "dns_servers": [
+    "dns1.p03.nsone.net",
+    "dns2.p03.nsone.net",
+    "dns3.p03.nsone.net",
+    "dns4.p03.nsone.net"
+  ],
+  "networks": [0],
+  "network_pools": ["p03"],
+  "primary": {
+    "enabled": false,
+    "secondaries": []
+  },
+  "records": [
+    {
+      "id": "520422af9f782d37dffb5890",
+      "type": "NS",
+      "tier": 1,
+      "ttl": 3600,
+      "short_answers": [
+        "dns1.p03.nsone.net",
+        "dns2.p03.nsone.net",
+        "dns3.p03.nsone.net",
+        "dns4.p03.nsone.net"
+      ],
+      "domain": "example.com"
+    },
+    {
+      "id": "520519509f782d58bb4df419",
+      "type": "A",
+      "tier": 1,
+      "ttl": 3600,
+      "short_answers": [
+        "1.2.3.4"
+      ],
+      "domain": "www.example.com"
+    }
+  ],
+  "meta": {}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2463fb84/libcloud/test/dns/fixtures/nsone/list_records_empty.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/nsone/list_records_empty.json b/libcloud/test/dns/fixtures/nsone/list_records_empty.json
new file mode 100644
index 0000000..6d6c8c9
--- /dev/null
+++ b/libcloud/test/dns/fixtures/nsone/list_records_empty.json
@@ -0,0 +1,24 @@
+{
+  "id": "520422af9f782d37dffb588b",
+  "hostmaster": "hostmaster@nsone.net",
+  "ttl": 3600,
+  "nx_ttl": 3600,
+  "retry": 7200,
+  "zone": "example.com",
+  "refresh": 43200,
+  "expiry": 1209600,
+  "dns_servers": [
+    "dns1.p03.nsone.net",
+    "dns2.p03.nsone.net",
+    "dns3.p03.nsone.net",
+    "dns4.p03.nsone.net"
+  ],
+  "networks": [0],
+  "network_pools": ["p03"],
+  "primary": {
+    "enabled": false,
+    "secondaries": []
+  },
+  "records": [],
+  "meta": {}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2463fb84/libcloud/test/dns/fixtures/nsone/list_zones.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/nsone/list_zones.json b/libcloud/test/dns/fixtures/nsone/list_zones.json
index e69de29..8d7433a 100644
--- a/libcloud/test/dns/fixtures/nsone/list_zones.json
+++ b/libcloud/test/dns/fixtures/nsone/list_zones.json
@@ -0,0 +1,40 @@
+[
+  {
+    "id": "520422af9f782d37dffb588b",
+    "ttl": 3600,
+    "nx_ttl": 3600,
+    "retry": 7200,
+    "zone": "example.com",
+    "refresh": 43200,
+    "expiry": 1209600,
+    "dns_servers": [
+      "dns1.p03.nsone.net",
+      "dns2.p03.nsone.net",
+      "dns3.p03.nsone.net",
+      "dns4.p03.nsone.net"
+    ],
+    "networks": [0],
+    "network_pools": ["p03"],
+    "meta": {},
+    "hostmaster": "hostmaster@nsone.net"
+  },
+  {
+    "id": "520422c99f782d37dffb5892",
+    "ttl": 3600,
+    "nx_ttl": 3600,
+    "retry": 7200,
+    "zone": "nsoneisgreat.com",
+    "refresh": 43200,
+    "expiry": 1209600,
+    "dns_servers": [
+      "dns1.p04.nsone.net",
+      "dns2.p04.nsone.net",
+      "dns3.p04.nsone.net",
+      "dns4.p04.nsone.net"
+    ],
+    "networks": [0],
+    "network_pools": ["p04"],
+    "meta": {},
+    "hostmaster": "hostmaster@nsone.net"
+  }
+]
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2463fb84/libcloud/test/dns/fixtures/nsone/record_does_not_exist.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/nsone/record_does_not_exist.json b/libcloud/test/dns/fixtures/nsone/record_does_not_exist.json
new file mode 100644
index 0000000..0aef49e
--- /dev/null
+++ b/libcloud/test/dns/fixtures/nsone/record_does_not_exist.json
@@ -0,0 +1 @@
+{"message":"record not found"}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2463fb84/libcloud/test/dns/fixtures/nsone/zone_already_exists.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/nsone/zone_already_exists.json b/libcloud/test/dns/fixtures/nsone/zone_already_exists.json
new file mode 100644
index 0000000..3340a53
--- /dev/null
+++ b/libcloud/test/dns/fixtures/nsone/zone_already_exists.json
@@ -0,0 +1 @@
+{"message":"zone already exists"}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2463fb84/libcloud/test/dns/fixtures/nsone/zone_does_not_exist.json
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/fixtures/nsone/zone_does_not_exist.json b/libcloud/test/dns/fixtures/nsone/zone_does_not_exist.json
new file mode 100644
index 0000000..ffe02d2
--- /dev/null
+++ b/libcloud/test/dns/fixtures/nsone/zone_does_not_exist.json
@@ -0,0 +1 @@
+{"message":"zone not found"}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/2463fb84/libcloud/test/dns/test_nsone.py
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/test_nsone.py b/libcloud/test/dns/test_nsone.py
index 6edf09d..f3c16f7 100644
--- a/libcloud/test/dns/test_nsone.py
+++ b/libcloud/test/dns/test_nsone.py
@@ -6,6 +6,9 @@ from libcloud.test.file_fixtures import DNSFileFixtures
 from libcloud.test.secrets import DNS_PARAMS_NSONE
 from libcloud.dns.drivers.nsone import NsOneDNSDriver
 from libcloud.utils.py3 import httplib
+from libcloud.dns.types import ZoneDoesNotExistError, ZoneAlreadyExistsError,\
+    RecordDoesNotExistError, RecordAlreadyExistsError, RecordType
+from libcloud.dns.base import Zone, Record
 
 
 class NsOneTests(unittest.TestCase):
@@ -13,6 +16,11 @@ class NsOneTests(unittest.TestCase):
         NsOneMockHttp.type = None
         NsOneDNSDriver.connectionCls.conn_classes = (None, NsOneMockHttp)
         self.driver = NsOneDNSDriver(*DNS_PARAMS_NSONE)
+        self.test_zone = Zone(id='test.com', type='master', ttl=None,
+                              domain='test.com', extra={}, driver=self)
+        self.test_record = Record(id='13', type=RecordType.A,
+                                  name='example.com', zone=self.test_zone,
+                                  data='127.0.0.1', driver=self, extra={})
 
     def test_list_zones_empty(self):
         NsOneMockHttp.type = 'EMPTY_ZONES_LIST'
@@ -20,6 +28,144 @@ class NsOneTests(unittest.TestCase):
 
         self.assertEqual(zones, [])
 
+    def test_list_zones_success(self):
+        zones = self.driver.list_zones()
+
+        self.assertEqual(len(zones), 2)
+
+        zone = zones[0]
+        self.assertEqual(zone.id, '520422af9f782d37dffb588b')
+        self.assertEqual(zone.type, None)
+        self.assertEqual(zone.domain, 'example.com')
+        self.assertEqual(zone.ttl, 3600)
+
+        zone = zones[1]
+        self.assertEqual(zone.id, '520422c99f782d37dffb5892')
+        self.assertEqual(zone.type, None)
+        self.assertEqual(zone.domain, 'nsoneisgreat.com')
+        self.assertEqual(zone.ttl, 3600)
+
+    def test_delete_zone_zone_does_not_exist(self):
+        NsOneMockHttp.type = 'DELETE_ZONE_ZONE_DOES_NOT_EXIST'
+
+        try:
+            self.driver.delete_zone(zone=self.test_zone)
+        except ZoneDoesNotExistError:
+            e = sys.exc_info()[1]
+            self.assertEqual(e.zone_id, self.test_zone.id)
+        else:
+            self.fail('Exception was not thrown')
+
+    def test_delete_zone_success(self):
+        NsOneMockHttp.type = 'DELETE_ZONE_SUCCESS'
+        status = self.driver.delete_zone(zone=self.test_zone)
+
+        self.assertTrue(status)
+
+    def test_get_zone_success(self):
+        NsOneMockHttp.type = 'GET_ZONE_SUCCESS'
+        zone = self.driver.get_zone(zone_id='getzone.com')
+
+        self.assertEqual(zone.id, '52051b2c9f782d58bb4df41b')
+        self.assertEqual(zone.domain, 'example.com')
+        self.assertEqual(zone.type, None)
+        self.assertEqual(zone.ttl, 3600)
+
+    def test_get_zone_zone_does_not_exist(self):
+        NsOneMockHttp.type = 'GET_ZONE_ZONE_DOES_NOT_EXIST'
+        try:
+            self.driver.get_zone(zone_id='zonedoesnotexist.com')
+        except ZoneDoesNotExistError:
+            e = sys.exc_info()[1]
+            self.assertEqual(e.zone_id, 'zonedoesnotexist.com')
+        else:
+            self.fail('Exception was not thrown')
+
+    def test_create_zone_success(self):
+        NsOneMockHttp.type = 'CREATE_ZONE_SUCCESS'
+        zone = self.driver.create_zone(domain='newzone.com')
+
+        self.assertEqual(zone.id, '52051b2c9f782d58bb4df41b')
+        self.assertEqual(zone.domain, 'newzone.com')
+        self.assertEqual(zone.type, None),
+        self.assertEqual(zone.ttl, 3600)
+
+    def test_create_zone_zone_already_exists(self):
+        NsOneMockHttp.type = 'CREATE_ZONE_ZONE_ALREADY_EXISTS'
+
+        try:
+            self.driver.create_zone(domain='newzone.com')
+        except ZoneAlreadyExistsError:
+            e = sys.exc_info()[1]
+            self.assertEqual(e.zone_id, 'newzone.com')
+        else:
+            self.fail('Exception was not thrown')
+
+    def test_get_record_record_does_not_exist(self):
+        NsOneMockHttp.type = 'GET_RECORD_RECORD_DOES_NOT_EXIST'
+
+        try:
+            self.driver.get_record(zone_id='getrecord.com', record_id='A')
+        except RecordDoesNotExistError:
+            e = sys.exc_info()[1]
+            self.assertEqual(e.record_id, 'A')
+        else:
+            self.fail('Exception was not thrown')
+
+    def test_get_record_success(self):
+        NsOneMockHttp.type = 'GET_RECORD_SUCCESS'
+        record = self.driver.get_record(zone_id='getrecord.com', record_id='A')
+
+        self.assertEqual(record.id, '520519509f782d58bb4df419')
+        self.assertEqual(record.name, 'www.example.com')
+        self.assertEqual(record.data, ['1.1.1.1'])
+        self.assertEqual(record.type, RecordType.A)
+
+    def test_list_records_zone_does_not_exist(self):
+        NsOneMockHttp.type = 'LIST_RECORDS_ZONE_DOES_NOT_EXIST'
+
+        try:
+            self.driver.list_records(zone=self.test_zone)
+        except ZoneDoesNotExistError:
+            e = sys.exc_info()[1]
+            self.assertEqual(e.zone_id, self.test_zone.id)
+        else:
+            self.fail('Exception was not thrown')
+
+    def test_list_records_empty(self):
+        NsOneMockHttp.type = 'LIST_RECORDS_EMPTY'
+        records = self.driver.list_records(zone=self.test_zone)
+
+        self.assertEqual(records, [])
+
+    def test_list_records_success(self):
+        NsOneMockHttp.type = 'LIST_RECORDS_SUCCESS'
+        records = self.driver.list_records(zone=self.test_zone)
+        self.assertEqual(len(records), 2)
+
+        arecord = records[1]
+        self.assertEqual(arecord.id, '520519509f782d58bb4df419')
+        self.assertEqual(arecord.name, 'www.example.com')
+        self.assertEqual(arecord.type, RecordType.A)
+        self.assertEqual(arecord.data, ['1.2.3.4'])
+
+    def test_delete_record_record_does_not_exist(self):
+        NsOneMockHttp.type = 'DELETE_RECORD_RECORD_DOES_NOT_EXIST'
+
+        try:
+            self.driver.delete_record(record=self.test_record)
+        except RecordDoesNotExistError:
+            e = sys.exc_info()[1]
+            self.assertEqual(e.record_id, self.test_record.id)
+        else:
+            self.fail('Exception was not thrown')
+
+    def test_delete_record_success(self):
+        NsOneMockHttp.type = 'DELETE_RECORD_SUCCESS'
+        status = self.driver.delete_record(record=self.test_record)
+
+        self.assertTrue(status)
+
 
 class NsOneMockHttp(MockHttp):
     fixtures = DNSFileFixtures('nsone')
@@ -29,6 +175,80 @@ class NsOneMockHttp(MockHttp):
 
         return httplib.OK, body, {}, httplib.responses[httplib.OK]
 
+    def _v1_zones(self, method, url, body, headers):
+        body = self.fixtures.load('list_zones.json')
+
+        return httplib.OK, body, {}, httplib.responses[httplib.OK]
+
+    def _v1_zones_getzone_com_GET_ZONE_SUCCESS(self, method, url, body, headers):
+        body = self.fixtures.load('get_zone_success.json')
+
+        return httplib.OK, body, {}, httplib.responses[httplib.OK]
+
+    def _v1_zones_zonedoesnotexist_com_GET_ZONE_ZONE_DOES_NOT_EXIST(self, method, url, body, headers):
+        body = self.fixtures.load('zone_does_not_exist.json')
+
+        return 404, body, {}, httplib.responses[httplib.OK]
+
+    def _v1_zones_test_com_DELETE_ZONE_SUCCESS(self, method, url, body, headers):
+        body = self.fixtures.load('delete_zone_success.json')
+
+        return httplib.OK, body, {}, httplib.responses[httplib.OK]
+
+    def _v1_zones_test_com_DELETE_ZONE_ZONE_DOES_NOT_EXIST(self, method, url, body, headers):
+        body = self.fixtures.load('zone_does_not_exist.json')
+
+        return httplib.OK, body, {}, httplib.responses[httplib.OK]
+
+    def _v1_zones_newzone_com_CREATE_ZONE_SUCCESS(self, method, url, body, headers):
+        body = self.fixtures.load('create_zone_success.json')
+
+        return httplib.OK, body, {}, httplib.responses[httplib.OK]
+
+    def _v1_zones_newzone_com_CREATE_ZONE_ZONE_ALREADY_EXISTS(self, method, url, body, headers):
+        body = self.fixtures.load('zone_already_exists.json')
+
+        return httplib.OK, body, {}, httplib.responses[httplib.OK]
+
+    def _v1_zones_test_com_LIST_RECORDS_SUCCESS(self, method, url, body, headers):
+        body = self.fixtures.load('get_zone_success.json')
+
+        return httplib.OK, body, {}, httplib.responses[httplib.OK]
+
+    def _v1_zones_test_com_LIST_RECORDS_EMPTY(self, method, url, body, headers):
+        body = self.fixtures.load('list_records_empty.json')
+
+        return httplib.OK, body, {}, httplib.responses[httplib.OK]
+
+    def _v1_zones_test_com_LIST_RECORDS_ZONE_DOES_NOT_EXIST(self, method, url, body, headers):
+        body = self.fixtures.load('zone_does_not_exist.json')
+
+        return httplib.OK, body, {}, httplib.responses[httplib.OK]
+
+    def _v1_zones_test_com_example_com_A_DELETE_RECORD_RECORD_DOES_NOT_EXIST(self, method, url, body, headers):
+        body = self.fixtures.load('record_does_not_exist.json')
+
+        return 404, body, {}, httplib.responses[httplib.OK]
+
+    def _v1_zones_test_com_example_com_A_DELETE_RECORD_SUCCESS(self, method, url, body, headers):
+        body = self.fixtures.load('delete_record_success.json')
+
+        return httplib.OK, body, {}, httplib.responses[httplib.OK]
+
+    def _v1_zones_getrecord_com_getrecord_com_A_GET_RECORD_SUCCESS(self, method, url, body, headers):
+        body = self.fixtures.load('get_record_success.json')
+
+        return httplib.OK, body, {}, httplib.responses[httplib.OK]
+
+    def _v1_zones_getrecord_com_GET_RECORD_SUCCESS(self, method, url, body, headers):
+        body = self.fixtures.load('get_zone_success.json')
+
+        return httplib.OK, body, {}, httplib.responses[httplib.OK]
+
+    def _v1_zones_getrecord_com_getrecord_com_A_GET_RECORD_RECORD_DOES_NOT_EXIST(self, method, url, body, headers):
+        body = self.fixtures.load('record_does_not_exist.json')
+
+        return httplib.OK, body, {}, httplib.responses[httplib.OK]
 
 if __name__ == '__main__':
     sys.exit(unittest.main())


[08/17] libcloud git commit: fixes iteration over keys in _to_zone, _to_record

Posted by an...@apache.org.
fixes iteration over keys in _to_zone, _to_record


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/990749bb
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/990749bb
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/990749bb

Branch: refs/heads/trunk
Commit: 990749bb5ee9ecba7f19b1718cca453b67f1a4b7
Parents: 1d85a2c
Author: lostbird <lostbird@lostbird.(none)>
Authored: Mon Feb 29 17:17:48 2016 +0100
Committer: anthony-shaw <an...@gmail.com>
Committed: Mon Mar 21 21:20:31 2016 +1100

----------------------------------------------------------------------
 libcloud/dns/drivers/nsone.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/990749bb/libcloud/dns/drivers/nsone.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/nsone.py b/libcloud/dns/drivers/nsone.py
index 3b903a3..3de153d 100644
--- a/libcloud/dns/drivers/nsone.py
+++ b/libcloud/dns/drivers/nsone.py
@@ -288,7 +288,7 @@ class NsOneDNSDriver(DNSDriver):
     def _to_zone(self, item):
         common_attr = ['zone', 'id', 'type']
         extra = {}
-        for key in item:
+        for key in item.keys():
             if key not in common_attr:
                 extra[key] = item.get(key)
 
@@ -307,7 +307,7 @@ class NsOneDNSDriver(DNSDriver):
     def _to_record(self, item, zone):
         common_attr = ['id', 'short_answers', 'answers', 'domain', 'type']
         extra = {}
-        for key in item:
+        for key in item.keys():
             if key not in common_attr:
                 extra[key] = item.get(key)
         if item.get('answers') is not None: