When I created the generic script, I had needed a way to view the CNAMEs and update them, so I had only needed the following methods: UDNS_UpdateCNAMERecords, UDNS_GetCNAMERecordsOfZone. Of course, since the associated Create and related ANAME methods were identical in nature, they were simple to test and, thus, my parse_xml techniques were based solely on these.
Yesterday, I had the need to create about a score of new zones as well as grant permissions to a few unprivileged users. As such, I had the chance to revisit the WebUI and, while adding a zone is not too taxing, granting permissions was like extracting wisdom teeth. First off, the tiny 15x15 (is it even that?) lock icon was not intuitive for me and it probably took half an hour to even figure out HOW to add permissions (I did not actually keep track of time so I may be exaggerating the length or brevity of time elapsed) and even when I did, I was rewarded with a complex collapsible folder browser method that reset itself after I went through all the check boxes on each individual user. After adding just one, I realized that I had to use the API and not subject myself to any more torture (not that the API is significantly less painful, mind you, but at least it provided a relief from the mundane repetition).
The UltraDNS_API.py contains a few examples at the bottom of how you would automate using python, but I decided to whip up a quick bash script for kicks. While doing so, I discovered that the output was not consumable by my existing parse_xml techniques, so I cloned the iterator to aide in the "unmatched" case, such as this one and will revisit it later on, if need be. I also removed my login credentials from the autogenerated UltraDNS_API.cf file and provided a way to pass them in via command line switch. The resulting UltraDNS_API.py can be found in the same GitHub location.
The BASH script itself, utilizes its own basename to create a users and zone lists, which it edits prior to asking for you username and password and then passes the parameters to the python script:
#!/bin/bash
# Using the UltraDNS_API.py to create multiple zones and their prmissions
SCR=${0##*/}
DIR=${0%/*}
[[ $DIR == '.' ]] && DIR=$PWD
cd $DIR
ZONE=${SCR%.sh}.zones
USER=${SCR%.sh}.users
TOOL=UltraDNS_API.py
CONF=${TOOL%.py}.cf
# Edit zones and users first
vi $ZONE $USER
# Ask for username and password
echo -n "Username: "; read username
echo -n "Password: "; read password
for zone in $(cat $ZONE); do
python $TOOL -M UDNS_CreatePrimaryZone -c 'n' \
-a "{'username': '$username', 'password': '$password'}" \
-d -p "{'zonename': '$zone', 'forceimport': 'False'}"
for user in $(cat $USER); do
python $TOOL -M UDNS_GrantPermissionsToZoneForUser -c 'n' \
-a "{'username': '$username', 'password': '$password'}" \
-d -p "{'user': '$user', 'zone': '$zone',
'allowcreate': 'True', 'allowread': 'True',
'allowupdate': 'True', 'allowdelete': 'True',
'denycreate': 'False', 'denyread': 'False',
'denyupdate': 'False', 'denydelete': 'False'}"
done
done
Worked like a charm! Of course, if you run the python script without parameters for the two methods utilized in the BASH script, you will be prompted with the last answers used.