Line | |
---|
1 | import re
|
---|
2 |
|
---|
3 | from ....builtins import *
|
---|
4 |
|
---|
5 | from ...exceptions import *
|
---|
6 | from ...expressions import *
|
---|
7 | from ...streams import *
|
---|
8 |
|
---|
9 | ##
|
---|
10 | ## ontap df has one record per-line
|
---|
11 | ##
|
---|
12 | def stream(stream, format='df -s'):
|
---|
13 |
|
---|
14 | if format in ['df -s']:
|
---|
15 | return NewLineStream(stream, header=1)
|
---|
16 | else:
|
---|
17 | raise ParseError, 'Unknown format %s' % (format)
|
---|
18 |
|
---|
19 |
|
---|
20 | ##
|
---|
21 | ## Parse an ontap df record
|
---|
22 | ##
|
---|
23 | def parse(record, format='df -s', version=None, tz=None):
|
---|
24 |
|
---|
25 | fs = ExtendedDict()
|
---|
26 |
|
---|
27 | if format == 'df -s':
|
---|
28 |
|
---|
29 | regex = re.compile('^(\S+)\s+(\d+)\s+(\d+)\s+(\d+)%.*$')
|
---|
30 |
|
---|
31 | try:
|
---|
32 |
|
---|
33 | match = regex.match(record)
|
---|
34 |
|
---|
35 | filesystem = match.group(1)
|
---|
36 |
|
---|
37 | if filesystem[-1] == '/':
|
---|
38 | filesystem = filesystem[:-1]
|
---|
39 |
|
---|
40 | fs['filesystem'] = filesystem
|
---|
41 | fs['used'] = long(match.group(2))
|
---|
42 | fs['saved'] = long(match.group(3))
|
---|
43 | fs['pct_saved'] = int(match.group(4))
|
---|
44 |
|
---|
45 | return fs
|
---|
46 |
|
---|
47 | except Exception, e:
|
---|
48 |
|
---|
49 | raise ParseError, e
|
---|
50 |
|
---|
51 | else:
|
---|
52 |
|
---|
53 | raise ParseError, 'Unknown format %s' % (format)
|
---|
Note:
See
TracBrowser
for help on using the repository browser.