source: people/peter.buschman/backup_monitoring/backmon/commands/check/_check.py@ 1269

Last change on this file since 1269 was 976, checked in by peter, on Dec 6, 2011 at 10:19:33 AM

Raw checkin of current NetBackup / TSM parsing code.

File size: 1.7 KB
Line 
1#!/usr/bin/python26
2###
3### backmon.commands.check
4###
5
6import sys
7import os
8import os.path
9import glob
10import re
11
12from optparse import OptionParser
13
14from ...lib import *
15
16import subcommands
17
18SUBCOMMAND_LIST = [
19 'dssu',
20 'jobs',
21 'scratch',
22 'puredisk',
23]
24
25SUBCOMMAND_HELP = {
26 'dssu' : 'check disk staging storage unit',
27 'jobs' : 'check active jobs',
28 'scratch' : 'check scratch media',
29 'puredisk' : 'check puredisk status',
30}
31
32##
33## OPTIONS
34##
35usage = """Usage: %prog [options] -e [ENVIRONMENT] -g [HOSTGROUP] check [subcommand] [options] [arguments]'
36
37 available subcommands:
38
39""" + '\n'.join([' %-12s %s' % (cmd, SUBCOMMAND_HELP[cmd]) for cmd in SUBCOMMAND_LIST])
40
41parser = OptionParser(usage=usage)
42
43def run(args, kwargs):
44
45 #
46 # add kwargs to local namespace
47 #
48 for key in kwargs.keys():
49
50 if re.compile('^[A-Z][A-Z_]+$').match(key):
51 exec(key + ' = kwargs[\'' + key + '\']')
52
53 SUBCOMMAND=None
54 subcommand_pos = 0
55
56 i = 0
57
58 for arg in args:
59
60 i += 1
61
62 if arg in SUBCOMMAND_LIST:
63 SUBCOMMAND = arg
64 subcommand_pos = i
65 break
66
67 subcommand_args = args[subcommand_pos:]
68
69 if SUBCOMMAND:
70 (options, args) = parser.parse_args(args[:subcommand_pos])
71
72 #
73 # SUBCOMMAND
74 #
75 if( not SUBCOMMAND ):
76 parser.print_help()
77 sys.exit(1)
78
79 DEBUG('SUBCOMMAND=%s' % (SUBCOMMAND))
80
81 if hasattr(subcommands, SUBCOMMAND):
82 exec 'subcommands.' + SUBCOMMAND + '.run(subcommand_args, locals())'
83 else:
84 ERROR('Invalid subcommand \'%s\'.' % (SUBCOMMAND))
85
86
Note: See TracBrowser for help on using the repository browser.