table_row['pruned_count'])
def __str__(self):
- return f'''{self.path}: {self.schedule}; {self.retention}'''
+ return f'''{self.path} {self.schedule} {self.retention}'''
CREATE_TABLES = '''CREATE TABLE schedules(
id integer PRIMARY KEY ASC,
strftime("%s", "now") - strftime("%s", sm.start) > 0
ORDER BY until;'''
- GET_SCHEDULES = '''SELECT
- s.path, s.subvol, s.rel_path, s.active,
- sm.schedule, sm.retention, sm.start, sm.first, sm.last,
- sm.last_pruned, sm.created, sm.created_count, sm.pruned_count
- FROM schedules s
- INNER JOIN schedules_meta sm ON sm.schedule_id = s.id
- WHERE s.path = ?'''
+ PROTO_GET_SCHEDULES = '''SELECT
+ s.path, s.subvol, s.rel_path, s.active,
+ sm.schedule, sm.retention, sm.start, sm.first, sm.last,
+ sm.last_pruned, sm.created, sm.created_count, sm.pruned_count
+ FROM schedules s
+ INNER JOIN schedules_meta sm ON sm.schedule_id = s.id
+ WHERE'''
- GET_SCHEDULE = '''SELECT
- s.path, s.subvol, s.rel_path, s.active,
- sm.schedule, sm.retention, sm.start, sm.first, sm.last,
- sm.last_pruned, sm.created, sm.created_count, sm.pruned_count
- FROM schedules s
- INNER JOIN schedules_meta sm ON sm.schedule_id = s.id
- WHERE s.path = ? and sm.start = ? AND sm.repeat = ?'''
+ GET_SCHEDULES = PROTO_GET_SCHEDULES + ' s.path = ?'
+
+ GET_SCHEDULE = PROTO_GET_SCHEDULES + ' s.path = ? and sm.start = ? AND sm.repeat = ?'
@classmethod
def get_db_schedules(cls, path, db, fs):
else:
return None
- LIST_SCHEDULES = '''SELECT
- s.path, sm.schedule, sm.retention
- FROM schedules s
- INNER JOIN schedules_meta sm ON sm.schedule_id = s.id
- WHERE'''
-
@classmethod
def list_schedules(cls, path, db, fs, recursive):
with db:
if recursive:
- c = db.execute(cls.LIST_SCHEDULES + ' path LIKE ?',
+ c = db.execute(cls.PROTO_GET_SCHEDULES + ' path LIKE ?',
(f'{path}%',))
else:
- c = db.execute(cls.LIST_SCHEDULES + ' path = ?',
+ c = db.execute(cls.PROTO_GET_SCHEDULES + ' path = ?',
(f'{path}',))
- return [row for row in c.fetchall()]
+ return [cls._from_get_query(row, fs) for row in c.fetchall()]
INSERT_SCHEDULE = '''INSERT INTO
schedules(path, subvol, rel_path, active)
return Schedule.list_schedules(path, db, fs, recursive)
@updates_schedule_db
- def store_snap_schedule(self, fs, sched):
+ def store_snap_schedule(self, fs, args):
+ sched = Schedule(*args)
log.debug(f'attempting to add schedule {sched}')
db = self.get_schedule_db(fs)
sched.store_schedule(db)
import errno
import json
import sqlite3
-from .fs.schedule import SnapSchedClient, Schedule
+from .fs.schedule import SnapSchedClient
from mgr_module import MgrModule, CLIReadCommand, CLIWriteCommand
from mgr_util import CephfsConnectionException
-from rados import ObjectNotFound
from threading import Event
return e.to_tuple()
if not scheds:
return errno.ENOENT, '', f'SnapSchedule for {path} not found'
- return 0, json.dumps([[sched[1], sched[2]] for sched in scheds]), ''
+ return 0, '\n'.join([str(sched) for sched in scheds]), ''
@CLIWriteCommand('fs snap-schedule add',
'name=path,type=CephString '
try:
use_fs = fs if fs else self.default_fs
abs_path = self.resolve_subvolume_path(fs, subvol, path)
- sched = Schedule(abs_path, snap_schedule, retention_policy,
- start, use_fs, subvol, path)
- self.client.store_snap_schedule(use_fs, sched)
+ self.client.store_snap_schedule(use_fs, (abs_path, snap_schedule,
+ retention_policy, start,
+ use_fs, subvol, path))
suc_msg = f'Schedule set for path {path}'
except sqlite3.IntegrityError:
existing_scheds = self.client.get_snap_schedules(use_fs, path)