libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject libcloud git commit: Fix interfaces methods in zonomi, worlwidedns, dnsimple, pointdns and liquidweb dns providers
Date Tue, 13 Oct 2015 20:06:38 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk 06b81eac2 -> 713727ebb


Fix interfaces methods in zonomi, worlwidedns, dnsimple, pointdns and liquidweb dns providers

Closes #601

Signed-off-by: Tomaz Muraus <tomaz@apache.org>


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

Branch: refs/heads/trunk
Commit: 713727ebb21c2185d5ce58925ec62aa634a827fa
Parents: 06b81ea
Author: Alejandro Pereira <alepereira.dev@gmail.com>
Authored: Mon Oct 12 12:26:49 2015 -0300
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Tue Oct 13 17:09:20 2015 +0200

----------------------------------------------------------------------
 libcloud/dns/drivers/dnsimple.py       | 17 ++++++---
 libcloud/dns/drivers/liquidweb.py      | 53 +++++++++++++++++++++++------
 libcloud/dns/drivers/pointdns.py       | 10 ++++--
 libcloud/dns/drivers/worldwidedns.py   | 32 ++++++++++-------
 libcloud/test/dns/test_dnsimple.py     |  1 +
 libcloud/test/dns/test_liquidweb.py    |  5 ++-
 libcloud/test/dns/test_worldwidedns.py | 33 ++++++++++++++++--
 7 files changed, 120 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/713727eb/libcloud/dns/drivers/dnsimple.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/dnsimple.py b/libcloud/dns/drivers/dnsimple.py
index 16b1a42..a6a1b03 100644
--- a/libcloud/dns/drivers/dnsimple.py
+++ b/libcloud/dns/drivers/dnsimple.py
@@ -111,13 +111,19 @@ class DNSimpleDNSDriver(DNSDriver):
         record = self._to_record(response.object, zone_id=zone_id)
         return record
 
-    def create_zone(self, domain, extra=None):
+    def create_zone(self, domain, type='master', ttl=None, extra=None):
         """
         Create a new zone.
 
         :param domain: Zone domain name (e.g. example.com)
         :type domain: ``str``
 
+        :param type: Zone type (All zones are master by design).
+        :type  type: ``str``
+
+        :param ttl: TTL for new records. (This is not really used)
+        :type  ttl: ``int``
+
         :param extra: Extra attributes (driver specific). (optional)
         :type extra: ``dict``
 
@@ -130,8 +136,8 @@ class DNSimpleDNSDriver(DNSDriver):
         if extra is not None:
             r_json.update(extra)
         r_data = json.dumps({'domain': r_json})
-        response = self.connection.request('/v1/domains', method='POST',
-                                           data=r_data)
+        response = self.connection.request(
+            '/v1/domains', method='POST', data=r_data)
         zone = self._to_zone(response.object)
         return zone
 
@@ -168,7 +174,7 @@ class DNSimpleDNSDriver(DNSDriver):
         record = self._to_record(response.object, zone=zone)
         return record
 
-    def update_record(self, record, name, data, extra=None):
+    def update_record(self, record, name, type, data, extra=None):
         """
         Update an existing record.
 
@@ -181,6 +187,9 @@ class DNSimpleDNSDriver(DNSDriver):
                      argument.
         :type  name: ``str``
 
+        :param type: DNS record type (A, AAAA, ...).
+        :type  type: :class:`RecordType`
+
         :param data: Data for the record (depends on the record type).
         :type  data: ``str``
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/713727eb/libcloud/dns/drivers/liquidweb.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/liquidweb.py b/libcloud/dns/drivers/liquidweb.py
index eee67bb..803849a 100644
--- a/libcloud/dns/drivers/liquidweb.py
+++ b/libcloud/dns/drivers/liquidweb.py
@@ -152,17 +152,34 @@ class LiquidWebDNSDriver(DNSDriver):
         record = self._to_record(response.objects[0], zone=zone)
         return record
 
-    def create_zone(self, domain):
+    def create_zone(self, domain, type='master', ttl=None, extra=None):
         """
         Create a new zone.
 
         :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 not really used)
+        :type  ttl: ``int``
+
+        :param extra: Extra attributes (driver specific). ('region_support',
+                      'zone_data')
+        :type extra: ``dict``
+
         :rtype: :class:`Zone`
+
+        For more info, please see:
+        https://www.liquidweb.com/storm/api/docs/v1/Network/DNS/Zone.html
         """
         action = '/v1/Network/DNS/Zone/create'
         data = json.dumps({'params': {'name': domain}})
