f5Automation
Thank you for Subscribing! x

How to create wideip on F5 GTM DNS using Python

The article shows you how to create a wideip on F5 GTM DNS using Python with the help of F5 iControl REST API

The below code snippet imports the necessary python modules required by the script

          
            import requests
            import json
            import warnings
            warnings.filterwarnings('ignore', message='Unverified HTTPS request')
            
        
        

Here we read declaring the device IPaddress and credentials


           
            f5device =  "192.168.2.66"
            user = "admin"
            password = "p@ssword123"
            
            
                
                



                  

In this specific portion we are defining the payload that need be sent the F5 REST API to create the wideip on the F5 GTM/DNS.

                    headers = {'Content-type': 'application/json'}
                    dc_data = {"name":"India","enabled":True}
                    vs_data = {"name":"lab.localhost","enabled":True,"virtual-servers":[{'name':'test_vs','destination':'1.1.1.1:80'}],"addresses":['192.168.2.66'],"datacenter":"India"}
                    pool_data = {"name":"test_pool","enabled":True,"members":['lab.localhost:test_vs']}
                    wip_data = {"name":"test1.gtm.com","enabled":True,"pools":['test_pool']}
                    
                    



                  

Below we define the REST API call that creates the wideip,pool,server and virtual servers on the f5 GTM/DNS

       
        def create_dc():
            r = requests.post("https://"+f5device+"/mgmt/tm/gtm/datacenter", data=json.dumps(dc_data),auth=(user,password),headers=headers,verify=False)
            print(r.text)
      
      
        def create_vs():
            r = requests.post("https://"+f5device+"/mgmt/tm/gtm/server", data=json.dumps(vs_data),auth=(user,password),headers=headers,verify=False)
            print(r.text)
      
      
        def create_pool():
            r = requests.post("https://"+f5device+"/mgmt/tm/gtm/pool/a", data=json.dumps(pool_data),auth=(user,password),headers=headers,verify=False)
            print(r.text)
      
      
        def create_wip():
            r = requests.post("https://"+f5device+"/mgmt/tm/gtm/wideip/a", data=json.dumps(wip_data),auth=(user,password),headers=headers,verify=False)
            print(r.text)
      
        print("creating datacenter")
        create_dc()
        print("creating virtual server")
        create_vs()
        print("creating pool")
        create_pool()
        print("creating wideip")
        create_wip()
      
      

      

You can find the full version of the above code on my Github

            https://github.com/anesh/f5automationblog/
        

Banner

.