Skip to content

Instantly share code, notes, and snippets.

@warmwaffles
Created February 16, 2012 18:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save warmwaffles/1846835 to your computer and use it in GitHub Desktop.
Save warmwaffles/1846835 to your computer and use it in GitHub Desktop.
Add / Remove Rackpsace Loadbalancer Error Page
#!/usr/bin/python
#
# Just change the three variables below and you are all set!
# @author Matthew A. Johnston (WarmWaffles)
# your user name
API_USERNAME = "username"
# your api key
API_KEY = "api-key"
# Load balancer Region
LB_REGION = "region"
import sys
import cloudlb
def print_balancers(balancers) :
for lb in lbs:
print "[%s] => %s" % (lb.id, lb.name)
clb = cloudlb.CloudLoadBalancer(API_USERNAME, API_KEY, LB_REGION);
lbs = clb.loadbalancers.list()
print "Choose an action..."
print "[1] - Set the error page"
print "[2] - Remove the error page"
print "[X] - Exit (really any value other than 1 or 2"
try:
mode = int(sys.stdin.readline())
except ValueError:
print "Good bye..."
sys.exit()
# ##################################################################################################
# ##################################################################################################
if mode == 1:
print "Set the error page..."
print_balancers(lbs)
print "Type one of the ID's above..."
id = 0
try:
try:
id = int(sys.stdin.readline())
except ValueError:
print "Invalid entry..."
sys.exit()
except IOError:
print "Good bye..."
sys.exit()
try:
balancer = clb.loadbalancers.get(id)
except cloudlb.errors.ResponseError:
print "Invalid load balancer ID..."
sys.exit()
print "Path to the error.html page..."
print "It has to be absolute for now..."
try:
file_path = sys.stdin.readline().rstrip('\n')
error_file = open(file_path)
error_page = error_file.read()
except IOError:
print "I can't do that Dave..."
sys.exit()
print "====== OLD ERROR PAGE ======"
print balancer.errorpage().get()
balancer.errorpage().add(error_page)
print "====== NEW ERROR PAGE ======"
print balancer.errorpage().get()
# ##################################################################################################
# ##################################################################################################
elif mode == 2:
print "Remove the error page"
print_balancers(lbs)
print "Type one of the ID's above..."
id = 0
try:
try:
id = int(sys.stdin.readline())
except ValueError:
print "Invalid entry..."
sys.exit()
except IOError:
print "Good bye..."
sys.exit()
try:
balancer = clb.loadbalancers.get(id)
except cloudlb.errors.ResponseError:
print "Invalid load balancer ID..."
sys.exit()
print "====== OLD ERROR PAGE ======"
print balancer.errorpage().get()
balancer.errorpage().delete()
print "====== RESET TO ======"
print balancer.errorpage().get()
# ##################################################################################################
# ##################################################################################################
else:
print "Good bye..."
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment