Add linux specific timeslidersmf module and dependencies
[time-slider.git] / usr / share / time-slider / lib / time_slider / linux / timesliderconfig.py
1 #!/usr/bin/python2
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 import ConfigParser
24 import sys
25
26 # Default config file name position
27 configfile = "/etc/time-slider/timesliderd.conf"
28
29 # Default values
30 default_properties = {
31     'application/time-slider': {
32         'zpool/emergency-level': 95,
33         'zpool/critical-level': 90,
34         'zpool/warning-level': 80,
35         'zfs/sep': '_',
36         'daemon/verbose': 'true',
37         'state': 'online',
38     },
39     'system/filesystem/zfs/auto-snapshot:monthly': {
40         'zfs/interval': 'months',
41         'zfs/period': 1,
42         'zfs/keep': 2,
43         'state': 'online',
44     },
45     'system/filesystem/zfs/auto-snapshot:weekly': {
46         'zfs/interval': 'days',
47         'zfs/period': 7,
48         'zfs/keep': 4,
49         'state': 'online',
50     },
51     'system/filesystem/zfs/auto-snapshot:daily': {
52         'zfs/interval': 'days',
53         'zfs/period': 1,
54         'zfs/keep': 6,
55         'state': 'online',
56     },
57     'system/filesystem/zfs/auto-snapshot:hourly': {
58         'zfs/interval': 'hours',
59         'zfs/period': 1,
60         'zfs/keep': 23,
61         'state': 'online',
62     },
63     'system/filesystem/zfs/auto-snapshot:frequent': {
64         'zfs/interval': 'minutes',
65         'zfs/period': 15,
66         'zfs/keep': 3,
67         'state': 'online',
68     },
69 }
70
71 class Config:
72     def __init__(self):
73         self.config = ConfigParser.ConfigParser()
74         self.config.read(configfile)
75
76     def get(self, section, option):
77         try:
78             result = self.config.get(section, option)
79             sys.stderr.write('CONFIG: FILE section %s, option %s with value %s\n' % (section, option, result))
80             return result
81         except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
82             try:
83                 result = default_properties[section][option]
84                 sys.stderr.write('CONFIG: DEFAULT section %s, option %s with value %s\n' % (section, option, result))
85                 return result
86             except KeyError:
87                 sys.stderr.write('CONFIG: NOTFOUND section %s, option %s\n' % (section, option))
88                 return ''
89
90     def sections(self):
91         return self.config.sections()