Forum Discussion

DarioGB_339840's avatar
DarioGB_339840
Icon for Altostratus rankAltostratus
Jul 04, 2018

Check if property exists in F5 SDK Python

Hello.

After get a virtual server collection, I'm looking for a method to validate if an specific resource property exists, for example pools & rules, which are optional parameters.

Next below, three ways with errors:

virtuals = session.tm.ltm.virtuals.get_collection()
for virtual in virtuals:
    if virtual.pool != None:
        print(virtual.pool)
    --->> AttributeError: '' object has no attribute 'pool'
    if virtual.get('pool') != None:
        print(virtual.pool)        
    --->> AttributeError: '' object has no attribute 'get'
    if virtual['pool'] != None:
        print(virtual.pool)
    --->> TypeError: 'Virtual' object is not subscriptable

Same way for rules :-S

I'm newbie in python. How do you do this in your scenarios?

Thanks in advance!

KR, Dario.