Kami commented on a change in pull request #1323: Add Gandi LiveDNS driver
URL: https://github.com/apache/libcloud/pull/1323#discussion_r307993931
 
 

 ##########
 File path: libcloud/dns/drivers/gandi_live.py
 ##########
 @@ -0,0 +1,347 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from __future__ import with_statement
+
+import json
+from libcloud.dns.types import Provider, RecordType
+from libcloud.dns.types import RecordError
+from libcloud.dns.types import ZoneDoesNotExistError, \
+    RecordDoesNotExistError, ZoneAlreadyExistsError, RecordAlreadyExistsError
+from libcloud.dns.base import DNSDriver, Zone, Record
+from libcloud.common.gandi_live import ResourceNotFoundError, \
+    ResourceConflictError, GandiLiveResponse, GandiLiveConnection, \
+    BaseGandiLiveDriver
+
+
+__all__ = [
+    'GandiLiveDNSDriver',
+]
+
+
+TTL_MIN = 300
+TTL_MAX = 2592000  # 30 days
+API_BASE = '/api/v5'
+
+
+class GandiLiveDNSResponse(GandiLiveResponse):
+    pass
+
+
+class GandiLiveDNSConnection(GandiLiveConnection):
+    responseCls = GandiLiveDNSResponse
+
+
+class GandiLiveDNSDriver(BaseGandiLiveDriver, DNSDriver):
+    """
+    API reference can be found at:
+
+    https://doc.livedns.gandi.net/
+
+    Please note that the Libcloud paradigm of one zone per domain does not
+    match exactly with Gandi LiveDNS.  For Gandi, a "zone" can apply to
+    multiple domains.  This driver behaves as if the domain is a zone, but be
+    warned that modifying a domain means modifying the zone.  Iif you have a
+    zone associated with mutiple domains, all of those domains will be
+    modified as well.
+    """
+
+    type = Provider.GANDI
+    name = 'Gandi LiveDNS'
+    website = 'http://www.gandi.net/domain'
+
+    connectionCls = GandiLiveDNSConnection
+
+    # also supports CAA, CDS
+    RECORD_TYPE_MAP = {
+        RecordType.A: 'A',
+        RecordType.AAAA: 'AAAA',
+        RecordType.ALIAS: 'ALIAS',
+        RecordType.CNAME: 'CNAME',
+        RecordType.DNAME: 'DNAME',
+        RecordType.DS: 'DS',
+        RecordType.KEY: 'KEY',
+        RecordType.LOC: 'LOC',
+        RecordType.MX: 'MX',
+        RecordType.NS: 'NS',
+        RecordType.PTR: 'PTR',
+        RecordType.SPF: 'SPF',
+        RecordType.SRV: 'SRV',
+        RecordType.SSHFP: 'SSHFP',
+        RecordType.TLSA: 'TLSA',
+        RecordType.TXT: 'TXT',
+        RecordType.WKS: 'WKS',
+    }
+
+    def _to_zone(self, zone):
+        extra = {}
+        if 'zone_uuid' in zone:
+            extra = {
+                'zone_uuid': zone['zone_uuid']
+            }
+        return Zone(
+            id=str(zone['fqdn']),
+            domain=zone['fqdn'],
+            type='master',
+            ttl=0,
+            driver=self,
+            extra=extra,
+        )
+
+    def _to_zones(self, zones):
+        ret = []
+        for z in zones:
+            ret.append(self._to_zone(z))
+        return ret
+
+    def list_zones(self):
+        zones = self.connection.request(action='%s/domains' % API_BASE,
+                                        method='GET')
+        return self._to_zones(zones.object)
+
+    def get_zone(self, zone_id):
+        action = '%s/domains/%s' % (API_BASE, zone_id)
+        try:
+            zone = self.connection.request(action=action, method='GET')
+        except ResourceNotFoundError:
+            raise ZoneDoesNotExistError(value='',
+                                        driver=self.connection.driver,
+                                        zone_id=zone_id)
+        return self._to_zone(zone.object)
+
+    """
+    :param extra: (optional) Extra attributes ('name'); if not provided, name
+                             is based on domain.
+    """
+    def create_zone(self, domain, type='master', ttl=None, extra=None):
+        if extra and 'name' in extra:
+            zone_name = extra['name']
+        else:
+            zone_name = '%s zone' % domain
+        raw_zone_data = {
+            'name': zone_name,
+        }
+        post_zone_data = json.dumps(raw_zone_data)
 
 Review comment:
   This encoding should happens inside the connection class - please add 
``encode_data`` to the connection class and remove data encoding inside the 
driver methods.
   
   For details and context, please see 
https://github.com/apache/libcloud/pull/1315#issuecomment-512226526

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to