AddServiceGroup.php
AddServiceGroup.php
<?php
require_once __DIR__.'/vendor/autoload.php';
$username = "set me";
$apiKey = "set me";
$vipAddress = "159.253.157.82";
$allocations = array(10, 10, 10, 70);
$group = "HTTPS";
$method = "Insert Cookie";
$port = 5459;
$notes = "this is for test Rcv";
$timeout = 0;
$accountService = \SoftLayer\SoapClient::getClient('SoftLayer_Account', null, $username, $apiKey);
$balancerService = \SoftLayer\SoapClient::getClient('SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_VirtualIpAddress', null, $username, $apiKey);
$groupService = \SoftLayer\SoapClient::getClient('SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_Routing_Type', null, $username, $apiKey);
$methodService = \SoftLayer\SoapClient::getClient('SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_Routing_Method', 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);
$groupFilter = new stdClass();
$groupFilter -> name = new stdClass();
$groupFilter -> name -> operation = $group;
$groupService -> setObjectFilter($groupFilter);
$methodFilter = new stdClass();
$methodFilter -> name = new stdClass();
$methodFilter -> name -> operation = $method;
$methodService -> setObjectFilter($methodFilter);
$objectMask = "mask[virtualServerCount, virtualServers[serviceGroups]]";
$accountService -> setObjectMask($objectMask);
try {
$methods = $methodService -> getAllObjects();
$groups = $groupService -> getAllObjects();
$groupObject = new stdClass();
$groupObject -> routingMethodId = $methods[0] -> id;
$groupObject -> routingTypeId = $groups[0] -> id;
$groupObject -> notes = $notes;
$groupObject -> timeout = $timeout;
$groupList = array();
$groupList[] = $groupObject;
$methodObject = new stdClass();
$methodObject -> port = $port;
$methodObject -> serviceGroups = $groupList;
$loadBalancers = $accountService -> getAdcLoadBalancers();
array_push($loadBalancers[0] -> virtualServers, $methodObject);
$balancerService -> setInitParameter($loadBalancers[0] -> id);
if (sizeof($allocations) == (($loadBalancers[0] -> virtualServerCount) + 1)) {
if ($loadBalancers[0] -> virtualServerCount == 0) {
$loadBalancers[0] -> virtualServers[0] -> allocation = $allocations[0];
} else {
for ($i = 0; $i <= $loadBalancers[0] -> virtualServerCount; $i++) {
$loadBalancers[0] -> virtualServers[$i] -> allocation = $allocations[$i];
}
}
} else {
echo "Error: The number of allocations is not the required";
return;
}
$result = $balancerService -> editObject($loadBalancers[0]);
echo "Has been added the service group to the Load Balancer?: " . $result;
} catch(Exception $e) {
echo "Unable to add service group: " . $e -> getMessage();
}