Skip to content

Instantly share code, notes, and snippets.

@shawnsi
Last active December 7, 2015 17:24
Show Gist options
  • Save shawnsi/3ebd470d8b4e928100f5 to your computer and use it in GitHub Desktop.
Save shawnsi/3ebd470d8b4e928100f5 to your computer and use it in GitHub Desktop.
Netscaler to Route 53 Conversion
#!/usr/bin/env python
#
# Edit ns.conf appropriately and pass to this script:
# python ns2r53.py <hosted-zone-id> <ns.conf>
from datetime import datetime
import sys
import boto3
import botocore
NS_ACTIONS = {
'addRec': 'A',
'cnameRec': 'CNAME',
}
def get_changes(ns_conf):
changes = []
with open(ns_conf) as f:
for line in f.readlines():
_, _, action, record, value = line.split()[:5]
changes.append({
'Action': 'UPSERT',
'ResourceRecordSet': {
'Name': record,
'Type': NS_ACTIONS[action],
'ResourceRecords': [
{'Value': value}
],
'TTL': 3600
}
})
return changes
if __name__ == '__main__':
client = boto3.client('route53')
changes = get_changes(sys.argv[2])
try:
response = client.change_resource_record_sets(
HostedZoneId=sys.argv[1],
ChangeBatch={
'Comment': 'Netscaler Configuration Upload %s' % datetime.now(),
'Changes': changes
}
)
print(response)
except botocore.exceptions.ClientError as e:
print(e.response)
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment