source: people/peter.buschman/backup_monitoring/parsing/parsers/vmpool/_vmpool.py@ 1067

Last change on this file since 1067 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 
1import re
2
3from ....builtins import *
4
5from ...exceptions import *
6from ...expressions import *
7from ...streams import *
8
9##
10## vmpool has records separated by a line of = characters
11##
12def stream(stream, format='vmpool -list_all'):
13
14 if format in ['vmpool -list_all', 'vmpool -listall']:
15 return LineSeparatorStream(stream, separator='================================================================================', header=1)
16 elif format in ['vmpool -list_scratch']:
17 return LineSeparatorStream(stream, separator='=============', header=2)
18 else:
19 raise ParseError, 'Unknown format %s' % (format)
20
21
22##
23## Parse a vmpool record
24##
25## vmpool -listall
26##
27def parse(record, format='vmpool -listall', version=None, tz=None):
28
29 pool = ExtendedDict()
30 re_pair = re.compile('^([^:]+):\s*(.*)$')
31
32 if format in ['vmpool -list_all', 'vmpool -listall']:
33
34 try:
35
36 for line in record:
37
38 match = re_pair.match(line)
39
40 key = match.group(1)
41 value = match.group(2)
42 key = key.lower()
43 key = key.replace(' ', '_')
44 key = key.replace('/', '_')
45
46 #
47 # Convert to integer value
48 #
49 if re_integer.match(value):
50 value = int(value)
51
52 pool[key] = value
53
54 return pool
55
56 except Exception, e:
57
58 raise ParseError, e
59
60 elif format in ['vmpool -list_scratch']:
61
62 try:
63
64 return record[0]
65
66 except Exception, e:
67
68 raise ParseError, e
69
70 else:
71
72 raise ParseError, 'Unknown format %s' % (format)
73
74
Note: See TracBrowser for help on using the repository browser.