+        if extra is not None:
+            params = data.get('params')
+            params.update(extra)
         try:
             response = self.connection.request(action=action,
                                                method='POST',
@@ -171,7 +188,8 @@ class LiquidWebDNSDriver(DNSDriver):
             e = sys.exc_info()[1]
             if e.error_class == 'LW::Exception::DuplicateRecord':
                 raise ZoneAlreadyExistsError(zone_id=domain,
-                                             value=e.value, driver=self)
+                                             value=e.value,
+                                             driver=self)
             else:
                 raise e
 
@@ -179,7 +197,7 @@ class LiquidWebDNSDriver(DNSDriver):
 
         return zone
 
-    def create_record(self, name, zone, rtype, data, extra=None):
+    def create_record(self, name, zone, type, data, extra=None):
         """
         Create a record.
 
@@ -192,9 +210,9 @@ class LiquidWebDNSDriver(DNSDriver):
         :param zone: Zone which the records will be created for.
         :type zone: :class:`Zone`
 
-        :param rtype: DNS record type ( 'A', 'AAAA', 'CNAME', 'MX', 'NS',
+        :param type: DNS record type ( 'A', 'AAAA', 'CNAME', 'MX', 'NS',
                      'PTR', 'SOA', 'SRV', 'TXT').
-        :type  rtype: :class:`RecordType`
+        :type  type: :class:`RecordType`
 
         :param data: Data for the record (depends on the record type).
         :type  data: ``str``
@@ -207,7 +225,7 @@ class LiquidWebDNSDriver(DNSDriver):
         action = '/v1/Network/DNS/Record/create'
         to_post = {'params': {'name': name,
                               'rdata': data,
-                              'type': rtype,
+                              'type': type,
                               'zone': zone.domain,
                               'zone_id': zone.id
                               }
@@ -231,13 +249,26 @@ class LiquidWebDNSDriver(DNSDriver):
         record = self._to_record(response.objects[0], zone=zone)
         return record
 
-    def update_record(self, record, extra=None):
+    def update_record(self, record, name, type, data, extra=None):
         """
         Update an existing record.
 
         :param record: Record to update.
         :type  record: :class:`Record`
 
+        :param name: Record name without the domain name (e.g. www).
+                     Note: If you want to create a record for a base domain
+                     name, you should specify empty string ('') for this
+                     argument.
+        :type  name: ``str``
+
+        :param type: DNS record type ( 'A', 'AAAA', 'CNAME', 'MX', 'NS',
+                     'PTR', 'SOA', 'SRV', 'TXT').
+        :type  type: :class:`RecordType`
+
+        :param data: Data for the record (depends on the record type).
+        :type  data: ``str``
+
         :param extra: (optional) Extra attributes ('name', 'rdata', 'prio',
                       'ttl').
         :type  extra: ``dict``
@@ -246,14 +277,16 @@ class LiquidWebDNSDriver(DNSDriver):
         """
         zone = record.zone
         action = '/v1/Network/DNS/Record/update'
-        to_post = {'params': {'id': int(record.id)}}
+        to_post = {'params': {'id': int(record.id),
+                              'name': name,
+                              'rdata': data}}
         if extra is not None:
             to_post['params'].update(extra)
-        data = json.dumps(to_post)
+        j_data = json.dumps(to_post)
         try:
             response = self.connection.request(action=action,
                                                method='PUT',
-                                               data=data)
+                                               data=j_data)
         except APIException:
             e = sys.exc_info()[1]
             if e.error_class == 'LW::Exception::RecordNotFound':

http://git-wip-us.apache.org/repos/asf/libcloud/blob/713727eb/libcloud/dns/drivers/pointdns.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/pointdns.py b/libcloud/dns/drivers/pointdns.py
index def30a6..a639bdb 100644
--- a/libcloud/dns/drivers/pointdns.py
+++ b/libcloud/dns/drivers/pointdns.py
@@ -236,13 +236,16 @@ class PointDNSDriver(DNSDriver):
         record = self._to_record(response.object, zone_id=zone_id)
         return record
 
-    def create_zone(self, domain, ttl=None, extra=None):
+    def create_zone(self, domain, type='master', ttl=None, extra=None):
         """
         Create a new zone.
 
         :param domain: Zone domain name (e.g. example.com)
         :type domain: ``str``
 
+        :param type: Zone type (All zones are master by design).
+        :type  type: ``str``
+
         :param ttl: TTL for new records. (optional)
         :type  ttl: ``int``
 
@@ -305,7 +308,7 @@ class PointDNSDriver(DNSDriver):
         record = self._to_record(response.object, zone=zone)
         return record
 
