def perform_operation(args): if not os.path.exists(CURRENT_SCHEDULER): update_current_scheduler("none") # Initialise snapshot scheduler on local node if args.action == "init": ret = initialise_scheduler() if ret != 0: output("Failed to initialise snapshot scheduling") gf_event (eventtypes.SNAPSHOT_SCHEDULER_INIT_FAILED, error=print_error(ret)) return ret # Disable snapshot scheduler if args.action == "disable_force": ret = disable_scheduler() if ret == 0: subprocess.Popen(["touch", "-h", GCRON_TASKS]) gf_event (eventtypes.SNAPSHOT_SCHEDULER_DISABLED, status="Successfuly Disabled") else: gf_event (eventtypes.SNAPSHOT_SCHEDULER_DISABLE_FAILED, error=print_error(ret)) return ret # Check if the symlink to GCRON_TASKS is properly set in the shared storage if (not os.path.lexists(GCRON_UPDATE_TASK) or not os.path.lexists(GCRON_CROND_TASK) or os.readlink(GCRON_CROND_TASK) != GCRON_TASKS): print_str = ("Please run 'snap_scheduler.py' init to initialise " "the snap scheduler for the local node.") log.error(print_str) output(print_str) ret = NODE_NOT_INITIALISED return ret # Check status of snapshot scheduler. if args.action == "status": ret = scheduler_status() if ret == 0: if scheduler_enabled: output("Snapshot scheduling status: Enabled") else: output("Snapshot scheduling status: Disabled") else: output("Failed to check status of snapshot scheduler") return ret # Enable snapshot scheduler if args.action == "enable": ret = enable_scheduler() if ret == 0: subprocess.Popen(["touch", "-h", GCRON_TASKS]) gf_event (eventtypes.SNAPSHOT_SCHEDULER_ENABLED, status="Successfuly Enabled") else: gf_event (eventtypes.SNAPSHOT_SCHEDULER_ENABLE_FAILED, error=print_error(ret)) return ret # Disable snapshot scheduler if args.action == "disable": ret = disable_scheduler() if ret == 0: subprocess.Popen(["touch", "-h", GCRON_TASKS]) gf_event (eventtypes.SNAPSHOT_SCHEDULER_DISABLED, status="Successfuly Disabled") else: gf_event (eventtypes.SNAPSHOT_SCHEDULER_DISABLE_FAILED, error=print_error(ret)) return ret # List snapshot schedules if args.action == "list": ret = list_schedules() return ret # Add snapshot schedules if args.action == "add": ret = syntax_checker(args) if ret != 0: return ret ret = add_schedules(args.jobname, args.schedule, args.volname) if ret == 0: subprocess.Popen(["touch", "-h", GCRON_TASKS]) gf_event (eventtypes.SNAPSHOT_SCHEDULER_SCHEDULE_ADDED, status="Successfuly added job "+args.jobname) else: gf_event (eventtypes.SNAPSHOT_SCHEDULER_SCHEDULE_ADD_FAILED, status="Failed to add job "+args.jobname, error=print_error(ret)) return ret # Delete snapshot schedules if args.action == "delete": ret = syntax_checker(args) if ret != 0: return ret ret = delete_schedules(args.jobname) if ret == 0: subprocess.Popen(["touch", "-h", GCRON_TASKS]) gf_event (eventtypes.SNAPSHOT_SCHEDULER_SCHEDULE_DELETED, status="Successfuly deleted job "+args.jobname) else: gf_event (eventtypes.SNAPSHOT_SCHEDULER_SCHEDULE_DELETE_FAILED, status="Failed to delete job "+args.jobname, error=print_error(ret)) return ret # Edit snapshot schedules if args.action == "edit": ret = syntax_checker(args) if ret != 0: return ret ret = edit_schedules(args.jobname, args.schedule, args.volname) if ret == 0: subprocess.Popen(["touch", "-h", GCRON_TASKS]) gf_event (eventtypes.SNAPSHOT_SCHEDULER_SCHEDULE_EDITED, status="Successfuly edited job "+args.jobname) else: gf_event (eventtypes.SNAPSHOT_SCHEDULER_SCHEDULE_EDIT_FAILED, status="Failed to edit job "+args.jobname, error=print_error(ret)) return ret ret = INVALID_ARG return ret
def perform_operation(args): if not os.path.exists(CURRENT_SCHEDULER): update_current_scheduler("none") # Initialise snapshot scheduler on local node if args.action == "init": ret = initialise_scheduler() if ret != 0: output("Failed to initialise snapshot scheduling") gf_event(eventtypes.SNAPSHOT_SCHEDULER_INIT_FAILED, error=print_error(ret)) return ret # Disable snapshot scheduler if args.action == "disable_force": ret = disable_scheduler() if ret == 0: subprocess.Popen(["touch", "-h", GCRON_TASKS]) gf_event(eventtypes.SNAPSHOT_SCHEDULER_DISABLED, status="Successfuly Disabled") else: gf_event(eventtypes.SNAPSHOT_SCHEDULER_DISABLE_FAILED, error=print_error(ret)) return ret # Check if the symlink to GCRON_TASKS is properly set in the shared storage if (not os.path.lexists(GCRON_UPDATE_TASK) or not os.path.lexists(GCRON_CROND_TASK) or os.readlink(GCRON_CROND_TASK) != GCRON_TASKS): print_str = ("Please run 'snap_scheduler.py' init to initialise " "the snap scheduler for the local node.") log.error(print_str) output(print_str) ret = NODE_NOT_INITIALISED return ret # Check status of snapshot scheduler. if args.action == "status": ret = scheduler_status() if ret == 0: if scheduler_enabled: output("Snapshot scheduling status: Enabled") else: output("Snapshot scheduling status: Disabled") else: output("Failed to check status of snapshot scheduler") return ret # Enable snapshot scheduler if args.action == "enable": ret = enable_scheduler() if ret == 0: subprocess.Popen(["touch", "-h", GCRON_TASKS]) gf_event(eventtypes.SNAPSHOT_SCHEDULER_ENABLED, status="Successfuly Enabled") else: gf_event(eventtypes.SNAPSHOT_SCHEDULER_ENABLE_FAILED, error=print_error(ret)) return ret # Disable snapshot scheduler if args.action == "disable": ret = disable_scheduler() if ret == 0: subprocess.Popen(["touch", "-h", GCRON_TASKS]) gf_event(eventtypes.SNAPSHOT_SCHEDULER_DISABLED, status="Successfuly Disabled") else: gf_event(eventtypes.SNAPSHOT_SCHEDULER_DISABLE_FAILED, error=print_error(ret)) return ret # List snapshot schedules if args.action == "list": ret = list_schedules() return ret # Add snapshot schedules if args.action == "add": ret = syntax_checker(args) if ret != 0: return ret ret = add_schedules(args.jobname, args.schedule, args.volname) if ret == 0: subprocess.Popen(["touch", "-h", GCRON_TASKS]) gf_event(eventtypes.SNAPSHOT_SCHEDULER_SCHEDULE_ADDED, status="Successfuly added job " + args.jobname) else: gf_event(eventtypes.SNAPSHOT_SCHEDULER_SCHEDULE_ADD_FAILED, status="Failed to add job " + args.jobname, error=print_error(ret)) return ret # Delete snapshot schedules if args.action == "delete": ret = syntax_checker(args) if ret != 0: return ret ret = delete_schedules(args.jobname) if ret == 0: subprocess.Popen(["touch", "-h", GCRON_TASKS]) gf_event(eventtypes.SNAPSHOT_SCHEDULER_SCHEDULE_DELETED, status="Successfuly deleted job " + args.jobname) else: gf_event(eventtypes.SNAPSHOT_SCHEDULER_SCHEDULE_DELETE_FAILED, status="Failed to delete job " + args.jobname, error=print_error(ret)) return ret # Edit snapshot schedules if args.action == "edit": ret = syntax_checker(args) if ret != 0: return ret ret = edit_schedules(args.jobname, args.schedule, args.volname) if ret == 0: subprocess.Popen(["touch", "-h", GCRON_TASKS]) gf_event(eventtypes.SNAPSHOT_SCHEDULER_SCHEDULE_EDITED, status="Successfuly edited job " + args.jobname) else: gf_event(eventtypes.SNAPSHOT_SCHEDULER_SCHEDULE_EDIT_FAILED, status="Failed to edit job " + args.jobname, error=print_error(ret)) return ret ret = INVALID_ARG return ret
try: f = open(GCRON_TASKS, "w", 0644) f.close() except IOError as (errno, strerror): log.error("Failed to open %s. Error: %s.", GCRON_TASKS, strerror) ret = INIT_FAILED return ret if os.path.lexists(GCRON_CROND_TASK): os.remove(GCRON_CROND_TASK) os.symlink(GCRON_TASKS, GCRON_CROND_TASK) log.info("Successfully initialised snapshot scheduler for this node") output("Successfully initialised snapshot scheduler for this node") gf_event (eventtypes.SNAPSHOT_SCHEDULER_INITIALISED, status="Success") ret = 0 return ret def syntax_checker(args): if hasattr(args, 'jobname'): if (len(args.jobname.split()) != 1): output("Invalid Jobname. Jobname should not be empty and should not contain \" \" character.") ret = INVALID_JOBNAME return ret args.jobname=args.jobname.strip() if hasattr(args, 'volname'): if (len(args.volname.split()) != 1):
try: f = open(GCRON_TASKS, "w", 0644) f.close() except IOError as (errno, strerror): log.error("Failed to open %s. Error: %s.", GCRON_TASKS, strerror) ret = INIT_FAILED return ret if os.path.lexists(GCRON_CROND_TASK): os.remove(GCRON_CROND_TASK) os.symlink(GCRON_TASKS, GCRON_CROND_TASK) log.info("Successfully initialised snapshot scheduler for this node") output("Successfully initialised snapshot scheduler for this node") gf_event(eventtypes.SNAPSHOT_SCHEDULER_INITIALISED, status="Success") ret = 0 return ret def syntax_checker(args): if hasattr(args, 'jobname'): if (len(args.jobname.split()) != 1): output( "Invalid Jobname. Jobname should not be empty and should not contain \" \" character." ) ret = INVALID_JOBNAME return ret args.jobname = args.jobname.strip()