CloudFlare DNS Driver Documentation

CloudFlare, Inc. is a U.S. company that provides a content delivery network and distributed domain name server services.

../../_images/cloudflare.png

Instantiating the driver

To instantiate the driver you need to pass email address associated with your account and a Global API key available on the account page to the driver constructor as shown below.

from libcloud.dns.types import Provider
from libcloud.dns.providers import get_driver

cls = get_driver(Provider.CLOUDFLARE)
driver = cls("<email address>", "<api key>")

Alternatively, authentication can also be done via an API Token as shown below. It is recommended that the token at least has the Zone.DNS permissions.

from libcloud.dns.types import Provider
from libcloud.dns.providers import get_driver

cls = get_driver(Provider.CLOUDFLARE)
driver = cls("<api token>")

API Docs

class libcloud.dns.drivers.cloudflare.CloudFlareDNSDriver(key, secret=None, secure=True, host=None, port=None, **kwargs)[source]
Parameters
  • key (str) – API key or username to used (required)

  • secret (str) – Secret password to be used (required)

  • secure (bool) – Whether to use HTTPS or HTTP. Note: Some providers only support HTTPS, and it is on by default.

  • host (str) – Override hostname used for connections.

  • port (int) – Override port used for connections.

Returns

None

connectionCls

alias of libcloud.dns.drivers.cloudflare.GlobalAPIKeyDNSConnection

create_record(name, zone, type, data, extra=None)[source]

@inherits: DNSDriver.create_record

Note that for extra record properties, only the ones specified in RECORD_CREATE_ATTRIBUTES can be set at creation time. Any non-settable properties are ignored.

NOTE: For CAA RecordType, data needs to be in the following format: <flags> <tag> <ca domain name> where the tag can be issue, issuewild or iodef.

For example: 0 issue test.caa.com

NOTE: For SSHFP RecordType, data need to be in the format: <algorithm> <type> <fingerprint>

create_zone(domain, type='master', ttl=None, extra=None)[source]

@inherits: DNSDriver.create_zone

Note that for users who have more than one account membership, the id of the account in which to create the zone must be specified via the extra key account.

Note that for extra zone properties, only the ones specified in ZONE_CREATE_ATTRIBUTES can be set at creation time. Additionally, setting the ``ttl` property is not supported.

delete_record(record)[source]

Delete a record.

Parameters

record (Record) – Record to delete.

Return type

bool

delete_zone(zone)[source]

Delete a zone.

Note: This will delete all the records belonging to this zone.

Parameters

zone (Zone) – Zone to delete.

Return type

bool

export_zone_to_bind_format(zone)

Export Zone object to the BIND compatible format.

Parameters

zone (Zone) – Zone to export.

Returns

Zone data in BIND compatible format.

Return type

str

export_zone_to_bind_zone_file(zone, file_path)

Export Zone object to the BIND compatible format and write result to a file.

Parameters
  • zone (Zone) – Zone to export.

  • file_path (str) – File path where the output will be saved.

get_record(zone_id, record_id)[source]

Return a Record instance.

Parameters
  • zone_id (str) – ID of the required zone

  • record_id (str) – ID of the required record

Return type

Record

get_zone(zone_id)[source]

Return a Zone instance.

Parameters

zone_id (str) – ID of the required zone

Return type

Zone

iterate_records(zone)[source]

Return a generator to iterate over records for the provided zone.

Parameters

zone (Zone) – Zone to list records for.

Return type

generator of Record

iterate_zones()[source]

Return a generator to iterate over available zones.

Return type

generator of Zone

list_record_types()

Return a list of RecordType objects supported by the provider.

Returns

list of RecordType

list_records(zone)

Return a list of records for the provided zone.

Parameters

zone (Zone) – Zone to list records for.

Returns

list of Record

list_zones()

Return a list of zones.

Returns

list of Zone

update_record(record, name=None, type=None, data=None, extra=None)[source]

@inherits: DNSDriver.update_record

Note that for extra record properties, only the ones specified in RECORD_UPDATE_ATTRIBUTES can be updated. Any non-updatable properties are ignored.

update_zone(zone, domain, type='master', ttl=None, extra=None)[source]

@inherits: DNSDriver.update_zone

Note that the zone, type and ttl properties can’t be updated. The only updatable properties are the extra zone properties specified in ZONE_UPDATE_ATTRIBUTES. Only one property may be updated at a time. Any non-updatable properties are ignored.