Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

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

0
Rate this Question
Comments on this Question
Comment made 24-Jan-2018 by Jason Rahm

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()
0
Comment made 24-Jan-2018 by Saran 57

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    
'<class 'f5.bigip.tm.ltm.virtual.Virtual'>' object has no attribute 'disabled'    
0
Comment made 25-Jan-2018 by Jason Rahm

good call, I didn't even realize that was in there! See my answer below.

0

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

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()
0
Comments on this Answer
Comment made 25-Jan-2018 by Jason Rahm

this has been merged to the development branch on github.

0
Comment made 31-Jan-2018 by Saran 57

Thank You Jason,

I will try it soon and update.

0