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.
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.
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]
30 SMF_EXIT_ERR_FATAL = 95
31 SMF_EXIT_ERR_CONFIG = 96
32 SMF_EXIT_MON_DEGRADE = 97
33 SMF_EXIT_MON_OFFLINE = 98
34 SMF_EXIT_ERR_NOSMF = 99
35 SMF_EXIT_ERR_PERM = 100
36 #SMF_EXIT_ERR_OTHER = non-zero
38 cleanupTypes = ("warning", "critical", "emergency")
40 SMFNAME = 'svc:/application/time-slider'
42 ZPOOLPROPGROUP = "zpool"
43 DAEMONPROPGROUP = "daemon"
45 # Commonly used command paths
46 PFCMD = "/usr/bin/pfexec"
47 SVCSCMD = "/usr/bin/svcs"
48 SVCADMCMD = "/usr/sbin/svcadm"
49 SVCCFGCMD = "/usr/sbin/svccfg"
50 SVCPROPCMD = "/usr/bin/svcprop"
53 class TimeSliderSMF(smf.SMFInstance):
55 def __init__(self, instanceName = SMFNAME):
56 smf.SMFInstance.__init__(self, instanceName)
57 self._cleanupLevels = {}
58 self._cleanupLevelsLock = threading.Lock()
60 def get_keep_empties(self):
61 if self.get_prop(ZFSPROPGROUP, "keep-empties") == "true":
66 def is_custom_selection(self):
67 value = self.get_prop(ZFSPROPGROUP, "custom-selection")
73 def get_separator(self):
74 result = self.get_prop(ZFSPROPGROUP, "sep")
76 raise ValueError("zfs/sep must be a single character length")
79 def get_remedial_cleanup(self):
80 value = self.get_prop(ZPOOLPROPGROUP, "remedial-cleanup")
86 def get_cleanup_level(self, cleanupType):
87 if cleanupType not in cleanupTypes:
88 raise ValueError("\'%s\' is not a valid cleanup type" % \
90 self._cleanupLevelsLock.acquire()
91 value = self.get_prop(ZPOOLPROPGROUP, "%s-level" % (cleanupType))
92 self._cleanupLevelsLock.release()
95 def set_cleanup_level(self, cleanupType, level):
96 if cleanupType not in cleanupTypes:
97 raise ValueError("\'%s\' is not a valid cleanup type" % \
100 raise ValueError("Cleanup level value can not not be negative")
101 if cleanupType == "warning" and \
102 level > self.get_cleanup_level("critical"):
103 raise ValueError("Warning cleanup level value can not exceed " + \
104 "critical cleanup level value")
105 elif cleanupType == "critical" and \
106 level > self.get_cleanup_level("emergency"):
107 raise ValueError("Critical cleanup level value can not " + \
108 "exceed emergency cleanup level value")
109 elif level > 100: # Emergency type value
110 raise ValueError("Cleanup level value can not exceed 100")
112 self._cleanupLevelsLock.acquire()
113 propname = "%s-level" % (cleanupType)
114 self.set_integer_prop(ZPOOLPROPGROUP, propname, level)
115 self._cleanupLevels[cleanupType] = level
116 self._cleanupLevelsLock.release()
117 self.refresh_service()
119 def set_custom_selection(self, value):
120 self.set_boolean_prop(ZFSPROPGROUP, "custom-selection", value)
121 self.refresh_service()
123 def get_verbose(self):
124 value = self.get_prop(DAEMONPROPGROUP, "verbose")
130 def __eq__(self, other):
131 if self.fs_name == other.fs_name and \
132 self.interval == other.interval and \
133 self.period == other.period:
138 ret = "SMF Instance:\n" +\
139 "\tName:\t\t\t%s\n" % (self.instanceName) +\
140 "\tState:\t\t\t%s\n" % (self.svcstate) + \
141 "\tVerbose:\t\t%s\n" % str(self.get_verbose()) + \
142 "\tCustom Selction:\t%s\n" % str(self.is_custom_selection()) +\
143 "\tKeep Empties:\t\t%s\n" % str(self.get_keep_empties()) +\
144 "\tWarning Level:\t\t%d\n" % (self.get_cleanup_level("warning")) + \
145 "\tCritical Level:\t\t%d\n" % (self.get_cleanup_level("critical")) + \
146 "\tEmergency Level:\t%d\n" % (self.get_cleanup_level("emergency")) + \
147 "\tSeparator Char:\t\t\'%s\'" % (self.get_separator())
151 if __name__ == "__main__":
152 S = TimeSliderSMF('svc:/application/time-slider')