From: Ralf Ertzinger Date: Fri, 21 Feb 2014 14:13:59 +0000 (+0100) Subject: Add linux specific autosnapsmf module and dependencies X-Git-Tag: 0.2.98.python3.1~28 X-Git-Url: https://git.camperquake.de/gitweb.cgi?p=time-slider.git;a=commitdiff_plain;h=bb5f597d37e6c9d9957f7eaf9b6310a3ec071651 Add linux specific autosnapsmf module and dependencies --- diff --git a/usr/share/time-slider/lib/time_slider/linux/autosnapsmf.py b/usr/share/time-slider/lib/time_slider/linux/autosnapsmf.py new file mode 100755 index 0000000..3152cf9 --- /dev/null +++ b/usr/share/time-slider/lib/time_slider/linux/autosnapsmf.py @@ -0,0 +1,129 @@ +#!/usr/bin/python2 +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +import time_slider.autosnapsmf as base +import smf +from timesliderconfig import Config + +SNAPLABELPREFIX = base.SNAPLABELPREFIX + +def get_default_schedules(): + """ + Finds the default schedules that are enabled (online, offline or degraded) + """ + #This is not the fastest method but it is the safest, we need + #to ensure that default schedules are processed in the pre-defined + #order to ensure that the overlap between them is adhered to + #correctly. monthly->weekly->daily->hourly->frequent. They have + #to be processed first and they HAVE to be in the correct order. + _defaultSchedules = [] + for s in base.factoryDefaultSchedules: + instanceName = "%s:%s" % (base.BASESVC,s) + config = Config() + result = config.get(instanceName[5:], "state") + # + # Note that the schedules, being dependent on the time-slider service + # itself will typically be in an offline state when enabled. They will + # transition to an "online" state once time-slider itself comes + # "online" to satisfy it's dependency + if result == "online" or result == "offline" or result == "degraded": + instance = AutoSnap(s) + try: + _defaultSchedules.append(instance.get_schedule_details()) + except RuntimeError, message: + raise RuntimeError, "Error getting schedule details for " + \ + "default auto-snapshot SMF instance:" + \ + "\n\t" + instanceName + "\nDetails:\n" + \ + str(message) + return _defaultSchedules + + +def get_custom_schedules(): + """ + Finds custom schedules ie. not the factory default + 'monthly', 'weekly', 'hourly', 'daily' and 'frequent' schedules + """ + _customSchedules = [] + config = Config() + for section in config.sections(): + if section.startswith(base.BASESVC[5:]): + frmi = section.rsplit(":", 1) + label = frmi[1] + state = config.get(section, "state") + + if label not in base.factoryDefaultSchedules: + # Note that the schedules, being dependent on the time-slider service + # itself will typically be in an offline state when enabled. They will + # transition to an "online" state once time-slider itself comes + # "online" to satisfy it's dependency + if state == "online" or state == "offline" or state == "degraded": + instance = AutoSnap(label) + try: + _customSchedules.append(instance.get_schedule_details()) + except RuntimeError, message: + raise RuntimeError, "Error getting schedule details " + \ + "for custom auto-snapshot SMF " + \ + "instance:\n\t" + label + "\n" + \ + "Details:\n" + str(message) + return _customSchedules + +class AutoSnap(base.AutoSnap): + + def __init__(self, schedule): + base.AutoSnap.__init__(self, schedule) + +# +# This is beyond ugly. +# +# The problem this is trying to solve is to change the inheritance chain. Origially +# it looks like this: +# +# +# +# +# +# +# +# +# We'd like it to look like this: +# +# +# +# +# +# +# +# +# +# so we can inject some linux specific things into SMF without having to copy all +# the code. +# +# This has to be done here as the __init__ of AutoSnap will otherwise fail. +# + +base.AutoSnap.__bases__ = (smf.SMFInstance,) + +if __name__ == "__main__": + defaults = get_default_schedules() + for sched in defaults: + S = AutoSnap(sched[0]) + print S.get_schedule_details() diff --git a/usr/share/time-slider/lib/time_slider/timesliderd.py b/usr/share/time-slider/lib/time_slider/timesliderd.py index d3fee51..dc669b6 100755 --- a/usr/share/time-slider/lib/time_slider/timesliderd.py +++ b/usr/share/time-slider/lib/time_slider/timesliderd.py @@ -44,7 +44,7 @@ import dbussvc import zfs import smf import time_slider.linux.timeslidersmf as timeslidersmf -import autosnapsmf +import time_slider.linux.autosnapsmf as autosnapsmf import plugin from time_slider.linux.rbac import RBACprofile import util