Skip to content

Commit

Permalink
Merge pull request #15 from ultradns/pr_merge
Browse files Browse the repository at this point in the history
test code analysis job on local pr
  • Loading branch information
stevedejong authored Feb 10, 2023
2 parents 5081964 + 3ac8c05 commit 64c4d87
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
3 changes: 3 additions & 0 deletions sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,8 @@
#delete task status
print 'delete task status: %s ' % c.clear_task(result['task_id'])

#export zonefile in bind format
print('export zone: %s ' % c.export_zone('sample.client.me.'))

#delete the zone
print 'delete zone: %s ' % c.delete_zone('sample.client.me.')
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='ultra_rest_client',
version='0.2.1',
version='0.2.2',
description='A sample Python client for communicating with the UltraDNS REST API',
url='https://github.com/ultradns/python_rest_api_client',
author='Jon Bodner',
Expand Down
3 changes: 3 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,8 @@
#delete task status
print('delete task status: %s ' % c.clear_task(result['task_id']))

#export zonefile in bind format
print('export zone: %s ' % c.export_zone('sample.client.me.'))

#delete the zone
print('delete zone: %s ' % c.delete_zone('sample.client.me.'))
3 changes: 3 additions & 0 deletions ultra_rest_client/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def _do_call(self, uri, method, params=None, body=None, retry=True, files=None,
# body = {"errorCode":60001,"errorMessage":"invalid_grant:token not found, expired or invalid"}
if r1.status_code == requests.codes.NO_CONTENT:
return {}
# if the content-type is text/plain just return the text
if r1.headers['Content-Type'] == 'text/plain':
return r1.text
json_body = r1.json()
# if this is a background task, add the task id to the body
if r1.status_code == requests.codes.ACCEPTED:
Expand Down
22 changes: 21 additions & 1 deletion ultra_rest_client/ultra_rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
__author__ = 'Jon Bodner'
from .connection import RestApiConnection
import json

import time

class RestApiClient:
def __init__(self, username, password, use_http=False, host="restapi.ultradns.com"):
Expand Down Expand Up @@ -735,6 +735,26 @@ def edit_tc_pool(self, zone_name, owner_name, ttl, pool_info, rdata_info, backup
rrset = self._build_tc_rrset(backup_record, pool_info, rdata_info, ttl)
return self.rest_api_connection.put("/v1/zones/" + zone_name + "/rrsets/A/" + owner_name, json.dumps(rrset))

# export zone in bind format
def export_zone(self, zone_name):
"""Returns a zone file in bind format
Arguments:
zone_name -- The name of the zone being returned. A single zone as a string.
"""
zonelist = [zone_name]
zonejson=json.dumps({'zoneNames': zonelist})
status = self.rest_api_connection.post("/v3/zones/export", zonejson)
taskId = status.get('task_id')
while True:
task_status = self.rest_api_connection.get("/v1/tasks/"+taskId)
if task_status['code'] != 'IN_PROCESS':
break
time.sleep(1)
result=self.rest_api_connection.get("/v1/tasks/"+taskId+"/result")
self.clear_task(taskId)
return result

def build_params(q, args):
params = {}
Expand Down

0 comments on commit 64c4d87

Please sign in to comment.