Просмотр исходного кода

Added interfaces for dns services

Nuwan Goonasekera 6 лет назад
Родитель
Сommit
1892f9a208

+ 19 - 0
cloudbridge/interfaces/provider.py

@@ -232,6 +232,25 @@ class CloudProvider(object):
         """
         pass
 
+    @abstractproperty
+    def dns(self):
+        """
+        Provides access to all DNS related services.
+
+        Example:
+
+        .. code-block:: python
+
+            if provider.has_service(CloudServiceType.DNS):
+               print("Provider supports DNS services")
+               dns_zones = provider.dns.host_zones.list()
+               print(dns_zones)
+
+        :rtype: :class:`.DnsService`
+        :return: a DNS service object
+        """
+        pass
+
 
 class TestMockHelperMixin(object):
     """

+ 114 - 0
cloudbridge/interfaces/resources.py

@@ -24,6 +24,7 @@ class CloudServiceType(object):
     SECURITY = 'security'
     VOLUME = 'storage.volumes'
     BUCKET = 'storage.buckets'
+    DNS = 'dns'
 
 
 class CloudResource(object):
@@ -1306,6 +1307,119 @@ class InternetGateway(ObjectLifeCycleMixin, Gateway):
     __metaclass__ = ABCMeta
 
 
+class DnsZone(CloudResource):
+    """
+    Represents a dns host zone.
+
+    A host zone represents a top level domain (e.g. cloudve.org) in which
+    multiple dns records (e.g. A, CNAME. MX etc.) are contained.
+    """
+    __metaclass__ = ABCMeta
+
+    @abstractmethod
+    def delete(self):
+        """
+        Delete this zone.
+        """
+        pass
+
+    @abstractproperty
+    def records(self):
+        """
+        List of DNS records in this zone.
+
+        :rtype: ``list`` of :class:`.DnsRecord` objects
+        :return: A list of DnsRecords associated with this zone.
+        """
+        pass
+
+
+class RecordType(object):
+    """
+    DNS record types.
+    """
+    A = 'A'
+    AAAA = 'AAAA'
+    AFSDB = 'A'
+    ALIAS = 'ALIAS'
+    CERT = 'CERT'
+    CNAME = 'CNAME'
+    DNAME = 'DNAME'
+    DNSKEY = 'DNSKEY'
+    DS = 'DS'
+    GEO = 'GEO'
+    HINFO = 'HINFO'
+    KEY = 'KEY'
+    LOC = 'LOC'
+    MX = 'MX'
+    NAPTR = 'NAPTR'
+    NS = 'NS'
+    NSEC = 'NSEC'
+    OPENPGPKEY = 'OPENPGPKEY'
+    PTR = 'PTR'
+    REDIRECT = 'REDIRECT'
+    RP = 'RP'
+    RRSIG = 'RRSIG'
+    SOA = 'SOA'
+    SPF = 'SPF'
+    SRV = 'SRV'
+    SSHFP = 'SSHFP'
+    TLSA = 'TLSA'
+    TXT = 'TXT'
+    URL = 'URL'
+    WKS = 'WKS'
+
+
+class DnsRecord(CloudResource):
+    """
+    Represents a dns record.
+
+    A dns record belongs to a host zone and can contain
+    records of varous types such as A, CNAME. MX etc.
+    """
+    __metaclass__ = ABCMeta
+
+    @abstractproperty
+    def zone_id(self):
+        """
+        The containing zone for this dns record
+
+        :rtype: ``str``
+        :return: The ID of the zone for this dns record
+        """
+        pass
+
+    @abstractproperty
+    def type(self):
+        """
+        Dns Record type which could be A, CNAME, MX, AAAA, PTR
+
+        :rtype: ``DnsRecordType``
+        :return: An enum representing the DNS record type.
+        """
+        pass
+
+    @abstractproperty
+    def data(self):
+        """
+        Dns Record data
+
+        :rtype: ``str``
+        :return: A string containing this DNS record's data.
+        """
+        pass
+
+    @abstractproperty
+    def ttl(self):
+        """
+        ttl for this record
+
+        :rtype: ``int``
+        :return: The ttl (in seconds) for this record.
+        """
+        pass
+
+
 class AttachmentInfo(object):
     """
     Contains attachment information for a volume.

+ 150 - 0
cloudbridge/interfaces/services.py

@@ -873,6 +873,156 @@ class RouterService(PageableObjectMixin, CloudService):
         pass
 
 
+class DnsService(CloudService):
+    """
+    Base service interface for DNS.
+
+    This service offers a collection of DNS services that in turn
+    provide access to DNS resources.
+    """
+    __metaclass__ = ABCMeta
+
+    @abstractproperty
+    def host_zones(self):
+        """
+        Provides access to all dns zones.
+
+        :rtype: :class:`.DnsZoneService`
+        :return: a Dns Host Zone service
+        """
+        pass
+
+    @abstractproperty
+    def _records(self):
+        """
+        Provides access to dns records for this service.
+        This service is not iterable.
+
+        :rtype: :class:`.DnsRecordSubService`
+        :return: a DnsRecordSubService object
+        """
+        pass
+
+
+class DnsZoneService(PageableObjectMixin, CloudService):
+    """
+    Manage DNS Zone actions and resources. This service is optional and
+    the :func:`CloudProvider.has_service()` method should be used to verify its
+    availability before using the service.
+    """
+    __metaclass__ = ABCMeta
+
+    @abstractmethod
+    def get(self, dns_zone_id):
+        """
+        Returns a DnsZone object given its ID.
+
+        :type dns_zone_id: ``str``
+        :param dns_zone_id: The ID of the host zone to retrieve.
+
+        :rtype: ``object``  of :class:`.DnsZone` or ``None``
+        :return: a DnsZone object of ``None`` if not found.
+        """
+        pass
+
+    @abstractmethod
+    def list(self, limit=None, marker=None):
+        """
+        List all host zones.
+
+        :rtype: ``list`` of :class:`.DnsZone`
+        :return: list of DnsZone objects
+        """
+        pass
+
+    @abstractmethod
+    def find(self, **kwargs):
+        """
+        Searches for a host zone by a given list of attributes.
+
+        Supported attributes: label
+
+        :rtype: List of ``object`` of :class:`.DnsZone`
+        :return: A list of Dns Zone objects matching the supplied attributes.
+        """
+        pass
+
+    @abstractmethod
+    def create(self, label):
+        """
+        Create a new host zone.
+
+        :type label: ``str``
+        :param label: A host zone label.
+
+        :rtype: ``object`` of :class:`.DnsZone`
+        :return:  A DnsZone object
+        """
+        pass
+
+    @abstractmethod
+    def delete(self, dns_zone):
+        """
+        Delete an existing DnsHostZone.
+
+        :type dns_zone: :class:`.DnsZone` object or ``str``
+        :param dns_zone: DnsZone object or ID of the host zone to delete.
+        """
+        pass
+
+
+class DnsRecordService(CloudService):
+
+    """
+    The Dns Record Service interface provides access to the records belonging
+    to a Dns Zone.
+    """
+    __metaclass__ = ABCMeta
+
+    @abstractmethod
+    def get(self, dns_zone, rec_id):
+        """
+        Returns a record given its ID and the dns_zone containing
+        it. Returns ``None`` if the record does not exist.
+
+        :rtype: :class:`.DnsRecord`
+        :return:  a DnsRecord instance
+        """
+        pass
+
+    @abstractmethod
+    def list(self, dns_zone, limit=None, marker=None):
+        """
+        List all records within a dns zone.
+
+        :rtype: :class:`.DnsRecord`
+        :return:  a DnsRecord instance
+        """
+        pass
+
+    @abstractmethod
+    def create(self, dns_zone, name, type, data, ttl=None):
+        """
+        Create a new record within a zone.
+
+        :type name: ``str``
+        :param name: The record name.
+
+        :type type: ``str``
+        :param type: The DnsRecord type. (e.g. A, CNAME, MX etc)
+
+        :type data: ``str``
+        :param data: The corresponding value for the record.
+
+        :type data: ``int``
+        :param data: The ttl (in seconds) for thisrecord.
+
+        :rtype: ``object`` of :class:`.DnsRecord`
+        :return:  A DnsRecord object
+        """
+        pass
+
+
 class BucketService(PageableObjectMixin, CloudService):
 
     """

