Forum Discussion

Masoud_pourshab's avatar
Masoud_pourshab
Icon for Nimbostratus rankNimbostratus
Jul 05, 2018

Updating F5 VIP using requests

Hello all, I am using the following code(only brief) to create VIP and pool. How can update an item in a VIP. For example, how can I change NAT from Autonat to None or how to change VIP IP address? Executing the code with new parameter does not overwrite the current configuration. Thank you

 

bigip = requests.session()

 

bigip.auth = (BIGIP_USER, BIGIP_PASS)

 

bigip.verify = False

 

bigip.headers.update({'Content-Type': 'application/json'})

 

bigip.post('%s/ltm/virtual' % BIGIP_URL_BASE, data=json.dumps(payload))

 

BIGIP_URL_BASE = '' % BIGIP_ADDRESS

 

create_http_virtual(bigip, VS_NAME, VS_ADDRESS, VS_PORT, POOL_NAME)

 

  • You must use PATCH instead of POST. See https://devcentral.f5.com/wiki/icontrolrest.icontrolrestuserguide_v1300_3.ashx for details:

    Citation:

    Modifying a resource with PATCH

    Using the PATCH method, you can modify properties of a resource without affecting any other properties.

    To modify an object in the BIG-IP® system configuration, specify the resource in the URI. Do not specify a collection in the URI.

    PATCH https://192.168.25.42/mgmt/tm/pool/~Common~tcb-pool2
    {"member": [{:name":"192.168.25.32:80", "description":"Tertiary web server"}] }
    
  • Adapted to python requests, it would for example translate to:

    payload = {'description':'modified via REST'}
    bigip.patch(BIGIP_URL_BASE + '/ltm/virtual/~Common~vipname',data=json.dumps(payload))
    
  • It seems like I can only patch the description. The following works

     

    payload['description'] = 'test'

     

    bigip.patch(BIGIP_URL_BASE + '/ltm/virtual/test5-http-virtual_python', data=json.dumps(payload))

     

    but they did not work

     

    payload['service port'] = '100'

     

    payload['service_port'] = '100'

     

  • There is no property like this. If you plan to change the port, you need to alter the destination property instead. Try issuing an http GET on the same virtual first, then you can see the exact names and values of all properties.

     

  • tatmotiv if you posted that as an answer the questioned could be flagged as answered now :)