cancel
Showing results for 
Search instead for 
Did you mean: 
Login & Join the DevCentral Connects Group to watch the Recorded LiveStream (May 12) on Basic iControl Security - show notes included.
JackofallTrades
Historic F5 Account

Problem this snippet solves:

This script creates a DC with pyControl..

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']


    )

################################################
Version history
Last update:
‎09-Mar-2015 12:22
Updated by:
Contributors