Created
March 1, 2012 21:37
-
-
Save softlayer/1953408 to your computer and use it in GitHub Desktop.
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
# So we can talk to the SoftLayer API: | |
import SoftLayer.API | |
import argparse | |
# Your SoftLayer API username and key. | |
# | |
# Generate an API key at the SoftLayer Customer Portal: | |
# https://manage.softlayer.com/Administrative/apiKeychain | |
apiUsername = '' | |
apiKey = '' | |
accountClient = SoftLayer.API.Client('SoftLayer_Account', None, apiUsername, apiKey) | |
serviceClient = SoftLayer.API.Client('SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_Service', None, apiUsername, apiKey) | |
argsparse = argparse.ArgumentParser(description='Toggle the status of an ADC LB Service') | |
argsparse.add_argument('serviceNotes', metavar='Notes String', type=str, nargs='?', | |
help='String in the notes field of the service. Typically a hostname.') | |
args = argsparse.parse_args() | |
def findServiceIdByNotes(notes): | |
mask = { | |
'adcLoadBalancers': { | |
'virtualServers': { | |
'serviceGroups': { | |
'services': { | |
'ipAddress': { | |
'ipAddress': {} | |
} | |
} | |
} | |
} | |
} | |
} | |
accountClient.set_object_mask(mask) | |
virtualIps = accountClient.getAdcLoadBalancers() | |
for virtualIp in virtualIps: | |
for virtualServers in virtualIp['virtualServers']: | |
for serviceGroups in virtualServers['serviceGroups']: | |
for service in serviceGroups['services']: | |
if 'ipAddress' not in service: | |
continue | |
if service['notes'] == notes: | |
return service['id'] | |
def toggleServiceStatus(serviceId): | |
if serviceId == None: | |
exit("Error: Unable to find SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_Service") | |
serviceClient.set_init_parameter(serviceId) | |
return serviceClient.getObject() | |
print toggleServiceStatus(findServiceIdByNotes(args.serviceNotes)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment