RemoveService.php
RemoveService.php
<?php
require_once __DIR__.'/vendor/autoload.php';
$username = "set me";
$apiKey = "set me";
$vipAddress = "173.193.117.96";
$virtualPort = 80;
$destPorts = array(815, 816, 817, 812, 80000, 8000);
$accountService = \SoftLayer\SoapClient::getClient('SoftLayer_Account', null, $username, $apiKey);
$serviceService = \SoftLayer\SoapClient::getClient('SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_Service', null, $username, $apiKey);
$filter = new stdClass();
$filter -> adcLoadBalancers = new stdClass();
$filter -> adcLoadBalancers -> ipAddress = new stdClass();
$filter -> adcLoadBalancers -> ipAddress -> ipAddress = new stdClass();
$filter -> adcLoadBalancers -> ipAddress -> ipAddress -> operation = $vipAddress;
$accountService -> setObjectFilter($filter);
$objectMask = "mask[virtualServers[serviceGroups[services[healthChecks[type], groups, groupReferences, ipAddress]]]]";
$accountService -> setObjectMask($objectMask);
try {
$loadBalancers = $accountService -> getAdcLoadBalancers();
foreach($loadBalancers[0] -> virtualServers as $virtualServer)
{
if($virtualServer -> port == $virtualPort)
{
foreach($virtualServer -> serviceGroups as $serviceGroup)
{
foreach($destPorts as $destPort)
{
$removeFlag = true;
foreach($serviceGroup -> services as $service)
{
if($service -> port == $destPort)
{
$serviceService -> setInitParameter($service -> id);
$result = $serviceService -> deleteObject();
echo "Has been the '" . $destPort . "' (Dest. Port) service deleted?: " . $result . "\n";
$removeFlag = false;
}
}
if($removeFlag)
{
echo "The ". $destPort . " Dest. Port doesn't exists.\n";
}
}
}
}
}
} catch(Exception $e) {
echo "Unable to remove the service: " . $e -> getMessage();
}