Skip to content

SomethingSubtle/cloudconnect

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CloudConnect

Build Status

CloudConnect is a simple pure python interface for v4 of the CloudFlare API.

At the moment it mostly provides a thin wrapper around CloudFlare API connections. Each wrapped call returns the JSON data as a python dict.

Over time it will also include commands that complement and extend the current CF API's capabilities.
A current example is listing DNS records based on domain name, rather than just by ID.

Python Versions Supported

  • Python 2.7
  • Python 3.3+

Under Development

This project is currently under development. Pull requests and suggested code improvements are welcome.

Install

$ git clone https://github.com/0snug0/cloudconnect.git
$ python setup.py install

Or via pip with:

$ pip install git+git://github.com/0snug0/cloudconnect.git

Usage

Calls to the CloudFlare API with CloudConnect will return a dict of the JSON data returned (unless otherwise noted).

Initializing CloudConnect

>>> from cloudconnect import CloudConnect
>>> cf = CloudConnect('email@example.com', 'd2gYOURoAPIoKEYo24fmdsf')

Create a new zone (add a domain) with create_zone and skip the automagic record grabbing by CloudFlare.

>>> from cloudconnect import CloudConnect
>>> cf = CloudConnect('email@example.com', 'd2gYOURoAPIoKEYo24fmdsf')
>>> cf.create_zone('mydomain.com', jump_start=False)
{u'errors': [],
 u'messages': [],
 u'result': {u'status': u'pending',
             u'original_name_servers': [u'ns1.com', u'ns2.com'],
             u'original_dnshost': None,
             u'name': u'anotherdomain.com',
             u'owner': {u'type': u'user', 
                        u'id': u'd2gYOURoAPIoKEYo24fmdsf', 
                        u'email': u'tim@dualmediasolutions.com'},
             u'original_registrar': None,
             u'paused': False, 
             u'modified_on': u'2015-06-17T21:37:45.967464Z',
             u'created_on': u'2015-06-17T21:37:45.930702Z',
  ...

A Note About **kwargs

You can use **kwargs to pass arguments/parameters that are not required by Cloudflare. For example, notice how jump_start=False is passed above.

Current Queries

Initialize CloudConnect

cf = Cloudconnect('email@example.com', 'd2gYOURoAPIoKEYo24fmdsf')

Create a Zone (Add a domain)

cf.create_zone(domain, **kwargs)

Get zone_id

cf.get_zone_id(domain)

Create a DNS Record

cf.create_dns_record(zone_id, r_type, name, content, **kwargs)

Update DNS Records

cf.update_dns_record(zone_id, rec_id, **kwargs)

List DNS Records

cf.list_dns_records(zone_id, **kwargs)

Delete DNS Record

cf.delete_dns_record(zone_id, rec_id)

Commands that improve, augment, or compliment CF API commands

List DNS Records for Domain (rather than by Zone ID)

cf.domain_list_dns_records(domain, **kwargs)

Subclassing CloudConnect

you can subclass CloudConnect to create another layer of project specific abstraction for API calls.

For example, let's say that you had two records to apply to your domains, both proxied by CloudFlare.

>>> from cloudconnect import CloudConnect
>>> class MyCloudConnect(CloudConnect):
>>>     def set_the_records(self, domain):
>>>         zone_id = self.get_zone_id(domain)
>>>         rec1 = self.create_dns_record(zone_id, 'A', '@', '127.0.0.1', proxied=True)
>>>         rec2 = self.create_dns_record(zone_id, 'CNAME', 'www', 'mydomain.com', proxied=True)
>>>         return rec1, rec2

About

Cloudflare API v4 Python Wrapper

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%