-    def update_zone(self, zone, domain, ttl=None, extra=None):
+    def update_zone(self, zone, domain, type='master', ttl=None, extra=None):
         """
         Update en existing zone.
 
@@ -315,6 +318,9 @@ class PointDNSDriver(DNSDriver):
         :param domain: Zone domain name (e.g. example.com)
         :type  domain: ``str``
 
+        :param type: Zone type (All zones are master by design).
+        :type  type: ``str``
+
         :param ttl: TTL for new records. (optional)
         :type  ttl: ``int``
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/713727eb/libcloud/dns/drivers/worldwidedns.py
----------------------------------------------------------------------
diff --git a/libcloud/dns/drivers/worldwidedns.py b/libcloud/dns/drivers/worldwidedns.py
index 50022a0..e3193bd 100644
--- a/libcloud/dns/drivers/worldwidedns.py
+++ b/libcloud/dns/drivers/worldwidedns.py
@@ -232,7 +232,7 @@ class WorldWideDNSDriver(DNSDriver):
         zone = self.get_zone(zone.id)
         return zone
 
-    def update_record(self, record, name, type, data, ex_entry):
+    def update_record(self, record, name, type, data, extra=None):
         """
         Update an existing record.
 
@@ -251,11 +251,15 @@ class WorldWideDNSDriver(DNSDriver):
         :param data: Data for the record (depends on the record type).
         :type  data: ``str``
 
-        :param ex_entry: Entry position (1 thru 40)
-        :type  ex_entry: ``int``
+        :param extra: Contains 'entry' Entry position (1 thru 40)
+        :type extra: ``dict``
 
         :rtype: :class:`Record`
         """
+        if (extra is None) or ('entry' not in extra):
+            raise WorldWideDNSError(value="You must enter 'entry' parameter",
+                                    driver=self)
+        entry = extra.get('entry')
         if name == '':
             name = '@'
         if type not in self.RECORD_TYPE_MAP:
@@ -263,9 +267,9 @@ class WorldWideDNSDriver(DNSDriver):
                               driver=record.zone.driver,
                               record_id=name)
         zone = record.zone
-        extra = {'S%s' % ex_entry: name,
-                 'T%s' % ex_entry: type,
-                 'D%s' % ex_entry: data}
+        extra = {'S%s' % entry: name,
+                 'T%s' % entry: type,
+                 'D%s' % entry: data}
         zone = self.update_zone(zone, zone.domain, extra=extra)
         record = self.get_record(zone.id, name)
         return record
@@ -315,7 +319,7 @@ class WorldWideDNSDriver(DNSDriver):
             zone = self.update_zone(zone, zone.domain, ttl=ttl)
         return zone
 
-    def create_record(self, name, zone, type, data, ex_entry):
+    def create_record(self, name, zone, type, data, extra=None):
         """
         Create a new record.
 
@@ -334,20 +338,24 @@ class WorldWideDNSDriver(DNSDriver):
         :param data: Data for the record (depends on the record type).
         :type  data: ``str``
 
