Skip to content

Instantly share code, notes, and snippets.

@jcockhren
Last active February 3, 2016 19:54
Show Gist options
  • Save jcockhren/506c2e5a0079c813b724 to your computer and use it in GitHub Desktop.
Save jcockhren/506c2e5a0079c813b724 to your computer and use it in GitHub Desktop.
Example execution module for DNSimple
from __future__ import absolute_import
from salt import utils
import salt
import salt.utils
import salt.version
import salt.loader
import salt.ext.six as six
HAS_LIBCLOUD = False
UNDER_SALT = False
try:
from libcloud.dns.types import Provider
from libcloud.dns.providers import get_driver
cls = get_driver(Provider.DNSIMPLE)
client = None
HAS_LIBCLOUD = True
except ImportError:
pass
def __init__(opts):
global UNDER_SALT
UNDER_SALT = True
def _get_client():
'''
Initialize the DNSimple driver or return the already defined
object
'''
username = __salt__['pillar.get']('dnsimple.username')
api_token = __salt__['pillar.get']('dnsimple.key')
client = cls(username, api_token)
return client
def zone(name='example.com'):
return _get_client().get_zone(name)
def create_record(name, location, type='A', ttl=3600):
zone().create_record(name, type, location, extra={'ttl': ttl})
return True
def remove_record(name):
record = [x for x in zone().list_records() if x.name == name][0]
return _get_client().delete_record(record)
def test():
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment