cancel
Showing results for 
Search instead for 
Did you mean: 

Problem this snippet solves:

This script allows the user to query/evict RAMCache entries.

Code :

#!/usr/bin/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.
----------------------------------------------------------------------------
'''

def getRAMCacheEntries(obj, rc_info):

rc_key=obj.typefactory.create('LocalLB.RAMCacheInformation.RAMCacheKey')

key_attr = rc_info.split(' ')
rc_key.profile_name = key_attr[0]
rc_key.host_name = ''
rc_key.uri = ''
rc_key.maximum_responses = 100L

rc_entry = obj.get_ramcache_entry(keys=[rc_key])
return rc_entry

def getRAMCacheExactEntry(obj, rc_info):

rc_key=obj.typefactory.create('LocalLB.RAMCacheInformation.RAMCacheKey')

key_attr = rc_info.split(' ')
rc_key.profile_name = key_attr[0]
rc_key.host_name = key_attr[1]
rc_key.uri = key_attr[2]
rc_key.maximum_responses = 100L

rc_entry = obj.get_ramcache_entry_exact_match(keys=[rc_key])
return rc_entry

def evictRAMCacheEntry(obj, rc_info):

rc_key=obj.typefactory.create('LocalLB.RAMCacheInformation.RAMCacheKey')

key_attr = rc_info.split(' ')
rc_key.profile_name = key_attr[0]
rc_key.host_name = key_attr[1]
rc_key.uri = key_attr[2]
rc_key.maximum_responses = 100L

rc_entry = obj.evict_ramcache_entry_v2(keys=[rc_key], exact_match=False)
return rc_entry

def evictRAMCacheExactEntry(obj, rc_info):

rc_key=obj.typefactory.create('LocalLB.RAMCacheInformation.RAMCacheKey')

key_attr = rc_info.split(' ')
rc_key.profile_name = key_attr[0]
rc_key.host_name = key_attr[1]
rc_key.uri = key_attr[2]
rc_key.maximum_responses = 100L

rc_entry = obj.evict_ramcache_entry_v2(keys=[rc_key], exact_match=True)
return rc_entry

def evictRAMCacheAllEntries(obj):

rc_entry = obj.evict_all_ramcache_entries()
return rc_entry


if __name__ == "__main__":

import sys
import pycontrol.pycontrol as pc
import getpass
from optparse import OptionParser

if pc.__version__[:3] == '2.0':
pass
else:
print "pycontrol 2.x required!"
sys.exit()

parser = OptionParser()
parser.add_option("-H", "--host", action="store", type="string", dest="host")
parser.add_option("-u", "--user", action="store", type="string", dest="uname")
parser.add_option("-g", "--get", action="store", type="string", dest="get", help="Supply profile name")
parser.add_option("-x", "--get_exact", action="store", type="string", dest="get_exact", help="Supply profile name, host, and URI")
parser.add_option("-E", "--evict", action="store", type="string", dest="evict_entry")
parser.add_option("-X", "--evict_exact", action="store", type="string", dest="evict_exact")
parser.add_option("-A", "--evict_all", action="store_false", default=False, dest="evict_all")
(options, args) = parser.parse_args()

if (options.host is None) or (options.uname is None):
print "\n\tHost (-H) and username (-u) must be supplied, exiting..."
sys.exit()

print "Please enter the password for user %s" % options.uname
upass = getpass.getpass()

b = pc.BIGIP(
hostname = options.host,
username = options.uname,
password = upass,
fromurl = True,
wsdls = ['LocalLB.RAMCacheInformation']
)

rc = b.LocalLB.RAMCacheInformation

if options.get is not None:
rce = getRAMCacheEntries(rc, options.get)
print rce

elif options.get_exact is not None:
rce = getRAMCacheExactEntry(rc, options.get_exact)
print rce

elif options.evict_entry is not None:
rce = evictRAMCacheEntry(rc, options.evict_entry)
print rce

elif options.evict_exact is not None:
rce = evictRAMCacheExactEntry(rc, options.evict_exact)
print rce

elif options.evict_all is not None:
rce = evictRAMCacheAllEntries(rc)
print rce

else:
print "No options selected!"
sys.exit()
Version history
Last update:
‎09-Mar-2015 13:16
Updated by:
Contributors