Line | |
---|
1 | #!/usr/bin/python26
|
---|
2 | ###
|
---|
3 | ### backmon.commands.check
|
---|
4 | ###
|
---|
5 |
|
---|
6 | import sys
|
---|
7 | import os
|
---|
8 | import os.path
|
---|
9 | import glob
|
---|
10 | import re
|
---|
11 |
|
---|
12 | from optparse import OptionParser
|
---|
13 |
|
---|
14 | from ...lib import *
|
---|
15 |
|
---|
16 | import subcommands
|
---|
17 |
|
---|
18 | SUBCOMMAND_LIST = [
|
---|
19 | 'dssu',
|
---|
20 | 'jobs',
|
---|
21 | 'scratch',
|
---|
22 | 'puredisk',
|
---|
23 | ]
|
---|
24 |
|
---|
25 | SUBCOMMAND_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 | ##
|
---|
35 | usage = """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 |
|
---|
41 | parser = OptionParser(usage=usage)
|
---|
42 |
|
---|
43 | def 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.