Documentation for PythonAPI
17.2.0py1

example

#!/usr/bin/env python

"""
Script to reset VBS data.

This script clears all transferdata for the specified objects.

Observe that PacketLogic uses a sliding window for calculating the
amount of transferred data, so this script should only be used to
force a reset of the accounted transfer. Using this script to reset
VBS data each month instead of allowing the sliding window do its work
is not the recommended mode of operation for VBS in PacketLogic.

Example usage:

 # reset transfer for 10.0.1.10 and 10.0.1.11 in
 # split by localhost object named Cust VBS
 reset-vbsdata.py 192.168.1.25 admin pldemo00 "Cust VBS" 10.0.1.10 10.0.1.11

 # reset transfer for netobject "U-123" in
 # split by netobject object named Users VBS
 reset-vbsdata.py 192.168.1.25 admin pldemo00 "Users VBS" U-123

"""

__version__ = "1.1 2006-08-16 Procera Networks"

###############################################################################
#
#                          NO WARRANTY
#
#  BECAUSE THE PROGRAM IS PROVIDED FREE OF CHARGE, THERE IS NO WARRANTY
#  FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
#  OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
#  PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
#  OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
#  TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
#  PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
#  REPAIR OR CORRECTION.
#
#  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
#  WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
#  REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
#  INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
#  OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
#  TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
#  YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
#  PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
#  POSSIBILITY OF SUCH DAMAGES.
#
###############################################################################

import sys
import packetlogic2

if len(sys.argv) < 4:
    print "Usage: reset-vbsdata.py IP USERNAME PASSWORD [VBSOBJECT [SPLITKEYS ...]]"
    sys.exit(1)


try:
    pl = packetlogic2.connect(sys.argv[1], sys.argv[2], sys.argv[3])
    p = pl.Realtime()
except:
    t, v, tb = sys.exc_info()
    print "Couldn't connect: %s" % v
    sys.exit(1)

args = sys.argv[4:]

if len(args) == 0:
    print "VBS object to reset must be specified."
    print "Available VBS objects:"
    for machine, soid, soname, flags in p.vbs_list():
        print " %s" % soname
    sys.exit(1)


for machine, soid, soname, flags in p.vbs_list():
    if args[0] == soname:
        if flags != 0:
            sp = dict([(d['splitname'], d) for d in p.vbs_query(machine, soid, 0)])

            if len(args) < 2:
                print "Shaping object '%s' is splitted, extra key must be specified" % soname
                print "Available split keys:"
                print " "+("\n ".join(sp.keys()))
                sys.exit(1)
            
            if args[1] == 'all':
                for x in sp.keys():
                    print "Resetting VBS '%s/%s'" % (soname, x)
                    p.vbs_reset(machine, soid, sp[x]['extra'])
            else:
                for x in args[1:]:
                    if not sp.has_key(x):
                        print "VBS '%s/%s' does not exist, skipping" % (soname, x)
                        continue

                    print "Resetting VBS '%s/%s'" % (soname, x)
                    p.vbs_reset(machine, soid, sp[x]['extra'])

        else: #flags == 0, no split
            print "Resetting VBS '%s'" % soname
            p.vbs_reset(machine, soid, 0)

        sys.exit(0)

print "Couldn't find VBS object '%s'" % soname
sys.exit(1)