pyControl Toggle Pool Member

Problem this snippet solves:

Summary: A sample pyControl script that toggles a pool member. The main point is the usage of the pycontrol.Utils module, that has some convenience functions for disabling/enabling/status checking of a pool member.

You'll need to change the parameters to reflect your system(s). In this example our BigIP system is 192.168.1.245 with the default username and password info. Our test pool is called pyControl, and the pool member we are toggling is 192.168.43.11 on port 80. Change these to reflect your environment (see syntax, below).

Script

toggle_pool_member.py

How to use this snippet:

The following syntax usage is taken from the IPython interactive shell.

In [10]: import pycontrol.pyControl as pc
In [11]: from pycontrol.Utils import disable_member, enable_member, show_status
In [12]: b = pc.BIGIP(hostname = '192.168.1.245', username = 'admin', password = 'admin', wsdl_files = ['LocalLB.PoolMember'])
In [13]: disable_member(b.LocalLB_PoolMember, 'pyControl', '192.168.43.11:80')
In [15]: enable_member(b.LocalLB_PoolMember, 'pyControl', '192.168.43.11:80')

Code :

#!/bin/env python

'''
----------------------------------------------------------------------------
 The contents of this file are subject to the "END USER LICENSE AGREEMENT FOR F5
 Software Development Kit for iControl"; you may not use this file except in
 compliance with the License. The License is included in the iControl
 Software Development Kit.

 Software distributed under the License is distributed on an "AS IS"
 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 the License for the specific language governing rights and limitations
 under the License.

 The Original Code is iControl Code and related documentation
 distributed by F5.

 The Initial Developer of the Original Code is F5 Networks,
 Inc. Seattle, WA, USA. Portions created by F5 are Copyright (C) 1996-2004 F5 Networks,
 Inc. All Rights Reserved.  iControl (TM) is a registered trademark of F5 Networks, Inc.

 Alternatively, the contents of this file may be used under the terms
 of the GNU General Public License (the "GPL"), in which case the
 provisions of GPL are applicable instead of those above.  If you wish
 to allow use of your version of this file only under the terms of the
 GPL and not to allow others to use your version of this file under the
 License, indicate your decision by deleting the provisions above and
 replace them with the notice and other provisions required by the GPL.
 If you do not delete the provisions above, a recipient may use your
 version of this file under either the License or the GPL.
----------------------------------------------------------------------------
'''

import pycontrol.pyControl as pc
from pycontrol.Utils import disable_member, enable_member, show_status

#create the PoolMember object to pass into the methods.

b = pc.BIGIP(
hostname = '192.168.1.245',
username   = 'admin',
password   = 'admin',
wsdl_files = ['LocalLB.PoolMember']

)
#Create a shortcut to the object to save keystrokes...
mbr = b.LocalLB_PoolMember

print "Disabling pool member...\n"

disable_member( mbr,
pool = 'pyControl',
member = '192.168.43.11:80') 

for x in mbr.get_session_enabled_state( pool_names = ['pyControl'])['return'][0]:
print "\t %s:%s => %s" % (x['member']['address'], x['member']['port'], x['session_state']) 

print "Enabling pool member...\n"

enable_member(  mbr,
pool = 'pyControl',
member = '192.168.43.11:80',
) 

for x in mbr.get_session_enabled_state(
pool_names = ['pyControl'])['return'][0]:
print "\t %s:%s => %s" % (x['member']['address'], x['member']['port'], x['session_state'])
Published Mar 09, 2015
Version 1.0
No CommentsBe the first to comment