Forum Discussion

SaranSakthivel's avatar
SaranSakthivel
Icon for Nimbostratus rankNimbostratus
Jan 24, 2018

Disable-Enable virtual server using F5 Python SDK

How to disable/enable a virtual server using f5 python sdk ?

I am getting an error 404, cant have disable when enable is present.

I did the following tweak (delete enabled dictionary key, if i have to disable) to make it work.

Is it the correct method?, is there a better way ?

Before executing the below script, VS was in enabled state

_virtual = g_f5mgmt.tm.ltm.virtuals.virtual.load(partition=_vs_prt_name, name=_vs_name)   
_virtual.disabled = True   
del _virtual.raw['enabled']   
_virtual.update()   

After executing the above script, VS is in disabled state

  • Hi Saran, I'd recommend something a little simpler:

     Load the vip
    vip = b.tm.ltm.virtuals.virtual.load(name='testvip')
    
     Change from enabled to disabled
    del vip.enabled
    vip.disabled = True
    vip.update()
    
     Change from disabled to enabled
    del vip.disabled
    vip.enabled = True
    vip.update()
    
  • Thank You Jason,

    I watched one of the videos from Agility 2017 'The F5 Python SDK for iControl REST'.

    I was interested in the 'reducing Boolean pairs'. I found the following part of the response.
    '_meta_data': {
            'reduction_forcing_pairs': [('enabled',
            'disabled'),
            ('online',
            'offline'),
            ('vlansEnabled',
            'vlansDisabled')]
    

    However when i tried the following i get an error. Is 'reducing Boolean pairs' not supported for virtual server configs ?

    _virtual = g_f5mgmt.tm.ltm.virtuals.virtual.load(partition=_vs_prt_name, name=_vs_name)     
    print(_virtual.enabled)     
    print(_virtual.disabled)      
    
    Output:    
    True    
    '' object has no attribute 'disabled'    
    
  • This is actually a bug in how the virtual server endpoint was created in the sdk. I've submitted a PR that should merge for the 3.0.10 release next Friday, but you can grab my branch to test now if you like. Once updated, you can simply set the state and update:

     From enabled->disabled
    vip.disabled = True
    vip.update()
    
     From disabled->enabled
    vip.enabled = True
    vip.update()
    
  • good call, I didn't even realize that was in there! See my answer below.