Use Case
I want to create a copy of a SiteBacker pool and its probes.
Postman Example
Note: You'll need a token to supply in headers tab in Postman. UltraDNS REST API Examples: Login
You'll ultimately want to post pool data and probe data using two different api endpoints.
POST /zones/{zoneName}/rrsets/A/{ownerName}
POST /zones/{zoneName}/rrsets/A/{ownerName}/probes
But first you need the know the data that goes into the body.
That can be found via a GET of the existing pool you wish to copy.
Instead of {zoneName} and {ownerName} I'll use some specific examples from here on out.
You would need to update to values for your zones and hostnames in your account.
GET /zones/ultra-api-examples.com/rrsets/A/apac
Authorization: Bearer {Token from Authorization Endpoint}
Content-Type: application/jsonHere's an example of what you'd see returned:
{
"zoneName": "ultra-api-examples.com",
"rrSets": [
{
"ownerName": "apac.ultra-api-examples.com.",
"rrtype": "A (1)",
"ttl": 120,
"rdata": [
"10.5.5.5",
"10.5.5.6"
],
"profile": {
"@context": "http://schemas.ultradns.com/SBPool.jsonschema",
"description": "apac.ultra-api-examples.com.",
"runProbes": true,
"actOnProbes": true,
"order": "ROUND_ROBIN",
"maxActive": 1,
"maxServed": 0,
"status": "OK",
"rdataInfo": [
{
"state": "NORMAL",
"runProbes": false,
"priority": 1,
"failoverDelay": 0,
"restorationDelay": 0,
"threshold": 1,
"availableToServe": true,
"type": "A"
},
{
"state": "NORMAL",
"runProbes": false,
"priority": 2,
"failoverDelay": 0,
"restorationDelay": 0,
"threshold": 1,
"availableToServe": false,
"type": "A"
}
],
"backupRecords": [
{
"rdata": "10.5.5.5",
"failoverDelay": 0,
"restorationDelay": 0,
"type": "A",
"availableToServe": false
}
]
}
}
],
"queryInfo": {
"sort": "OWNER",
"reverse": false,
"limit": 100
},
"resultInfo": {
"totalCount": 1,
"offset": 0,
"returnedCount": 1
}
}So to copy those pool settings you'd need you need the info from rrsets, excluding ownerName and rrType, as those are set in URL.
This could then be sent in a post, where you update the ownerName in the url to the desired value.
POST /zones/ultra-api-examples.com/rrsets/A/apac2 HTTP/1.1
Host: api.ultradns.com
Authorization: Bearer {Token from Authorization Endpoint}
Content-Type: application/json{
"ttl": 120,
"rdata": [
"10.5.5.5",
"10.5.5.6"
],
"profile": {
"@context": "http://schemas.ultradns.com/SBPool.jsonschema",
"description": "apac.ultra-api-examples.com.",
"runProbes": true,
"actOnProbes": true,
"order": "ROUND_ROBIN",
"maxActive": 1,
"maxServed": 0,
"status": "OK",
"rdataInfo": [
{
"state": "NORMAL",
"runProbes": false,
"priority": 1,
"failoverDelay": 0,
"restorationDelay": 0,
"threshold": 1,
"availableToServe": true,
"type": "A"
},
{
"state": "NORMAL",
"runProbes": false,
"priority": 2,
"failoverDelay": 0,
"restorationDelay": 0,
"threshold": 1,
"availableToServe": false,
"type": "A"
}
],
"backupRecords": [
{
"rdata": "10.5.5.5",
"failoverDelay": 0,
"restorationDelay": 0,
"type": "A",
"availableToServe": false
}
]
}
}That should give a 201 Created.
Then you can follow a similar for probes.
GET /zones/ultra-api-examples.com/rrsets/A/apac/probes HTTP/1.1
Host: api.ultradns.com
Authorization: Bearer {Token from Authorization Endpoint}
Content-Type: application/json
That will return something like this:
{
"probes": [
{
"id": "6034EF9152D4AA93",
"type": "HTTP",
"interval": "HALF_MINUTE",
"agents": [
"EUROPE_WEST",
"ASIA",
"USEast",
"USWest"
],
"threshold": 2,
"details": {
"transactions": [
{
"method": "GET",
"url": "https://ultra-api-examples.com/",
"transmittedData": "",
"limits": {
"connect": {
"fail": 20
},
"run": {
"fail": 60
}
},
"followRedirects": true,
"expectedResponse": "2XX|3XX",
"protocolVersion": "HTTP/1.0"
}
]
}
}
],
"queryInfo": {
"reverse": false,
"limit": 100
},
"resultInfo": {
"totalCount": 1,
"offset": 0,
"returnedCount": 1
}
}From there you can post this:
POST /zones/ultra-api-examples.com/rrsets/A/apac2/probes
Host: api.ultradns.com
Authorization: Bearer {Token}
Content-Type: application/json {
"id": "6034EF9152D4AA93",
"type": "HTTP",
"interval": "HALF_MINUTE",
"agents": [
"EUROPE_WEST",
"ASIA",
"USEast",
"USWest"
],
"threshold": 2,
"details": {
"transactions": [
{
"method": "GET",
"url": "https://ultra-api-examples.com/",
"transmittedData": "",
"limits": {
"connect": {
"fail": 20
},
"run": {
"fail": 60
}
},
"followRedirects": true,
"expectedResponse": "2XX|3XX",
"protocolVersion": "HTTP/1.0"
}
]
}
}
]}Python Examples - UltraDNS Client
Requirement: https://github.com/ultradns/python_rest_api_client
Script example
import ultra_rest_client
import sys
import json
c = ultra_rest_client.RestApiClient('username', 'password', False, 'api.ultradns.com')
with open('filename.txt') as f:
for line in f:
line = line.rstrip()
line = line.split()
pfd_json = c.rest_api_connection.get("/zones/" + line[0] + "/rrsets/A/" + line[1])
pfd_json2 = pfd_json['rrSets']
pfd_json3 = json.dumps(pfd_json2)[1:-1]
pfduri = "/zones/" + line[0] + "/rrsets/A/" + line[2]
print(str(c.rest_api_connection.post(pfduri, pfd_json3)) + " config copy for " + line[2])
pr_json = c.rest_api_connection.get("/zones/" + line[0] + "/rrsets/A/" + line[1] + "/probes/")
pr_json2 = pr_json['probes']
pr_json3 = json.dumps(pr_json2)[1:-1]
pruri = "/zones/" + line[0] + "/rrsets/A/" + line[2] + "/probes"
print(str(c.rest_api_connection.post(pruri, pr_json3)) + " probe copy for " + line[2])line[0] = zoneName
line[1] = SiteBacker pool you wish to copy.
line[2] = SiteBacker pool you wish to create.
File example
ultra-api-examples.com. existingpool.ultra-api-examples.com. newpool1.ultra-api-examples.com.
ultra-api-examples.com. existingpool.ultra-api-examples.com. newpool2.ultra-api-examples.com.
ultra-api-examples.com. existingpool.ultra-api-examples.com. newpool3.ultra-api-examples.com.So you'll have two files.
One script (sitebacker_copy.py in this example but it can be anything as long as it is a py file) and one input file (filename.txt in the script but it can be anything).
After you edit the script example to have the desired username, password, filename and save it, you can run it from command prompt like this and see this output:
% python3 sitebacker_copy.py
{'message': 'Successful'} config copy for newpool1.ultra-api-examples.com.
{'message': 'Successful'} probe copy for newpool1.ultra-api-examples.com.
{'message': 'Successful'} config copy for newpool2.ultra-api-examples.com.
{'message': 'Successful'} probe copy for newpool2.ultra-api-examples.com.
{'message': 'Successful'} config copy for newpool3.ultra-api-examples.com.
{'message': 'Successful'} probe copy for newpool3.ultra-api-examples.com.