pyControl Creating a DC sample script 1
Problem this snippet solves:
This pyControl script creates a Datacenter. It checks to makesure the ip addres of the bigip is a valid IP address. This version of the script will allow you to pass command line arguments to the script.
Code :
#This Script creates a DC .
import pycontrol.pyControl as pyControl
import sys
import re
#check to see if the right number of arguments are present
nargs = len(sys.argv)
if nargs < 7:
print "Usage: create_dc.py GTM_ip_addr username password DC_name DC_location contact"
sys.exit()
#check to makesure the ip addres is valid
ip_str = sys.argv[1]
def checkip(ip_str):
pattern = r"\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"
if re.match(pattern, ip_str):
return True
else:
print checkip(ip_str)
#Create the BigIP object
b = pyControl.BIGIP(hostname = sys.argv[1],
username = sys.argv[2],
password = sys.argv[3],
wsdl_files = ['GlobalLB.DataCenter']
)
#Create a DC
d = b.GlobalLB_DataCenter
try:
d.create( data_centers = [{'name' : sys.argv[4],
'location': sys.argv[5],
'contact' : sys.argv[6]}])
print "DATA CENTER Successfully created."
except: print "DC creation error. Check log."
# Enable the DC
try:
d.set_enabled_state( data_centers = [sys.argv[4]],
states = ['1']
)
print "DATA CENTER Successfully enabled."
except: print "DC enable error. Check log."Published Mar 09, 2015
Version 1.0JackofallTrades
Historic F5 Account
Joined January 28, 2008
JackofallTrades
Historic F5 Account
Joined January 28, 2008
No CommentsBe the first to comment
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)