Created
June 26, 2012 20:36
-
-
Save softlayer/2998759 to your computer and use it in GitHub Desktop.
Update DNS Zone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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