Skip to content

Instantly share code, notes, and snippets.

@softlayer
Created June 26, 2012 20:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save softlayer/2998759 to your computer and use it in GitHub Desktop.
Save softlayer/2998759 to your computer and use it in GitHub Desktop.
Update DNS Zone
<?php
require_once('SoftLayer/SoapClient.class.php');
function updateDns() {
$apiUsername = 'USER HERE';
$apiKey = 'KEY HERE';
$domainId = 'DOMAIN ID HERE';
$dnsClient = SoftLayer_SoapClient::getClient('SoftLayer_Dns_Domain', $domainId, $apiUsername, $apiKey);
$recordClient = SoftLayer_SoapClient::getClient('SoftLayer_Dns_Domain_ResourceRecord', null , $apiUsername, $apiKey);
// Get the zone's records
$existingRecords = $dnsClient->getResourceRecords();
// Loop through each record, store everything but ns and soa
foreach ($existingRecords as $record) {
// skip ns and soa records
if ($record->type == 'ns' || $record->type == 'soa') {
continue;
}
$recordsForDeletion[] = $record;
}
// Delete all records except for soa and ns
$recordClient->deleteObjects($recordsForDeletion);
// Parse zone file into an array of std objects
$newRecords = array();
$specificRecord = array (
'id' => NULL,
'data' => '127.0.2.1',
'domainId' => $domainId,
'host' => 'test5',
'ttl' => 900,
'type' => 'a'
);
$newRecords[] = (object)$specificRecord;
$recordClient->createObjects($newRecords);
}
try {
updateDns();
} catch ( Exception $e) {
die($e->getMessage() . "\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment