Skip to content

Commit

Permalink
Added proxed flag to show how to adjust DNS entries after creation
Browse files Browse the repository at this point in the history
  • Loading branch information
mahtin committed May 4, 2016
1 parent bc25c34 commit 94d5c2d
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions examples/example-create-zone-and-populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def main():

# DNS records to create
dns_records = [
{'name':'ding', 'type':'A', 'content':'216.58.194.206'},
{'name':'foo', 'type':'AAAA', 'content':'2001:d8b::1'},
{'name':'foo', 'type':'A', 'content':'192.168.0.1'},
{'name':'duh', 'type':'A', 'content':'10.0.0.1', 'ttl':120},
Expand All @@ -49,7 +50,24 @@ def main():
exit('/zones.dns_records.post %s %s - %d %s' % (zone_name, record['name'], e, e))
# Print respose info - they should be the same
dns_record = r
print '\t%s %30s %6d %-5s %s' % (dns_record['id'], dns_record['name'], dns_record['ttl'], dns_record['type'], dns_record['content'])
print '\t%s %30s %6d %-5s %s ; proxied=%s proxiable=%s' % (dns_record['id'], dns_record['name'], dns_record['ttl'], dns_record['type'], dns_record['content'], dns_record['proxied'], dns_record['proxiable'])

# set proxied flag to false - for example
dns_record_id = dns_record['id']

new_dns_record = {
# Must have type/name/content (even if they don't change)
'type':dns_record['type'],
'name':dns_record['name'],
'content':dns_record['content'],
# now add new values you want to change
'proxied':False
}

try:
dns_record = cf.zones.dns_records.put(zone_id, dns_record_id, data=new_dns_record)
except CloudFlare.CloudFlareAPIError as e:
exit('/zones/dns_records.put %d %s - api call failed' % (e, e))

print ''

Expand All @@ -61,7 +79,7 @@ def main():
exit('/zones.dns_records.get %s - %d %s' % (zone_name, e, e))

for dns_record in sorted(dns_records, key=lambda v: v['name']):
print '\t%s %30s %6d %-5s %s' % (dns_record['id'], dns_record['name'], dns_record['ttl'], dns_record['type'], dns_record['content'])
print '\t%s %30s %6d %-5s %s ; proxied=%s proxiable=%s' % (dns_record['id'], dns_record['name'], dns_record['ttl'], dns_record['type'], dns_record['content'], dns_record['proxied'], dns_record['proxiable'])

print ''

Expand Down

0 comments on commit 94d5c2d

Please sign in to comment.