+ 83 - 1
cloudbridge/interfaces/subservices.py

@@ -222,7 +222,7 @@ class VMFirewallRuleSubService(PageableObjectMixin):
         pass
 
     @abstractmethod
-    def create(self,  direction, protocol=None, from_port=None,
+    def create(self, direction, protocol=None, from_port=None,
                to_port=None, cidr=None, src_dest_fw=None):
         """
         Create a VM firewall rule.
@@ -395,3 +395,85 @@ class SubnetSubService(PageableObjectMixin):
         :param subnet_id: The ID of the Subnet to be deleted.
         """
         pass
+
+
+class DnsRecordSubService(PageableObjectMixin):
+    """
+    Base interface for a Dns Record Service.
+    """
+    __metaclass__ = ABCMeta
+
+    @abstractmethod
+    def get(self, record_id):
+        """
+        Returns a Dns Record given its ID or ``None`` if not found.
+
+        :type record_id: ``str``
+        :param record_id: The ID of the DnsRecord to retrieve.
+
+        :rtype: ``object`` of :class:`.DnsRecord`
+        :return: a DnsRecord object
+        """
+        pass
+
+    @abstractmethod
+    def list(self, limit=None, marker=None):
+        """
+        List Dns Records within the Dns Zone holding this subservice.
+
+        :rtype: ``list`` of :class:`.DnsRecord`
+        :return: list of DnsRecord objects
+        """
+        pass
+
+    @abstractmethod
+    def find(self, **kwargs):
+        """
+        Searches for a DnsRecord by a given list of attributes.
+
+        Supported attributes: label
+
+        Example:
+
+        .. code-block:: python
+
+            subnet = provider.networking.dns.host_zones.get('id').records.find(
+                        label='my-label')
+
+
+        :rtype: List of ``object`` of :class:`.DnsRecord`
+        :return: A list of DnsRecord objects matching the supplied attributes.
+        """
+        pass
+
+    @abstractmethod
+    def create(self, label, type, data, ttl=None):
+        """
+        Create a new DnsRecord within the Dns Zone holding this subservice.
+
+        :type label: ``str``
+        :param label: The record label.
+
+        :type type: ``str``
+        :param type: The DnsRecord type. (e.g. A, CNAME, MX etc)
+
+        :type data: ``str``
+        :param data: The corresponding value for the record.
+
+        :type data: ``int``
+        :param data: The ttl (in seconds) for thisrecord.
+
+        :rtype: ``object`` of :class:`.DnsRecord`
+        :return:  A DnsRecord object
+        """
+        pass
+
+    @abstractmethod
+    def delete(self, record_id):
+        """
+        Delete an existing DnsRecord.
+
+        :type record_id: ``str``
+        :param record_id: The ID of the DnsRecord to be deleted.
+        """
+        pass