Skip to content

Instantly share code, notes, and snippets.

@chechuironman
Last active August 29, 2015 14:00
Show Gist options
  • Save chechuironman/5c929f530317e48ec671 to your computer and use it in GitHub Desktop.
Save chechuironman/5c929f530317e48ec671 to your computer and use it in GitHub Desktop.
Add Server to a LB
#!/usr/bin/ruby
##################################################################################
# Add server to a LB
# ©Copyright IBM Corporation 2014.
# LICENSE: MIT (http://opensource.org/licenses/MIT)
# gems used:
# rubygems, softlayer-api
##################################################################################
require 'rubygems'
require 'softlayer_api'
$SL_API_USERNAME = "xxxx" # enter your username here
$SL_API_KEY = "xxx" # enter your apiKey here
ip='xxxx' #IP of the server
server_id='xxx' #Server that will be added id
lb_id='xxx' #LB id
object_mask='mask[ipAddress,virtualServers[serviceGroups[services[ipAddress]]]]'
softlayer_LBVI = SoftLayer::Service.new( "SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_VirtualIpAddress")
load_balancer = softlayer_LBVI.object_mask(object_mask).object_with_id(server_id).getObject
softlayer_NSI = SoftLayer::Service.new( "SoftLayer_Network_Subnet_IpAddress")
ip_address1=softlayer_NSI.getByIpAddress(ip)
newServer=[]
serviceGroup=load_balancer['virtualServers'][0]['serviceGroups'][0]
serviceGroup['services']=[{"enabled" => 1,
"port" => 80,
"notes" => 'test',
"ipAddressId" => ip_address1['id'],
"groupReferences" =>[{"weight" => 50}],
"healthChecks" => [{"healthCheckTypeId" => 21}]
}]
newServer={"id"=>load_balancer['id'],
"virtualServers"=>[{"id"=>load_balancer['virtualServers'][0]['id'],
"port"=>load_balancer['virtualServers'][0]['port'],
"allocation"=>load_balancer['virtualServers'][0]['allocation'],
"serviceGroups"=>[serviceGroup]
}]}
softlayer_LBVI.object_with_id(lb_id).editObject(newServer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment