03961af2b1731478146573f0b7048bdc14b9a762
[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 MyConfigParser(ConfigParser.ConfigParser):
72     def __init__(self):
73         ConfigParser.ConfigParser.__init__(self)
74
75         for section, content in default_properties.iteritems():
76             if not self.has_section(section):
77                 self.add_section(section)
78             for k,v in content.iteritems():
79                 self.set(section, k, v)
80
81 class Config:
82     def __init__(self):
83         self.config = MyConfigParser()
84         self.config.read(configfile)
85
86     def get(self, section, option):
87         try:
88             result = self.config.get(section, option)
89             sys.stderr.write('CONFIG: GET section %s, option %s with value %s\n' % (section, option, result))
90             return result
91         except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
92             sys.stderr.write('CONFIG: NOTFOUND section %s, option %s\n' % (section, option))
93             return ''
94
95     def sections(self):
96         return self.config.sections()