Forum Discussion

vladtache_35966's avatar
vladtache_35966
Icon for Nimbostratus rankNimbostratus
Jun 13, 2018

How to update/delete the attribute of an object using F5 SDK

Hi all,

 

I would like to ask for an advice> I would like to update/delete the attribute of an object .

 

From this collection : mgmt.tm.net.selfips.get_collection() i would like to update : selfip.allowService

 

I noticed that for example when selfip.allowService is set to allow none from GUI this attribute allowService is missing from selfip.raw output So if i want to set this attribute to none in case it has allow all should i update the attribute to none or delete the attribute ?

 

Would you please advise and also recommend some documentation to read to better understand the update/delete process?

 

Regards,Vlad

 

2 Replies

  • I believe you are after an iControl REST method equivalent to the following tmsh:

    tmsh modify net self allow-service none

    In iControl REST, use an empty list [] for none. A curl example is shown below. The same method should work for Python SDK too.

    curl -sku admin: https:///mgmt/tm/net/self/-H "Content-Type: application/json" -X PATCH -d '{"allowService":[]}'

  • ... and a sample python code.

     

    The code becomes complex because the data type of the allowService field value depends on what you specify.

     

    Allow All is a string: 'all'
    Allow default is a list containing the string default: ['default']
    Allow none is represented by absence of the allowService field.
    The code is not sophisticated and there should be a better way, but at least it does the job for you.

     

    !/usr/bin/env python 
    from f5.bigip import ManagementRoot 
    
    mgmt = ManagementRoot('xx.xx.xx.xx', 'admin', 'adminPass') 
    def showSelfIp(str):
      selfIp = mgmt.tm.net.selfips.get_collection()
      selfIpList = {ip.raw['name']: ip for ip in selfIp}
      print('--- {}'.format(str))
      for ip, obj in selfIpList.iteritems():
        try: 
          allowService = obj.raw['allowService'] 
        except KeyError: 
          allowService = 'None' 
          allowServiceType = type(allowService) 
          print('{:<20}{:<20}{}'.format(ip, allowService, allowServiceType)) 
          return selfIpList 
    
    # Get a list of selfIP 
    selfIpList = showSelfIp('Before') 
    # Change allowService of 'vmnet1-self' from 'all' to 'default' ([list]) 
    selfIp1 = selfIpList['vmnet1-self'] 
    selfIp1.raw['allowService'] = ['default'] 
    selfIp1.update() 
    selfIpList = showSelfIp('vmnet1-self to default') 
    # Change allowService from 'default' to 'all' (string) 
    selfIp2 = selfIpList['vmnet2-self'] 
    selfIp2.raw['allowService'] = 'all' 
    selfIp2.update() 
    selfIpList = showSelfIp('vmnet2-self to all') 
    # Change allowService from 'default' to 'None' (no field) 
    selfIp3 = selfIpList['vmnet3-self'] 
    del selfIp3.raw['allowService'] 
    selfIp3.update() 
    selfIpList = showSelfIp('vmnet3-self to None') 
    # Done