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/11/14 23:51:00 UTC
[13/56] [abbrv] libcloud git commit: Removed sdist
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8afcda91/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/godaddy.py
----------------------------------------------------------------------
diff --git a/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/godaddy.py b/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/godaddy.py
deleted file mode 100644
index 1a18e3a..0000000
--- a/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/godaddy.py
+++ /dev/null
@@ -1,502 +0,0 @@
-# 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.
-
-__all__ = [
- 'GoDaddyDNSDriver'
-]
-
-try:
- import simplejson as json
-except:
- import json
-
-from libcloud.common.base import ConnectionKey, JsonResponse
-from libcloud.common.types import LibcloudError
-from libcloud.utils.py3 import httplib
-from libcloud.dns.types import Provider, RecordType, RecordDoesNotExistError
-from libcloud.dns.base import DNSDriver, Zone, Record
-
-API_HOST = 'api.godaddy.com'
-VALID_RECORD_EXTRA_PARAMS = ['prio', 'ttl']
-
-
-class GoDaddyDNSException(LibcloudError):
- def __init__(self, code, message):
- self.code = code
- self.message = message
- self.args = (code, message)
-
- def __str__(self):
- return self.__repr__()
-
- def __repr__(self):
- return ('<GoDaddyDNSException in %s: %s>' % (self.code, self.message))
-
-
-class GoDaddyDNSResponse(JsonResponse):
- valid_response_codes = [httplib.OK, httplib.ACCEPTED, httplib.CREATED,
- httplib.NO_CONTENT]
-
- def parse_body(self):
- if not self.body:
- return None
- # json.loads doesn't like the regex expressions used in godaddy schema
- self.body = self.body.replace('\\.', '\\\\.')
-
- data = json.loads(self.body)
- return data
-
- def parse_error(self):
- data = self.parse_body()
- raise GoDaddyDNSException(code=data['code'], message=data['message'])
-
- def success(self):
- return self.status in self.valid_response_codes
-
-
-class GoDaddyDNSConnection(ConnectionKey):
- responseCls = GoDaddyDNSResponse
- host = API_HOST
-
- allow_insecure = False
-
- def __init__(self, key, secret, shopper_id, secure=True, host=None,
- port=None, url=None, timeout=None,
- proxy_url=None, backoff=None, retry_delay=None):
- super(GoDaddyDNSConnection, self).__init__(
- key,
- secure=secure, host=host,
- port=port, url=url,
- timeout=timeout,
- proxy_url=proxy_url,
- backoff=backoff,
- retry_delay=retry_delay)
- self.key = key
- self.secret = secret
- self.shopper_id = shopper_id
-
- def add_default_headers(self, headers):
- headers['X-Shopper-Id'] = self.shopper_id
- headers['Authorization'] = "sso-key %s:%s" % \
- (self.key, self.secret)
- return headers
-
-
-class GoDaddyDNSDriver(DNSDriver):
- """
- A driver for GoDaddy DNS.
-
- This is for customers of GoDaddy
- who wish to purchase, update existing domains
- and manage records for DNS zones owned by GoDaddy NS servers.
- """
- type = Provider.GODADDY
- name = 'GoDaddy DNS'
- website = 'https://www.godaddy.com/'
- connectionCls = GoDaddyDNSConnection
-
- RECORD_TYPE_MAP = {
- RecordType.A: 'A',
- RecordType.AAAA: 'AAAA',
- RecordType.CNAME: 'CNAME',
- RecordType.MX: 'MX',
- RecordType.NS: 'SPF',
- RecordType.SRV: 'SRV',
- RecordType.TXT: 'TXT',
- }
-
- def __init__(self, shopper_id, key, secret,
- secure=True, host=None, port=None):
- """
- Instantiate a new `GoDaddyDNSDriver`
-
- :param shopper_id: Your customer ID or shopper ID with GoDaddy
- :type shopper_id: ``str``
-
- :param key: Your access key from developer.godaddy.com
- :type key: ``str``
-
- :param secret: Your access key secret
- :type secret: ``str``
- """
- super(GoDaddyDNSDriver, self).__init__(key=key, secret=secret,
- secure=secure,
- host=host, port=port,
- shopper_id=str(shopper_id))
-
- def list_zones(self):
- """
- Return a list of zones (purchased domains)
-
- :return: ``list`` of :class:`Zone`
- """
- result = self.connection.request(
- '/v1/domains/').object
- zones = self._to_zones(result)
- return zones
-
- def list_records(self, zone):
- """
- Return a list of records for the provided zone.
-
- :param zone: Zone to list records for.
- :type zone: :class:`Zone`
-
- :return: ``list`` of :class:`Record`
- """
- result = self.connection.request(
- '/v1/domains/%s/records' % (zone.domain)).object
- records = self._to_records(items=result, zone=zone)
- return records
-
- def create_record(self, name, zone, type, data, extra=None):
- """
- Create a new 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 zone: Zone where the requested record is created.
- :type zone: :class:`Zone`
-
- :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``
-
- :param extra: Extra attributes (driver specific). (optional)
- :type extra: ``dict``
-
- :rtype: :class:`Record`
- """
- new_record = self._format_record(name, type, data, extra)
- self.connection.request(
- '/v1/domains/%s/records' % (zone.domain), method='PATCH',
- data=[new_record])
- id = self._get_id_of_record(name, type)
- return Record(
- id=id, name=name,
- type=type, data=data,
- zone=zone, driver=self,
- ttl=new_record['ttl'],
- extra=extra)
-
- 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, ...).
- :type type: :class:`RecordType`
-
- :param data: Data for the record (depends on the record type).
- :type data: ``str``
-
- :param extra: (optional) Extra attributes (driver specific).
- :type extra: ``dict``
-
- :rtype: :class:`Record`
- """
- new_record = self._format_record(name, type, data, extra)
- self.connection.request(
- '/v1/domains/%s/records/%s/%s' % (record.zone.domain,
- record.type,
- record.name),
- method='PUT',
- data=[new_record])
- id = self._get_id_of_record(name, type)
- return Record(
- id=id, name=name,
- type=type, data=data,
- zone=record.zone, driver=self,
- ttl=new_record['ttl'],
- extra=extra)
-
- def get_record(self, zone_id, record_id):
- """
- Return a Record instance.
-
- :param zone_id: ID of the required zone
- :type zone_id: ``str``
-
- :param record_id: ID of the required record
- :type record_id: ``str``
-
- :rtype: :class:`Record`
- """
- parts = record_id.split(':')
- result = self.connection.request(
- '/v1/domains/%s/records/%s/%s' % (
- zone_id,
- parts[1],
- parts[0])).object
- if len(result) == 0:
- raise RecordDoesNotExistError(record_id,
- driver=self,
- record_id=record_id)
- return self._to_record(result[0],
- self.get_zone(zone_id))
-
- def get_zone(self, zone_id):
- """
- Get a zone (by domain)
-
- :param zone_id: The domain, not the ID
- :type zone_id: ``str``
-
- :rtype: :class:`Zone`
- """
- result = self.connection.request(
- '/v1/domains/%s/' % zone_id).object
- zone = self._to_zone(result)
- return zone
-
- def delete_zone(self, zone):
- """
- Delete a zone.
-
- Note: This will CANCEL a purchased domain
-
- :param zone: Zone to delete.
- :type zone: :class:`Zone`
-
- :rtype: ``bool``
- """
- self.connection.request(
- '/v1/domains/%s' % (zone.domain),
- method='DELETE')
- # no error means ok
- return True
-
- def ex_check_availability(self, domain, for_transfer=False):
- """
- Check the availability of the domain
-
- :param domain: the domain name e.g. wazzlewobbleflooble.com
- :type domain: ``str``
-
- :param for_transfer: Check if domain is available for transfer
- :type for_transfer: ``bool``
-
- :rtype: `list` of :class:`GoDaddyAvailability`
- """
- result = self.connection.request(
- '/v1/domains/available',
- method='GET',
- params={
- 'domain': domain,
- 'forTransfer': str(for_transfer)
- }
- ).object
- return GoDaddyAvailability(
- domain=result['domain'],
- available=result['available'],
- price=result['price'],
- currency=result['currency'],
- period=result['period']
- )
-
- def ex_list_tlds(self):
- """
- List available TLDs for sale
-
- :rtype: ``list`` of :class:`GoDaddyTLD`
- """
- result = self.connection.request(
- '/v1/domains/tlds',
- method='GET'
- ).object
- return self._to_tlds(result)
-
- def ex_get_purchase_schema(self, tld):
- """
- Get the schema that needs completing to purchase a new domain
- Use this in conjunction with ex_purchase_domain
-
- :param tld: The top level domain e.g com, eu, uk
- :type tld: ``str``
-
- :rtype: `dict` the JSON Schema
- """
- result = self.connection.request(
- '/v1/domains/purchase/schema/%s' % tld,
- method='GET'
- ).object
- return result
-
- def ex_get_agreements(self, tld, privacy=True):
- """
- Get the legal agreements for a tld
- Use this in conjunction with ex_purchase_domain
-
- :param tld: The top level domain e.g com, eu, uk
- :type tld: ``str``
-
- :rtype: `dict` the JSON Schema
- """
- result = self.connection.request(
- '/v1/domains/agreements',
- params={
- 'tlds': tld,
- 'privacy': str(privacy)
- },
- method='GET'
- ).object
- agreements = []
- for item in result:
- agreements.append(
- GoDaddyLegalAgreement(
- agreement_key=item['agreementKey'],
- title=item['title'],
- url=item['url'],
- content=item['content']))
- return agreements
-
- def ex_purchase_domain(self, purchase_request):
- """
- Purchase a domain with GoDaddy
-
- :param purchase_request: The completed document
- from ex_get_purchase_schema
- :type purchase_request: ``dict``
-
- :rtype: :class:`GoDaddyDomainPurchaseResponse` Your order
- """
- result = self.connection.request(
- '/v1/domains/purchase',
- data=purchase_request,
- method='POST'
- ).object
- return GoDaddyDomainPurchaseResponse(
- order_id=result['orderId'],
- item_count=result['itemCount'],
- total=result['total'],
- currency=result['currency']
- )
-
- def _format_record(self, name, type, data, extra):
- if extra is None:
- extra = {}
- new_record = {}
- if type == RecordType.SRV:
- new_record = {
- 'type': type,
- 'name': name,
- 'data': data,
- 'priority': 1,
- 'ttl': extra.get('ttl', 5),
- 'service': extra.get('service', ''),
- 'protocol': extra.get('protocol', ''),
- 'port': extra.get('port', ''),
- 'weight': extra.get('weight', '1')
- }
- else:
- new_record = {
- 'type': type,
- 'name': name,
- 'data': data,
- 'priority': 1,
- 'ttl': extra.get('ttl', 5)
- }
- return new_record
-
- def _to_zones(self, items):
- zones = []
- for item in items:
- zones.append(self._to_zone(item))
- return zones
-
- def _to_zone(self, item):
- extra = {"expires": item['expires']}
- zone = Zone(id=item['domainId'], domain=item['domain'],
- type='master', ttl=None,
- driver=self, extra=extra)
- return zone
-
- def _to_records(self, items, zone=None):
- records = []
-
- for item in items:
- records.append(self._to_record(item=item, zone=zone))
- return records
-
- def _to_record(self, item, zone=None):
- ttl = item['ttl']
- type = self._string_to_record_type(item['type'])
- name = item['name']
- id = self._get_id_of_record(name, type)
- record = Record(id=id, name=name,
- type=type, data=item['data'],
- zone=zone, driver=self,
- ttl=ttl)
- return record
-
- def _to_tlds(self, items):
- tlds = []
- for item in items:
- tlds.append(self._to_tld(item))
- return tlds
-
- def _to_tld(self, item):
- return GoDaddyTLD(
- name=item['name'],
- tld_type=item['type']
- )
-
- def _get_id_of_record(self, name, type):
- return '%s:%s' % (name, type)
-
-
-class GoDaddyAvailability(object):
- def __init__(self, domain, available, price, currency, period):
- self.domain = domain
- self.available = bool(available)
- # currency comes in micro-units, convert to dollars.
- self.price = float(price) / 1000000
- self.currency = currency
- self.period = int(period)
-
-
-class GoDaddyTLD(object):
- def __init__(self, name, tld_type):
- self.name = name
- self.type = tld_type
-
-
-class GoDaddyDomainPurchaseResponse(object):
- def __init__(self, order_id, item_count, total, currency):
- self.order_id = order_id
- self.item_count = item_count
- self.total = total
- self.current = currency
-
-
-class GoDaddyLegalAgreement(object):
- def __init__(self, agreement_key, title, url, content):
- self.agreement_key = agreement_key
- self.title = title
- self.url = url
- self.content = content
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8afcda91/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/google.py
----------------------------------------------------------------------
diff --git a/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/google.py b/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/google.py
deleted file mode 100644
index d0aebcb..0000000
--- a/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/google.py
+++ /dev/null
@@ -1,383 +0,0 @@
-# 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.
-
-__all__ = [
- 'GoogleDNSDriver'
-]
-
-# API docs: https://cloud.google.com/dns/api/v1
-API_VERSION = 'v1'
-
-import re
-from libcloud.common.google import GoogleResponse, GoogleBaseConnection
-from libcloud.common.google import ResourceNotFoundError
-from libcloud.dns.types import Provider, RecordType
-from libcloud.dns.types import ZoneDoesNotExistError, RecordDoesNotExistError
-from libcloud.dns.base import DNSDriver, Zone, Record
-
-
-class GoogleDNSResponse(GoogleResponse):
- pass
-
-
-class GoogleDNSConnection(GoogleBaseConnection):
- host = "www.googleapis.com"
- responseCls = GoogleDNSResponse
-
- def __init__(self, user_id, key, secure, auth_type=None,
- credential_file=None, project=None, **kwargs):
- super(GoogleDNSConnection, self).\
- __init__(user_id, key, secure=secure, auth_type=auth_type,
- credential_file=credential_file, **kwargs)
- self.request_path = '/dns/%s/projects/%s' % (API_VERSION, project)
-
-
-class GoogleDNSDriver(DNSDriver):
- type = Provider.GOOGLE
- name = 'Google DNS'
- connectionCls = GoogleDNSConnection
- website = 'https://cloud.google.com/'
-
- 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.SPF: 'SPF',
- RecordType.SRV: 'SRV',
- RecordType.TXT: 'TXT',
- }
-
- def __init__(self, user_id, key, project=None, auth_type=None, scopes=None,
- **kwargs):
- self.auth_type = auth_type
- self.project = project
- self.scopes = scopes
- if not self.project:
- raise ValueError('Project name must be specified using '
- '"project" keyword.')
- super(GoogleDNSDriver, self).__init__(user_id, key, **kwargs)
-
- def iterate_zones(self):
- """
- Return a generator to iterate over available zones.
-
- :rtype: ``generator`` of :class:`Zone`
- """
- return self._get_more('zones')
-
- def iterate_records(self, zone):
- """
- Return a generator to iterate over records for the provided zone.
-
- :param zone: Zone to list records for.
- :type zone: :class:`Zone`
-
- :rtype: ``generator`` of :class:`Record`
- """
- return self._get_more('records', zone=zone)
-
- def get_zone(self, zone_id):
- """
- Return a Zone instance.
-
- :param zone_id: ID of the required zone
- :type zone_id: ``str``
-
- :rtype: :class:`Zone`
- """
- request = '/managedZones/%s' % (zone_id)
-
- try:
- response = self.connection.request(request, method='GET').object
- except ResourceNotFoundError:
- raise ZoneDoesNotExistError(value='',
- driver=self.connection.driver,
- zone_id=zone_id)
-
- return self._to_zone(response)
-
- def get_record(self, zone_id, record_id):
- """
- Return a Record instance.
-
- :param zone_id: ID of the required zone
- :type zone_id: ``str``
-
- :param record_id: ID of the required record
- :type record_id: ``str``
-
- :rtype: :class:`Record`
- """
- (record_type, record_name) = record_id.split(':', 1)
-
- params = {
- 'name': record_name,
- 'type': record_type,
- }
-
- request = '/managedZones/%s/rrsets' % (zone_id)
-
- try:
- response = self.connection.request(request, method='GET',
- params=params).object
- except ResourceNotFoundError:
- raise ZoneDoesNotExistError(value='',
- driver=self.connection.driver,
- zone_id=zone_id)
-
- if len(response['rrsets']) > 0:
- zone = self.get_zone(zone_id)
- return self._to_record(response['rrsets'][0], zone)
-
- raise RecordDoesNotExistError(value='', driver=self.connection.driver,
- record_id=record_id)
-
- def create_zone(self, domain, type='master', ttl=None, extra=None):
- """
- Create a new zone.
-
- :param domain: Zone domain name (e.g. example.com.) with a \'.\'
- at the end.
- :type domain: ``str``
-
- :param type: Zone type (master is the only one supported).
- :type type: ``str``
-
- :param ttl: TTL for new records. (unused)
- :type ttl: ``int``
-
- :param extra: Extra attributes (driver specific). (optional)
- :type extra: ``dict``
-
- :rtype: :class:`Zone`
- """
- name = None
- description = ''
-
- if extra:
- description = extra.get('description')
- name = extra.get('name')
-
- if name is None:
- name = self._cleanup_domain(domain)
-
- data = {
- 'dnsName': domain,
- 'name': name,
- 'description': description,
- }
-
- request = '/managedZones'
- response = self.connection.request(request, method='POST',
- data=data).object
- return self._to_zone(response)
-
- def create_record(self, name, zone, type, data, extra=None):
- """
- Create a new record.
-
- :param name: Record name fully qualified, with a \'.\' at the end.
- :type name: ``str``
-
- :param zone: Zone where the requested record is created.
- :type zone: :class:`Zone`
-
- :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``
-
- :param extra: Extra attributes. (optional)
- :type extra: ``dict``
-
- :rtype: :class:`Record`
- """
- ttl = data.get('ttl', 0)
- rrdatas = data.get('rrdatas', [])
-
- data = {
- 'additions': [
- {
- 'name': name,
- 'type': type,
- 'ttl': int(ttl),
- 'rrdatas': rrdatas,
- }
- ]
- }
- request = '/managedZones/%s/changes' % (zone.id)
- response = self.connection.request(request, method='POST',
- data=data).object
- return self._to_record(response['additions'][0], zone)
-
- def delete_zone(self, zone):
- """
- Delete a zone.
-
- Note: This will delete all the records belonging to this zone.
-
- :param zone: Zone to delete.
- :type zone: :class:`Zone`
-
- :rtype: ``bool``
- """
- request = '/managedZones/%s' % (zone.id)
- response = self.connection.request(request, method='DELETE')
- return response.success()
-
- def delete_record(self, record):
- """
- Delete a record.
-
- :param record: Record to delete.
- :type record: :class:`Record`
-
- :rtype: ``bool``
- """
- data = {
- 'deletions': [
- {
- 'name': record.name,
- 'type': record.type,
- 'rrdatas': record.data['rrdatas'],
- 'ttl': record.data['ttl']
- }
- ]
- }
- request = '/managedZones/%s/changes' % (record.zone.id)
- response = self.connection.request(request, method='POST',
- data=data)
- return response.success()
-
- def ex_bulk_record_changes(self, zone, records):
- """
- Bulk add and delete records.
-
- :param zone: Zone where the requested record changes are done.
- :type zone: :class:`Zone`
-
- :param records: Dictionary of additions list or deletions list, or both
- of resourceRecordSets. For example:
- {'additions': [{'rrdatas': ['127.0.0.1'],
- 'kind': 'dns#resourceRecordSet',
- 'type': 'A',
- 'name': 'www.example.com.',
- 'ttl': '300'}],
- 'deletions': [{'rrdatas': ['127.0.0.1'],
- 'kind': 'dns#resourceRecordSet',
- 'type': 'A',
- 'name': 'www2.example.com.',
- 'ttl': '300'}]}
- :type records: ``dict``
-
- :return: A dictionary of Record additions and deletions.
- :rtype: ``dict`` of additions and deletions of :class:`Record`
- """
-
- request = '/managedZones/%s/changes' % (zone.id)
- response = self.connection.request(request, method='POST',
- data=records).object
-
- response_data = {
- 'additions': self._to_records(response.get('additions', []), zone),
- 'deletions': self._to_records(response.get('deletions', []), zone),
- }
-
- return response_data
-
- def _get_more(self, rtype, **kwargs):
- last_key = None
- exhausted = False
- while not exhausted:
- items, last_key, exhausted = self._get_data(rtype, last_key,
- **kwargs)
- for item in items:
- yield item
-
- def _get_data(self, rtype, last_key, **kwargs):
- params = {}
-
- if last_key:
- params['pageToken'] = last_key
-
- if rtype == 'zones':
- request = '/managedZones'
- transform_func = self._to_zones
- r_key = 'managedZones'
- elif rtype == 'records':
- zone = kwargs['zone']
- request = '/managedZones/%s/rrsets' % (zone.id)
- transform_func = self._to_records
- r_key = 'rrsets'
-
- response = self.connection.request(request, method='GET',
- params=params,)
-
- if response.success():
- nextpage = response.object.get('nextPageToken', None)
- items = transform_func(response.object.get(r_key), **kwargs)
- exhausted = False if nextpage is not None else True
- return items, nextpage, exhausted
- else:
- return [], None, True
-
- def _ex_connection_class_kwargs(self):
- return {'auth_type': self.auth_type,
- 'project': self.project,
- 'scopes': self.scopes}
-
- def _to_zones(self, response):
- zones = []
- for r in response:
- zones.append(self._to_zone(r))
- return zones
-
- def _to_zone(self, r):
- extra = {}
-
- if 'description' in r:
- extra['description'] = r.get('description')
-
- extra['creationTime'] = r.get('creationTime')
- extra['nameServers'] = r.get('nameServers')
- extra['id'] = r.get('id')
-
- return Zone(id=r['name'], domain=r['dnsName'],
- type='master', ttl=0, driver=self, extra=extra)
-
- def _to_records(self, response, zone):
- records = []
- for r in response:
- records.append(self._to_record(r, zone))
- return records
-
- def _to_record(self, r, zone):
- record_id = '%s:%s' % (r['type'], r['name'])
- return Record(id=record_id, name=r['name'],
- type=r['type'], data=r, zone=zone,
- driver=self, ttl=r.get('ttl', None),
- extra={})
-
- def _cleanup_domain(self, domain):
- # name can only contain lower case alphanumeric characters and hyphens
- domain = re.sub(r'[^a-zA-Z0-9-]', '-', domain)
- if domain[-1] == '-':
- domain = domain[:-1]
- return domain
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8afcda91/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/hostvirtual.py
----------------------------------------------------------------------
diff --git a/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/hostvirtual.py b/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/hostvirtual.py
deleted file mode 100644
index 75a3ec1..0000000
--- a/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/hostvirtual.py
+++ /dev/null
@@ -1,257 +0,0 @@
-# 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.
-
-__all__ = [
- 'HostVirtualDNSDriver'
-]
-
-import sys
-
-try:
- import simplejson as json
-except:
- import json
-
-from libcloud.utils.py3 import httplib
-from libcloud.utils.misc import merge_valid_keys, get_new_obj
-from libcloud.common.hostvirtual import HostVirtualResponse
-from libcloud.common.hostvirtual import HostVirtualConnection
-from libcloud.compute.drivers.hostvirtual import API_ROOT
-from libcloud.dns.types import Provider, RecordType
-from libcloud.dns.types import ZoneDoesNotExistError, RecordDoesNotExistError
-from libcloud.dns.base import DNSDriver, Zone, Record
-
-VALID_RECORD_EXTRA_PARAMS = ['prio', 'ttl']
-
-
-class HostVirtualDNSResponse(HostVirtualResponse):
- def parse_error(self):
- context = self.connection.context
- status = int(self.status)
-
- if status == httplib.NOT_FOUND:
- if context['resource'] == 'zone':
- raise ZoneDoesNotExistError(
- value=self.parse_body()['error']['message'],
- driver=self, zone_id=context['id'])
- elif context['resource'] == 'record':
- raise RecordDoesNotExistError(
- value=self.parse_body()['error']['message'],
- driver=self, record_id=context['id'])
-
- super(HostVirtualDNSResponse, self).parse_error()
- return self.body
-
-
-class HostVirtualDNSConnection(HostVirtualConnection):
- responseCls = HostVirtualDNSResponse
-
-
-class HostVirtualDNSDriver(DNSDriver):
- type = Provider.HOSTVIRTUAL
- name = 'Host Virtual DNS'
- website = 'https://www.hostvirtual.com/'
- connectionCls = HostVirtualDNSConnection
-
- RECORD_TYPE_MAP = {
- RecordType.A: 'A',
- RecordType.AAAA: 'AAAA',
- RecordType.CNAME: 'CNAME',
- RecordType.MX: 'MX',
- RecordType.NS: 'SPF',
- RecordType.SRV: 'SRV',
- RecordType.TXT: 'TXT',
- }
-
- def __init__(self, key, secure=True, host=None, port=None):
- super(HostVirtualDNSDriver, self).__init__(key=key, secure=secure,
- host=host, port=port)
-
- def _to_zones(self, items):
- zones = []
- for item in items:
- zones.append(self._to_zone(item))
- return zones
-
- def _to_zone(self, item):
- extra = {}
- if 'records' in item:
- extra['records'] = item['records']
- if item['type'] == 'NATIVE':
- item['type'] = 'master'
- zone = Zone(id=item['id'], domain=item['name'],
- type=item['type'], ttl=item['ttl'],
- driver=self, extra=extra)
- return zone
-
- def _to_records(self, items, zone=None):
- records = []
-
- for item in items:
- records.append(self._to_record(item=item, zone=zone))
- return records
-
- def _to_record(self, item, zone=None):
- extra = {'ttl': item['ttl']}
- type = self._string_to_record_type(item['type'])
- name = item['name'][:-len(zone.domain) - 1]
- record = Record(id=item['id'], name=name,
- type=type, data=item['content'],
- zone=zone, driver=self, ttl=item['ttl'],
- extra=extra)
- return record
-
- def list_zones(self):
- result = self.connection.request(
- API_ROOT + '/dns/zones/').object
- zones = self._to_zones(result)
- return zones
-
- def list_records(self, zone):
- params = {'id': zone.id}
- self.connection.set_context({'resource': 'zone', 'id': zone.id})
- try:
- result = self.connection.request(
- API_ROOT + '/dns/records/', params=params).object
- except ZoneDoesNotExistError:
- e = sys.exc_info()[1]
- if 'Not Found: No Records Found' in e.value:
- return []
- raise e
- records = self._to_records(items=result, zone=zone)
- return records
-
- def get_zone(self, zone_id):
- params = {'id': zone_id}
- self.connection.set_context({'resource': 'zone', 'id': zone_id})
- result = self.connection.request(
- API_ROOT + '/dns/zone/', params=params).object
- if 'id' not in result:
- raise ZoneDoesNotExistError(value='', driver=self, zone_id=zone_id)
- zone = self._to_zone(result)
- return zone
-
- def get_record(self, zone_id, record_id):
- zone = self.get_zone(zone_id=zone_id)
- params = {'id': record_id}
- self.connection.set_context({'resource': 'record', 'id': record_id})
- result = self.connection.request(
- API_ROOT + '/dns/record/', params=params).object
- if 'id' not in result:
- raise RecordDoesNotExistError(value='',
- driver=self, record_id=record_id)
- record = self._to_record(item=result, zone=zone)
- return record
-
- def delete_zone(self, zone):
- params = {'id': zone.id}
- self.connection.set_context({'resource': 'zone', 'id': zone.id})
- result = self.connection.request(
- API_ROOT + '/dns/zone/', params=params, method='DELETE').object
- return bool(result)
-
- def delete_record(self, record):
- params = {'id': record.id}
- self.connection.set_context({'resource': 'record', 'id': record.id})
- result = self.connection.request(
- API_ROOT + '/dns/record/', params=params, method='DELETE').object
-
- return bool(result)
-
- def create_zone(self, domain, type='NATIVE', ttl=None, extra=None):
- if type == 'master':
- type = 'NATIVE'
- elif type == 'slave':
- type = 'SLAVE'
- params = {'name': domain, 'type': type, 'ttl': ttl}
- result = self.connection.request(
- API_ROOT + '/dns/zone/',
- data=json.dumps(params), method='POST').object
- extra = {
- 'soa': result['soa'],
- 'ns': result['ns']
- }
- zone = Zone(id=result['id'], domain=domain,
- type=type, ttl=ttl, extra=extra, driver=self)
- return zone
-
- def update_zone(self, zone, domain=None, type=None, ttl=None, extra=None):
- params = {'id': zone.id}
- if domain:
- params['name'] = domain
- if type:
- params['type'] = type
- self.connection.set_context({'resource': 'zone', 'id': zone.id})
- self.connection.request(API_ROOT + '/dns/zone/',
- data=json.dumps(params), method='PUT').object
- updated_zone = get_new_obj(
- obj=zone, klass=Zone,
- attributes={
- 'domain': domain,
- 'type': type,
- 'ttl': ttl,
- 'extra': extra
- })
- return updated_zone
-
- def create_record(self, name, zone, type, data, extra=None):
- params = {
- 'name': name,
- 'type': self.RECORD_TYPE_MAP[type],
- 'domain_id': zone.id,
- 'content': data
- }
- merged = merge_valid_keys(
- params=params,
- valid_keys=VALID_RECORD_EXTRA_PARAMS,
- extra=extra
- )
- self.connection.set_context({'resource': 'zone', 'id': zone.id})
- result = self.connection.request(
- API_ROOT + '/dns/record/',
- data=json.dumps(params), method='POST').object
- record = Record(id=result['id'], name=name,
- type=type, data=data,
- extra=merged, zone=zone,
- ttl=merged.get('ttl', None),
- driver=self)
- return record
-
- def update_record(self, record, name=None, type=None,
- data=None, extra=None):
- params = {
- 'domain_id': record.zone.id,
- 'record_id': record.id
- }
- if name:
- params['name'] = name
- if data:
- params['content'] = data
- if type is not None:
- params['type'] = self.RECORD_TYPE_MAP[type]
- merged = merge_valid_keys(
- params=params,
- valid_keys=VALID_RECORD_EXTRA_PARAMS,
- extra=extra
- )
- self.connection.set_context({'resource': 'record', 'id': record.id})
- self.connection.request(API_ROOT + '/dns/record/',
- data=json.dumps(params), method='PUT').object
- updated_record = get_new_obj(
- obj=record, klass=Record, attributes={
- 'name': name, 'data': data,
- 'type': type,
- 'extra': merged
- })
- return updated_record
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8afcda91/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/linode.py
----------------------------------------------------------------------
diff --git a/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/linode.py b/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/linode.py
deleted file mode 100644
index 5d497ed..0000000
--- a/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/linode.py
+++ /dev/null
@@ -1,273 +0,0 @@
-# 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.
-
-__all__ = [
- 'LinodeDNSDriver'
-]
-
-from libcloud.utils.misc import merge_valid_keys, get_new_obj
-from libcloud.common.linode import (API_ROOT, LinodeException,
- LinodeConnection, LinodeResponse)
-from libcloud.dns.types import Provider, RecordType
-from libcloud.dns.types import ZoneDoesNotExistError, RecordDoesNotExistError
-from libcloud.dns.base import DNSDriver, Zone, Record
-
-
-VALID_ZONE_EXTRA_PARAMS = ['SOA_Email', 'Refresh_sec', 'Retry_sec',
- 'Expire_sec', 'status', 'master_ips']
-
-VALID_RECORD_EXTRA_PARAMS = ['Priority', 'Weight', 'Port', 'Protocol',
- 'TTL_sec']
-
-
-class LinodeDNSResponse(LinodeResponse):
- def _make_excp(self, error):
- result = super(LinodeDNSResponse, self)._make_excp(error)
- if isinstance(result, LinodeException) and result.code == 5:
- context = self.connection.context
-
- if context['resource'] == 'zone':
- result = ZoneDoesNotExistError(value='',
- driver=self.connection.driver,
- zone_id=context['id'])
-
- elif context['resource'] == 'record':
- result = RecordDoesNotExistError(value='',
- driver=self.connection.driver,
- record_id=context['id'])
- return result
-
-
-class LinodeDNSConnection(LinodeConnection):
- responseCls = LinodeDNSResponse
-
-
-class LinodeDNSDriver(DNSDriver):
- type = Provider.LINODE
- name = 'Linode DNS'
- website = 'http://www.linode.com/'
- connectionCls = LinodeDNSConnection
-
- RECORD_TYPE_MAP = {
- RecordType.NS: 'NS',
- RecordType.MX: 'MX',
- RecordType.A: 'A',
- RecordType.AAAA: 'AAAA',
- RecordType.CNAME: 'CNAME',
- RecordType.TXT: 'TXT',
- RecordType.SRV: 'SRV',
- }
-
- def list_zones(self):
- params = {'api_action': 'domain.list'}
- data = self.connection.request(API_ROOT, params=params).objects[0]
- zones = self._to_zones(data)
- return zones
-
- def list_records(self, zone):
- params = {'api_action': 'domain.resource.list', 'DOMAINID': zone.id}
-
- self.connection.set_context(context={'resource': 'zone',
- 'id': zone.id})
- data = self.connection.request(API_ROOT, params=params).objects[0]
- records = self._to_records(items=data, zone=zone)
- return records
-
- def get_zone(self, zone_id):
- params = {'api_action': 'domain.list', 'DomainID': zone_id}
- self.connection.set_context(context={'resource': 'zone',
- 'id': zone_id})
- data = self.connection.request(API_ROOT, params=params).objects[0]
- zones = self._to_zones(data)
-
- if len(zones) != 1:
- raise ZoneDoesNotExistError(value='', driver=self, zone_id=zone_id)
-
- return zones[0]
-
- def get_record(self, zone_id, record_id):
- zone = self.get_zone(zone_id=zone_id)
- params = {'api_action': 'domain.resource.list', 'DomainID': zone_id,
- 'ResourceID': record_id}
- self.connection.set_context(context={'resource': 'record',
- 'id': record_id})
- data = self.connection.request(API_ROOT, params=params).objects[0]
- records = self._to_records(items=data, zone=zone)
-
- if len(records) != 1:
- raise RecordDoesNotExistError(value='', driver=self,
- record_id=record_id)
-
- return records[0]
-
- def create_zone(self, domain, type='master', ttl=None, extra=None):
- """
- Create a new zone.
-
- API docs: http://www.linode.com/api/dns/domain.create
- """
- params = {'api_action': 'domain.create', 'Type': type,
- 'Domain': domain}
-
- if ttl:
- params['TTL_sec'] = ttl
-
- merged = merge_valid_keys(params=params,
- valid_keys=VALID_ZONE_EXTRA_PARAMS,
- extra=extra)
- data = self.connection.request(API_ROOT, params=params).objects[0]
- zone = Zone(id=data['DomainID'], domain=domain, type=type, ttl=ttl,
- extra=merged, driver=self)
- return zone
-
- def update_zone(self, zone, domain=None, type=None, ttl=None, extra=None):
- """
- Update an existing zone.
-
- API docs: http://www.linode.com/api/dns/domain.update
- """
- params = {'api_action': 'domain.update', 'DomainID': zone.id}
-
- if type:
- params['Type'] = type
-
- if domain:
- params['Domain'] = domain
-
- if ttl:
- params['TTL_sec'] = ttl
-
- merged = merge_valid_keys(params=params,
- valid_keys=VALID_ZONE_EXTRA_PARAMS,
- extra=extra)
- self.connection.request(API_ROOT, params=params).objects[0]
- updated_zone = get_new_obj(obj=zone, klass=Zone,
- attributes={'domain': domain,
- 'type': type, 'ttl': ttl,
- 'extra': merged})
- return updated_zone
-
- def create_record(self, name, zone, type, data, extra=None):
- """
- Create a new record.
-
- API docs: http://www.linode.com/api/dns/domain.resource.create
- """
- params = {'api_action': 'domain.resource.create', 'DomainID': zone.id,
- 'Name': name, 'Target': data,
- 'Type': self.RECORD_TYPE_MAP[type]}
- merged = merge_valid_keys(params=params,
- valid_keys=VALID_RECORD_EXTRA_PARAMS,
- extra=extra)
-
- result = self.connection.request(API_ROOT, params=params).objects[0]
- record = Record(id=result['ResourceID'], name=name, type=type,
- data=data, extra=merged, zone=zone, driver=self,
- ttl=merged.get('TTL_sec', None))
- return record
-
- def update_record(self, record, name=None, type=None, data=None,
- extra=None):
- """
- Update an existing record.
-
- API docs: http://www.linode.com/api/dns/domain.resource.update
- """
- params = {'api_action': 'domain.resource.update',
- 'ResourceID': record.id, 'DomainID': record.zone.id}
-
- if name:
- params['Name'] = name
-
- if data:
- params['Target'] = data
-
- if type is not None:
- params['Type'] = self.RECORD_TYPE_MAP[type]
-
- merged = merge_valid_keys(params=params,
- valid_keys=VALID_RECORD_EXTRA_PARAMS,
- extra=extra)
-
- self.connection.request(API_ROOT, params=params).objects[0]
- updated_record = get_new_obj(obj=record, klass=Record,
- attributes={'name': name, 'data': data,
- 'type': type,
- 'extra': merged})
- return updated_record
-
- def delete_zone(self, zone):
- params = {'api_action': 'domain.delete', 'DomainID': zone.id}
-
- self.connection.set_context(context={'resource': 'zone',
- 'id': zone.id})
- data = self.connection.request(API_ROOT, params=params).objects[0]
-
- return 'DomainID' in data
-
- def delete_record(self, record):
- params = {'api_action': 'domain.resource.delete',
- 'DomainID': record.zone.id, 'ResourceID': record.id}
-
- self.connection.set_context(context={'resource': 'record',
- 'id': record.id})
- data = self.connection.request(API_ROOT, params=params).objects[0]
-
- return 'ResourceID' in data
-
- def _to_zones(self, items):
- """
- Convert a list of items to the Zone objects.
- """
- zones = []
-
- for item in items:
- zones.append(self._to_zone(item))
-
- return zones
-
- def _to_zone(self, item):
- """
- Build an Zone object from the item dictionary.
- """
- extra = {'SOA_Email': item['SOA_EMAIL'], 'status': item['STATUS'],
- 'description': item['DESCRIPTION']}
- zone = Zone(id=item['DOMAINID'], domain=item['DOMAIN'],
- type=item['TYPE'], ttl=item['TTL_SEC'], driver=self,
- extra=extra)
- return zone
-
- def _to_records(self, items, zone=None):
- """
- Convert a list of items to the Record objects.
- """
- records = []
-
- for item in items:
- records.append(self._to_record(item=item, zone=zone))
-
- return records
-
- def _to_record(self, item, zone=None):
- """
- Build a Record object from the item dictionary.
- """
- extra = {'protocol': item['PROTOCOL'], 'ttl_sec': item['TTL_SEC'],
- 'port': item['PORT'], 'weight': item['WEIGHT']}
- type = self._string_to_record_type(item['TYPE'])
- record = Record(id=item['RESOURCEID'], name=item['NAME'], type=type,
- data=item['TARGET'], zone=zone, driver=self,
- ttl=item['TTL_SEC'], extra=extra)
- return record
http://git-wip-us.apache.org/repos/asf/libcloud/blob/8afcda91/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/liquidweb.py
----------------------------------------------------------------------
diff --git a/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/liquidweb.py b/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/liquidweb.py
deleted file mode 100644
index 803849a..0000000
--- a/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/liquidweb.py
+++ /dev/null
@@ -1,388 +0,0 @@
-# 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.
-"""
-Liquid Web DNS Driver
-"""
-
-import sys
-
-try:
- import simplejson as json
-except ImportError:
- import json
-
-from libcloud.common.liquidweb import LiquidWebResponse, LiquidWebConnection
-from libcloud.common.liquidweb import APIException
-from libcloud.dns.base import DNSDriver, Zone, Record
-from libcloud.dns.types import Provider, RecordType
-from libcloud.dns.types import ZoneDoesNotExistError, ZoneAlreadyExistsError
-from libcloud.dns.types import RecordDoesNotExistError
-from libcloud.dns.types import RecordAlreadyExistsError
-
-
-__all__ = [
- 'LiquidWebDNSDriver'
-]
-
-
-class LiquidWebDNSResponse(LiquidWebResponse):
- pass
-
-
-class LiquidWebDNSConnection(LiquidWebConnection):
- responseCls = LiquidWebDNSResponse
-
-
-class LiquidWebDNSDriver(DNSDriver):
- type = Provider.LIQUIDWEB
- name = 'Liquidweb DNS'
- website = 'https://www.liquidweb.com'
- connectionCls = LiquidWebDNSConnection
-
- 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):
- """
- Return a list of zones.
-
- :return: ``list`` of :class:`Zone`
- """
- action = '/v1/Network/DNS/Zone/list'
- response = self.connection.request(action=action,
- method='POST')
-
- zones = self._to_zones(response.objects[0])
-
- return zones
-
- def list_records(self, zone):
- """
- Return a list of records for the provided zone.
-
- :param zone: Zone to list records for.
- :type zone: :class:`Zone`
-
- :return: ``list`` of :class:`Record`
- """
- action = '/v1/Network/DNS/Record/list'
- data = json.dumps({'params': {'zone_id': zone.id}})
- response = self.connection.request(action=action,
- method='POST',
- data=data)
-
- records = self._to_records(response.objects[0], zone=zone)
-
- return records
-
- def get_zone(self, zone_id):
- """
- Return a Zone instance.
-
- :param zone_id: ID of the required zone
- :type zone_id: ``str``
-
- :rtype: :class:`Zone`
- """
- action = '/v1/Network/DNS/Zone/details'
- data = json.dumps({'params': {'id': zone_id}})
- try:
- response = self.connection.request(action=action,
- method='POST',
- data=data)
- except APIException:
- e = sys.exc_info()[1]
- if e.error_class == 'LW::Exception::RecordNotFound':
- raise ZoneDoesNotExistError(zone_id=zone_id,
- value=e.value, driver=self)
- else:
- raise e
-
- zone = self._to_zone(response.objects[0])
- return zone
-
- def get_record(self, zone_id, record_id):
- """
- Return a Record instance.
-
- :param zone_id: ID of the required zone
- :type zone_id: ``str``
-
- :param record_id: ID of the required record
- :type record_id: ``str``
-
- :rtype: :class:`Record`
- """
- zone = self.get_zone(zone_id=zone_id)
- action = '/v1/Network/DNS/Record/details'
- data = json.dumps({'params': {'id': record_id}})
- try:
- response = self.connection.request(action=action,
- method='POST',
- data=data)
- except APIException:
- e = sys.exc_info()[1]
- if e.error_class == 'LW::Exception::RecordNotFound':
- raise RecordDoesNotExistError(record_id=record_id, driver=self,
- value=e.value)
- else:
- raise e
-
- record = self._to_record(response.objects[0], zone=zone)
- return record
-
- 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',
- data=data)
- except APIException:
- e = sys.exc_info()[1]
- if e.error_class == 'LW::Exception::DuplicateRecord':
- raise ZoneAlreadyExistsError(zone_id=domain,
- value=e.value,
- driver=self)
- else:
- raise e
-
- zone = self._to_zone(response.objects[0])
-
- return zone
-
- def create_record(self, name, zone, type, data, extra=None):
- """
- Create a 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 zone: Zone which the records will be created for.
- :type zone: :class:`Zone`
-
- :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 ('prio', 'ttl').
- :type extra: ``dict``
-
- :rtype: :class:`Record`
- """
- action = '/v1/Network/DNS/Record/create'
- to_post = {'params': {'name': name,
- 'rdata': data,
- 'type': type,
- 'zone': zone.domain,
- 'zone_id': zone.id
- }
- }
- if extra is not None:
- to_post['params'].update(extra)
- data = json.dumps(to_post)
- try:
- response = self.connection.request(action=action,
- method='POST',
- data=data)
- except APIException:
- e = sys.exc_info()[1]
- if e.error_class == 'LW::Exception::DuplicateRecord':
- raise RecordAlreadyExistsError(record_id=name,
- value=e.value,
- driver=self)
- else:
- raise e
-
- record = self._to_record(response.objects[0], zone=zone)
- return record
-
- 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``
-
- :rtype: :class:`Record`
- """
- zone = record.zone
- action = '/v1/Network/DNS/Record/update'
- to_post = {'params': {'id': int(record.id),
- 'name': name,
- 'rdata': data}}
- if extra is not None:
- to_post['params'].update(extra)
- j_data = json.dumps(to_post)
- try:
- response = self.connection.request(action=action,
- method='PUT',
- data=j_data)
- except APIException:
- e = sys.exc_info()[1]
- if e.error_class == 'LW::Exception::RecordNotFound':
- raise RecordDoesNotExistError(record_id=record.id, driver=self,
- value=e.value)
- else:
- raise e
-
- record = self._to_record(response.objects[0], zone=zone)
- return record
-
- def delete_zone(self, zone):
- """
- Delete a zone.
-
- Note: This will delete all the records belonging to this zone.
-
- :param zone: Zone to delete.
- :type zone: :class:`Zone`
-
- :rtype: ``bool``
- """
- action = '/v1/Network/DNS/Zone/delete'
- data = json.dumps({'params': {'id': zone.id}})
- try:
- response = self.connection.request(action=action,
- method='POST',
- data=data)
- except APIException:
- e = sys.exc_info()[1]
- if e.error_class == 'LW::Exception::RecordNotFound':
- raise ZoneDoesNotExistError(zone_id=zone.id,
- value=e.value, driver=self)
- else:
- raise e
-
- return zone.domain in response.objects
-
- def delete_record(self, record):
- """
- Delete a record.
-
- :param record: Record to delete.
- :type record: :class:`Record`
-
- :rtype: ``bool``
- """
- action = '/v1/Network/DNS/Record/delete'
- data = json.dumps({'params': {'id': record.id}})
- try:
- response = self.connection.request(action=action,
- method='POST',
- data=data)
- except APIException:
- e = sys.exc_info()[1]
- if e.error_class == 'LW::Exception::RecordNotFound':
- raise RecordDoesNotExistError(record_id=record.id, driver=self,
- value=e.value)
- else:
- raise e
-
- return record.id in response.objects
-
- def _to_zone(self, item):
- common_attr = ['id', 'name', 'type']
- extra = {}
- for key in item:
- if key not in common_attr:
- extra[key] = item.get(key)
- zone = Zone(domain=item['name'], id=item['id'], type=item['type'],
- ttl=None, driver=self, extra=extra)
-
- 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', 'rdata', 'name', 'type']
- extra = {}
- for key in item:
- if key not in common_attr:
- extra[key] = item.get(key)
- record = Record(id=item['id'], name=item['name'], type=item['type'],
- data=item['rdata'], 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/8afcda91/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/luadns.py
----------------------------------------------------------------------
diff --git a/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/luadns.py b/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/luadns.py
deleted file mode 100644
index 48ed555..0000000
--- a/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/luadns.py
+++ /dev/null
@@ -1,293 +0,0 @@
-import sys
-
-try:
- import simplejson as json
-except ImportError:
- import json
-
-from libcloud.common.luadns import LuadnsResponse, LuadnsConnection
-from libcloud.common.luadns import LuadnsException
-from libcloud.dns.base import DNSDriver, Zone, Record
-from libcloud.dns.types import Provider, RecordType
-from libcloud.dns.types import ZoneDoesNotExistError, ZoneAlreadyExistsError
-from libcloud.dns.types import RecordDoesNotExistError
-
-
-__all__ = [
- 'LuadnsDNSDriver'
-]
-
-
-class LuadnsDNSResponse(LuadnsResponse):
- pass
-
-
-class LuadnsDNSConnection(LuadnsConnection):
- responseCls = LuadnsDNSResponse
-
-
-class LuadnsDNSDriver(DNSDriver):
- type = Provider.LUADNS
- name = 'Luadns'
- website = 'https://www.luadns.com'
- connectionCls = LuadnsDNSConnection
-
- 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):
- """
- Return a list of zones.
-
- :return: ``list`` of :class:`Zone`
- """
- action = '/v1/zones'
- response = self.connection.request(action=action,
- method='GET')
- zones = self._to_zones(response.parse_body())
-
- return zones
-
- def get_zone(self, zone_id):
- """
- Return a Zone instance.
-
- :param zone_id: ID of the required zone
- :type zone_id: ``str``
-
- :rtype: :class:`Zone`
- """
- action = '/v1/zones/%s' % zone_id
- try:
- response = self.connection.request(action=action)
- except LuadnsException:
- e = sys.exc_info()[1]
- if e.message in ['Zone not found.', 'Resource not found.']:
- raise ZoneDoesNotExistError(zone_id=zone_id,
- value='', driver=self)
- else:
- raise e
-
- zone = self._to_zone(response.parse_body())
-
- return zone
-
- def delete_zone(self, zone):
- """
- Delete a zone.
-
- Note: This will delete all the records belonging to this zone.
-
- :param zone: Zone to delete.
- :type zone: :class:`Zone`
-
- :rtype: ``bool``
- """
- action = '/v1/zones/%s' % zone.id
- try:
- response = self.connection.request(action=action,
- method='DELETE')
- except LuadnsException:
- e = sys.exc_info()[1]
- if e.message in ['Resource not found.', 'Zone not found.']:
- raise ZoneDoesNotExistError(zone_id=zone.id,
- value='', driver=self)
- else:
- raise e
-
- return response.status == 200
-
- 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`
- """
- action = '/v1/zones'
- data = json.dumps({'name': domain})
- try:
- response = self.connection.request(action=action,
- method='POST',
- data=data)
- except LuadnsException:
- e = sys.exc_info()[1]
- if e.message == "Zone '%s' is taken already." % domain:
- raise ZoneAlreadyExistsError(zone_id=domain,
- value='',
- driver=self)
- else:
- raise e
- zone = self._to_zone(response.parse_body())
-
- return zone
-
- def list_records(self, zone):
- """
- Return a list of records for the provided zone.
-
- :param zone: Zone to list records for.
- :type zone: :class:`Zone`
-
- :return: ``list`` of :class:`Record`
- """
- action = '/v1/zones/%s/records' % zone.id
- response = self.connection.request(action=action)
- records = self._to_records(response.parse_body(), zone=zone)
-
- return records
-
- def get_record(self, zone_id, record_id):
- """
- Return a Record instance.
-
- :param zone_id: ID of the required zone
- :type zone_id: ``str``
-
- :param record_id: ID of the required record
- :type record_id: ``str``
-
- :rtype: :class:`Record`
- """
- zone = self.get_zone(zone_id=zone_id)
- action = '/v1/zones/%s/records/%s' % (zone_id, record_id)
- try:
- response = self.connection.request(action=action)
- except LuadnsException:
- e = sys.exc_info()[1]
- if e.message == 'Record not found.':
- raise RecordDoesNotExistError(record_id=record_id, driver=self,
- value='')
- else:
- raise e
-
- record = self._to_record(response.parse_body(), zone=zone)
-
- return record
-
- def delete_record(self, record):
- """
- Delete a record.
-
- :param record: Record to delete.
- :type record: :class:`Record`
-
- :rtype: ``bool``
- """
- action = '/v1/zones/%s/records/%s' % (record.zone.id, record.id)
- try:
- response = self.connection.request(action=action,
- method='DELETE')
- except LuadnsException:
- e = sys.exc_info()[1]
- if e.message == 'Record not found.':
- raise RecordDoesNotExistError(record_id=record.id, driver=self,
- value='')
- else:
- raise e
-
- return response.status == 200
-
- def create_record(self, name, zone, type, data, extra=None):
- """
- Create a 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 zone: Zone which the records will be created for.
- :type zone: :class:`Zone`
-
- :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 ('prio', 'ttl').
- :type extra: ``dict``
-
- :rtype: :class:`Record`
- """
- action = '/v1/zones/%s/records' % zone.id
- to_post = {'name': name, 'content': data, 'type': type,
- 'zone_id': int(zone.id)}
- # ttl is required to create a record for luadns
- # pass it through extra like this: extra={'ttl':ttl}
- if extra is not None:
- to_post.update(extra)
- data = json.dumps(to_post)
- try:
- response = self.connection.request(action=action,
- method='POST',
- data=data)
- except LuadnsException:
- e = sys.exc_info()[1]
- raise e
-
- record = self._to_record(response.parse_body(), zone=zone)
-
- return record
-
- def _to_zone(self, item):
- common_attr = ['id', 'name']
- extra = {}
- for key in item:
- if key not in common_attr:
- extra[key] = item.get(key)
- zone = Zone(domain=item['name'], id=item['id'], type=None,
- ttl=None, driver=self, extra=extra)
-
- 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', 'content', 'name', 'type']
- extra = {}
- for key in item:
- if key not in common_attr:
- extra[key] = item.get(key)
- record = Record(id=item['id'], name=item['name'], type=item['type'],
- data=item['content'], 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/8afcda91/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/nfsn.py
----------------------------------------------------------------------
diff --git a/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/nfsn.py b/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/nfsn.py
deleted file mode 100644
index 0231ec4..0000000
--- a/apache-libcloud-1.0.0rc2/libcloud/dns/drivers/nfsn.py
+++ /dev/null
@@ -1,198 +0,0 @@
-# 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.
-"""
-NFSN DNS Driver
-"""
-import re
-import sys
-
-from libcloud.common.exceptions import BaseHTTPError
-from libcloud.common.nfsn import NFSNConnection
-from libcloud.dns.base import DNSDriver, Zone, Record
-from libcloud.dns.types import ZoneDoesNotExistError, RecordDoesNotExistError
-from libcloud.dns.types import RecordAlreadyExistsError
-from libcloud.dns.types import Provider, RecordType
-from libcloud.utils.py3 import httplib
-
-__all__ = [
- 'NFSNDNSDriver',
-]
-
-# The NFSN API does not return any internal "ID" strings for any DNS records.
-# This means that we must set all returned Record objects' id properties to
-# None. It also means that we cannot implement libcloud APIs that rely on
-# record_id, such as get_record(). Instead, the NFSN-specific
-# ex_get_records_by() method will return the desired Record objects.
-#
-# Additionally, the NFSN API does not provide ways to create, delete, or list
-# all zones, so create_zone(), delete_zone(), and list_zones() are not
-# implemented.
-
-
-class NFSNDNSDriver(DNSDriver):
- type = Provider.NFSN
- name = 'NFSN DNS'
- website = 'https://www.nearlyfreespeech.net'
- connectionCls = NFSNConnection
-
- RECORD_TYPE_MAP = {
- RecordType.A: 'A',
- RecordType.AAAA: 'AAAA',
- RecordType.CNAME: 'CNAME',
- RecordType.MX: 'MX',
- RecordType.NS: 'NS',
- RecordType.SRV: 'SRV',
- RecordType.TXT: 'TXT',
- RecordType.PTR: 'PTR',
- }
-
- def list_records(self, zone):
- """
- Return a list of all records for the provided zone.
-
- :param zone: Zone to list records for.
- :type zone: :class:`Zone`
-
- :return: ``list`` of :class:`Record`
- """
- # Just use ex_get_records_by() with no name or type filters.
- return self.ex_get_records_by(zone)
-
- def get_zone(self, zone_id):
- """
- Return a Zone instance.
-
- :param zone_id: name of the required zone, for example "example.com".
- :type zone_id: ``str``
-
- :rtype: :class:`Zone`
- :raises: ZoneDoesNotExistError: If no zone could be found.
- """
- # We will check if there is a serial property for this zone. If so,
- # then the zone exists.
- try:
- self.connection.request(action='/dns/%s/serial' % zone_id)
- except BaseHTTPError:
- e = sys.exc_info()[1]
- if e.code == httplib.NOT_FOUND:
- raise ZoneDoesNotExistError(zone_id=None, driver=self,
- value=e.message)
- raise e
- return Zone(id=None, domain=zone_id, type='master', ttl=3600,
- driver=self)
-
- def ex_get_records_by(self, zone, name=None, type=None):
- """
- Return a list of records for the provided zone, filtered by name and/or
- type.
-
- :param zone: Zone to list records for.
- :type zone: :class:`Zone`
-
- :param zone: Zone where the requested records are found.
- :type zone: :class:`Zone`
-
- :param name: name of the records, for example "www". (optional)
- :type name: ``str``
-
- :param type: DNS record type (A, MX, TXT). (optional)
- :type type: :class:`RecordType`
-
- :return: ``list`` of :class:`Record`
- """
- payload = {}
- if name is not None:
- payload['name'] = name
- if type is not None:
- payload['type'] = type
-
- action = '/dns/%s/listRRs' % zone.domain
- response = self.connection.request(action=action, data=payload,
- method='POST')
- return self._to_records(response, zone)
-
- def create_record(self, name, zone, type, data, extra=None):
- """
- Create a new 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 zone: Zone where the requested record is created.
- :type zone: :class:`Zone`
-
- :param type: DNS record type (A, MX, TXT).
- :type type: :class:`RecordType`
-
- :param data: Data for the record (depends on the record type).
- :type data: ``str``
-
- :param extra: Extra attributes (driver specific, e.g. 'ttl').
- (optional)
- :type extra: ``dict``
-
- :rtype: :class:`Record`
- """
- action = '/dns/%s/addRR' % zone.domain
- payload = {'name': name, 'data': data, 'type': type}
- if extra is not None and extra.get('ttl', None) is not None:
- payload['ttl'] = extra['ttl']
- try:
- self.connection.request(action=action, data=payload, method='POST')
- except BaseHTTPError:
- e = sys.exc_info()[1]
- exists_re = re.compile(r'That RR already exists on the domain')
- if e.code == httplib.BAD_REQUEST and \
- re.search(exists_re, e.message) is not None:
- value = '"%s" already exists in %s' % (name, zone.domain)
- raise RecordAlreadyExistsError(value=value, driver=self,
- record_id=None)
- raise e
- return self.ex_get_records_by(zone=zone, name=name, type=type)[0]
-
- def delete_record(self, record):
- """
- Use this method to delete a record.
-
- :param record: record to delete
- :type record: `Record`
-
- :rtype: Bool
- """
- action = '/dns/%s/removeRR' % record.zone.domain
- payload = {'name': record.name, 'data': record.data,
- 'type': record.type}
- try:
- self.connection.request(action=action, data=payload, method='POST')
- except BaseHTTPError:
- e = sys.exc_info()[1]
- if e.code == httplib.NOT_FOUND:
- raise RecordDoesNotExistError(value=e.message, driver=self,
- record_id=None)
- raise e
- return True
-
- def _to_record(self, item, zone):
- ttl = int(item['ttl'])
- return Record(id=None, name=item['name'], data=item['data'],
- type=item['type'], zone=zone, driver=self, ttl=ttl)
-
- def _to_records(self, items, zone):
- records = []
- for item in items.object:
- records.append(self._to_record(item, zone))
- return records