-        :param ex_entry: Entry position (1 thru 40)
-        :type  ex_entry: ``int``
+        :param extra: Contains 'entry' Entry position (1 thru 40)
+        :type extra: ``dict``
 
         :rtype: :class:`Record`
         """
+        if (extra is None) or ('entry' not in extra):
+            raise WorldWideDNSError(value="You must enter 'entry' parameter",
+                                    driver=zone.driver)
+        entry = extra.get('entry')
         if name == '':
             name = '@'
         if type not in self.RECORD_TYPE_MAP:
             raise RecordError(value="Record type is not allowed",
                               driver=zone.driver,
                               record_id=name)
-        extra = {'S%s' % ex_entry: name,
-                 'T%s' % ex_entry: type,
-                 'D%s' % ex_entry: data}
+        extra = {'S%s' % entry: name,
+                 'T%s' % entry: type,
+                 'D%s' % entry: data}
         zone = self.update_zone(zone, zone.domain, extra=extra)
         record = self.get_record(zone.id, name)
         return record

http://git-wip-us.apache.org/repos/asf/libcloud/blob/713727eb/libcloud/test/dns/test_dnsimple.py
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/test_dnsimple.py b/libcloud/test/dns/test_dnsimple.py
index 1f2f95c..0110fbd 100644
--- a/libcloud/test/dns/test_dnsimple.py
+++ b/libcloud/test/dns/test_dnsimple.py
@@ -168,6 +168,7 @@ class DNSimpleDNSTests(unittest.TestCase):
         DNSimpleDNSMockHttp.type = 'UPDATE'
         extra = {'ttl': 4500}
         record1 = self.driver.update_record(record=record, name='www',
+                                            type=record.type,
                                             data='updated.com',
                                             extra=extra)
         self.assertEqual(record.data, 'example.com')

http://git-wip-us.apache.org/repos/asf/libcloud/blob/713727eb/libcloud/test/dns/test_liquidweb.py
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/test_liquidweb.py b/libcloud/test/dns/test_liquidweb.py
index e627544..f7f96fa 100644
--- a/libcloud/test/dns/test_liquidweb.py
+++ b/libcloud/test/dns/test_liquidweb.py
@@ -200,7 +200,10 @@ class LiquidWebTests(unittest.TestCase):
         self.assertEqual(record.data, '127.0.0.1')
         self.assertEqual(record.extra.get('ttl'), 300)
         LiquidWebMockHttp.type = ''
-        record1 = self.driver.update_record(record, extra={'ttl': 5600})
+        record1 = self.driver.update_record(record=record, name=record.name,
+                                            type=record.type,
+                                            data=record.data,
+                                            extra={'ttl': 5600})
         self.assertEqual(record1.id, '13')
         self.assertEqual(record1.type, 'A')
         self.assertEqual(record1.name, 'nerd.domain.com')

http://git-wip-us.apache.org/repos/asf/libcloud/blob/713727eb/libcloud/test/dns/test_worldwidedns.py
----------------------------------------------------------------------
diff --git a/libcloud/test/dns/test_worldwidedns.py b/libcloud/test/dns/test_worldwidedns.py
index 8ea966e..3b19722 100644
--- a/libcloud/test/dns/test_worldwidedns.py
+++ b/libcloud/test/dns/test_worldwidedns.py
@@ -20,6 +20,7 @@ from libcloud.utils.py3 import httplib
 from libcloud.dns.types import RecordType, ZoneDoesNotExistError
 from libcloud.dns.types import RecordDoesNotExistError
 from libcloud.dns.drivers.worldwidedns import WorldWideDNSDriver
+from libcloud.dns.drivers.worldwidedns import WorldWideDNSError
 from libcloud.common.worldwidedns import NonExistentDomain
 from libcloud.common.worldwidedns import InvalidDomainName
 
@@ -192,7 +193,7 @@ class WorldWideDNSTests(unittest.TestCase):
         WorldWideDNSMockHttp.type = 'CREATE_RECORD'
         record = self.driver.create_record(name='domain4', zone=zone,
                                            type=RecordType.A, data='0.0.0.4',
-                                           ex_entry=4)
+                                           extra={'entry': 4})
 
         self.assertEqual(record.id, 'domain4')
         self.assertEqual(record.name, 'domain4')
@@ -201,13 +202,26 @@ class WorldWideDNSTests(unittest.TestCase):
         self.assertEqual(record.type, RecordType.A)
         self.assertEqual(record.data, '0.0.0.4')
 
+    def test_create_record_missing_entry(self):
+        zone = self.driver.list_zones()[0]
+        WorldWideDNSMockHttp.type = 'CREATE_RECORD'
+        try:
+            self.driver.create_record(name='domain1', zone=zone,
+                                      type=RecordType.A, data='0.0.0.1',
+                                      extra={'non_entry': 1})
+        except WorldWideDNSError:
+            e = sys.exc_info()[1]
+            self.assertEqual(e.value, "You must enter 'entry' parameter")
+        else:
+            self.fail('Exception was not thrown')
+
     def test_update_record_success(self):
         zone = self.driver.list_zones()[0]
         record = self.driver.get_record(zone.id, 'www')
         WorldWideDNSMockHttp.type = 'UPDATE_RECORD'
         record = self.driver.update_record(record=record, name='domain1',
                                            type=RecordType.A, data='0.0.0.1',
-                                           ex_entry=1)
+                                           extra={'entry': 1})
 
         self.assertEqual(record.id, 'domain1')
         self.assertEqual(record.name, 'domain1')
@@ -216,6 +230,21 @@ class WorldWideDNSTests(unittest.TestCase):
         self.assertEqual(record.type, RecordType.A)
         self.assertEqual(record.data, '0.0.0.1')
 
+    def test_update_record_missing_entry(self):
+        zone = self.driver.list_zones()[0]
+        record = self.driver.get_record(zone.id, 'www')
+        WorldWideDNSMockHttp.type = 'UPDATE_RECORD'
+        try:
+            record = self.driver.update_record(record=record, name='domain1',
+                                               type=RecordType.A,
+                                               data='0.0.0.1',
+                                               extra={'non_entry': 1})
+        except WorldWideDNSError:
+            e = sys.exc_info()[1]
+            self.assertEqual(e.value, "You must enter 'entry' parameter")
+        else:
+            self.fail('Exception was not thrown')
+
     def test_delete_zone_success(self):
         zone = self.driver.list_zones()[0]
         status = self.driver.delete_zone(zone=zone)


Mime
View raw message