Skip to content

Commit 36a86b5

Browse files
author
Brian Glogower
committed
Bounce now accepts an optional sleep argument for vservers
Some more PEP8 clean up
1 parent f28d155 commit 36a86b5

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

CONTRIBUTE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
1818
### Add a new second level argument, i.e. lb-vservers
1919
1. Create a new subparser off of parent subparser
20-
* `subparser_show = parser_show.add_subparsers(dest='subparserName')`
20+
* `subparser_show = parser_show.add_subparsers(dest='subparser_name')`
2121
1. Create parser
2222
2323
subparser_show.add_parser('lb-vservers', help='Shows all lb vservers')

netscalertool/netscalertool.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import socket
2525
import subprocess
2626
import sys
27+
import time
2728
import yaml
2829

2930
import netscalerapi
@@ -457,6 +458,8 @@ def server(self):
457458
raise
458459

459460
def vserver(self):
461+
debug = self.args.debug
462+
sleep = self.args.sleep
460463
vserver = self.args.vserver
461464

462465
properties = {
@@ -465,8 +468,13 @@ def vserver(self):
465468
}
466469

467470
try:
468-
if self.args.debug:
471+
if debug:
469472
print "\nAttempting to enable vserver %s" % vserver
473+
if sleep:
474+
if debug:
475+
print "Sleeping %d seconds before enabling %s" % (sleep,
476+
vserver)
477+
time.sleep(sleep)
470478
self.client.modify_object(properties)
471479
except RuntimeError:
472480
raise
@@ -593,7 +601,7 @@ def __call__(self, parser, namespace, values, option_string=None):
593601
print >> sys.stderr, msg
594602
sys.exit(1)
595603

596-
if namespace.subparserName == "server":
604+
if namespace.subparser_name == "server":
597605
# Checking if specified server is allowed to be managed
598606
try:
599607
cmd = ns_config["external_nodes"]
@@ -623,7 +631,7 @@ def __call__(self, parser, namespace, values, option_string=None):
623631
logger.info(msg)
624632

625633
# Checking if specified vserver is allowed to be managed
626-
elif namespace.subparserName == "vserver":
634+
elif namespace.subparser_name == "vserver":
627635
if values not in ns_config["manage_vservers"]:
628636
msg = "%s is a vserver that is not allowed to be " \
629637
"managed. If you would like to change this, " \
@@ -663,13 +671,13 @@ def __call__(self, parser, namespace, values, option_string=None):
663671
"--dryrun", action="store_true", help="Dryrun", default=False)
664672

665673
# Creating subparser.
666-
subparser = parser.add_subparsers(dest='topSubparserName')
674+
subparser = parser.add_subparsers(dest='top_subparser_name')
667675

668676
# Creating show subparser.
669677
parser_show = subparser.add_parser(
670678
'show', help='sub-command for showing objects'
671679
)
672-
subparser_show = parser_show.add_subparsers(dest='subparserName')
680+
subparser_show = parser_show.add_subparsers(dest='subparser_name')
673681
subparser_show.add_parser('lb-vservers', help='Shows all lb vservers')
674682
parser_show_lbvserver = subparser_show.add_parser(
675683
'lb-vserver', help='Shows stat(s) of a specified lb vserver'
@@ -717,7 +725,7 @@ def __call__(self, parser, namespace, values, option_string=None):
717725
parser_stat = subparser.add_parser(
718726
'stat', help='sub-command for showing ns_object stats'
719727
)
720-
subparser_stat = parser_stat.add_subparsers(dest='subparserName')
728+
subparser_stat = parser_stat.add_subparsers(dest='subparser_name')
721729
parser_stat_lb_vservers = subparser_stat.add_parser(
722730
'lb-vservers', help='Shows stats of all lbvservers'
723731
)
@@ -729,7 +737,7 @@ def __call__(self, parser, namespace, values, option_string=None):
729737
parser_cmp = subparser.add_parser(
730738
'compare', help='sub-command for comparing objects'
731739
)
732-
subparser_cmp = parser_cmp.add_subparsers(dest='subparserName')
740+
subparser_cmp = parser_cmp.add_subparsers(dest='subparser_name')
733741
subparser_cmp.add_parser(
734742
'configs', help='Compares running and saved ns configs'
735743
)
@@ -743,7 +751,7 @@ def __call__(self, parser, namespace, values, option_string=None):
743751
parser_enable = subparser.add_parser(
744752
'enable', help='sub-command for enable objects'
745753
)
746-
subparser_enable = parser_enable.add_subparsers(dest='subparserName')
754+
subparser_enable = parser_enable.add_subparsers(dest='subparser_name')
747755
parser_enable_server = subparser_enable.add_parser(
748756
'server',
749757
help='Enable server. Will actually enable all services bound to '
@@ -763,7 +771,7 @@ def __call__(self, parser, namespace, values, option_string=None):
763771
parser_disable = subparser.add_parser(
764772
'disable', help='sub-command for disabling objects'
765773
)
766-
subparser_disable = parser_disable.add_subparsers(dest='subparserName')
774+
subparser_disable = parser_disable.add_subparsers(dest='subparser_name')
767775
parser_disable_server = subparser_disable.add_parser(
768776
'server', help='Disable server'
769777
)
@@ -786,13 +794,16 @@ def __call__(self, parser, namespace, values, option_string=None):
786794
parser_bounce = subparser.add_parser(
787795
'bounce', help='sub-command for bouncing objects'
788796
)
789-
subparser_bounce = parser_bounce.add_subparsers(dest='subparserName')
797+
subparser_bounce = parser_bounce.add_subparsers(dest='subparser_name')
790798
parser_bounce_vserver = subparser_bounce.add_parser(
791799
'vserver', help='Bounce vserver'
792800
)
793801
parser_bounce_vserver.add_argument(
794802
'vserver', action=AllowedToManage, help='Vserver to bounce'
795803
)
804+
parser_bounce_vserver.add_argument('--sleep', type=int, help='Amount of '
805+
'time to sleep between disabling and '
806+
'enabling vserver')
796807

797808
# Getting arguments
798809
args = parser.parse_args()
@@ -812,13 +823,14 @@ def __call__(self, parser, namespace, values, option_string=None):
812823
print
813824

814825
# Getting method, based on subparser called from argparse.
815-
method = args.subparserName.replace('-', '')
826+
method = args.subparser_name.replace('-', '')
816827

817828
# Getting class, based on subparser called from argparse.
818829
try:
819-
klass = globals()[args.topSubparserName.capitalize()]
830+
klass = globals()[args.top_subparser_name.capitalize()]
820831
except KeyError:
821-
msg = "%s, %s is not a valid subparser." % (user, args.topSubparserName)
832+
msg = "%s, %s is not a valid subparser." % (user,
833+
args.top_subparser_name)
822834
print >> sys.stderr, msg
823835
logger.critical(msg)
824836
return 1
@@ -847,7 +859,7 @@ def __call__(self, parser, namespace, values, option_string=None):
847859
retval = 1
848860
finally:
849861
# Saving config if we run a enable or disable command
850-
if args.topSubparserName in ["bounce", "disable", "enable"]:
862+
if args.top_subparser_name in ["bounce", "disable", "enable"]:
851863
try:
852864
netscaler_tool.client.save_config()
853865
logger.info("Saving NetScaler config")

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def load_requirements(fname):
4646

4747
setup(
4848
name='netscaler-tool',
49-
version='1.26.0',
49+
version='1.27.0',
5050
packages=find_packages(),
5151

5252
author="Brian Glogower",

0 commit comments

Comments
 (0)