|
@@ -13,7 +13,7 @@ from flask import (
|
|
|
url_for,
|
|
url_for,
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-from db import db, Job, Run, Destination
|
|
|
|
|
|
|
+from db import db, Job, Run, Destination, RemoteInstance
|
|
|
from helpers import read_archive_info, get_ynh_apps
|
|
from helpers import read_archive_info, get_ynh_apps
|
|
|
|
|
|
|
|
bp = Blueprint("jobs", __name__)
|
|
bp = Blueprint("jobs", __name__)
|
|
@@ -50,7 +50,8 @@ def job_new():
|
|
|
return _save_job(None)
|
|
return _save_job(None)
|
|
|
return render_template("job_form.html", job=None,
|
|
return render_template("job_form.html", job=None,
|
|
|
ynh_apps=get_ynh_apps(exclude_app_ids=_used_app_ids()),
|
|
ynh_apps=get_ynh_apps(exclude_app_ids=_used_app_ids()),
|
|
|
- destinations=Destination.query.filter_by(enabled=True).all())
|
|
|
|
|
|
|
+ destinations=Destination.query.filter_by(enabled=True).all(),
|
|
|
|
|
+ remote_instances=RemoteInstance.query.order_by(RemoteInstance.name).all())
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/jobs/<int:job_id>/edit", methods=["GET", "POST"])
|
|
@bp.route("/jobs/<int:job_id>/edit", methods=["GET", "POST"])
|
|
@@ -60,7 +61,8 @@ def job_edit(job_id):
|
|
|
return _save_job(job)
|
|
return _save_job(job)
|
|
|
return render_template("job_form.html", job=job,
|
|
return render_template("job_form.html", job=job,
|
|
|
ynh_apps=get_ynh_apps(exclude_app_ids=_used_app_ids(exclude_job_id=job_id)),
|
|
ynh_apps=get_ynh_apps(exclude_app_ids=_used_app_ids(exclude_job_id=job_id)),
|
|
|
- destinations=Destination.query.filter_by(enabled=True).all())
|
|
|
|
|
|
|
+ destinations=Destination.query.filter_by(enabled=True).all(),
|
|
|
|
|
+ remote_instances=RemoteInstance.query.order_by(RemoteInstance.name).all())
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/jobs/<int:job_id>/delete", methods=["POST"])
|
|
@bp.route("/jobs/<int:job_id>/delete", methods=["POST"])
|
|
@@ -342,7 +344,8 @@ def _save_job(job):
|
|
|
if not name:
|
|
if not name:
|
|
|
flash("Le nom est requis.", "error")
|
|
flash("Le nom est requis.", "error")
|
|
|
return render_template("job_form.html", job=job, ynh_apps=get_ynh_apps(exclude_app_ids=_used_app_ids(exclude_job_id=job.id if job else None)),
|
|
return render_template("job_form.html", job=job, ynh_apps=get_ynh_apps(exclude_app_ids=_used_app_ids(exclude_job_id=job.id if job else None)),
|
|
|
- destinations=Destination.query.filter_by(enabled=True).all())
|
|
|
|
|
|
|
+ destinations=Destination.query.filter_by(enabled=True).all(),
|
|
|
|
|
+ remote_instances=RemoteInstance.query.order_by(RemoteInstance.name).all())
|
|
|
|
|
|
|
|
cfg = {}
|
|
cfg = {}
|
|
|
if job_type == "ynh_app":
|
|
if job_type == "ynh_app":
|
|
@@ -354,14 +357,16 @@ def _save_job(job):
|
|
|
if not dbname:
|
|
if not dbname:
|
|
|
flash("Le nom de la base de données est requis.", "error")
|
|
flash("Le nom de la base de données est requis.", "error")
|
|
|
return render_template("job_form.html", job=job, ynh_apps=get_ynh_apps(exclude_app_ids=_used_app_ids(exclude_job_id=job.id if job else None)),
|
|
return render_template("job_form.html", job=job, ynh_apps=get_ynh_apps(exclude_app_ids=_used_app_ids(exclude_job_id=job.id if job else None)),
|
|
|
- destinations=Destination.query.filter_by(enabled=True).all())
|
|
|
|
|
|
|
+ destinations=Destination.query.filter_by(enabled=True).all(),
|
|
|
|
|
+ remote_instances=RemoteInstance.query.order_by(RemoteInstance.name).all())
|
|
|
cfg = {"database": dbname}
|
|
cfg = {"database": dbname}
|
|
|
elif job_type == "custom_dir":
|
|
elif job_type == "custom_dir":
|
|
|
source_path = f.get("source_path", "").strip().rstrip("/")
|
|
source_path = f.get("source_path", "").strip().rstrip("/")
|
|
|
if not source_path or not source_path.startswith("/"):
|
|
if not source_path or not source_path.startswith("/"):
|
|
|
flash("Le chemin source doit être un chemin absolu (ex: /opt/monapp).", "error")
|
|
flash("Le chemin source doit être un chemin absolu (ex: /opt/monapp).", "error")
|
|
|
return render_template("job_form.html", job=job, ynh_apps=get_ynh_apps(exclude_app_ids=_used_app_ids(exclude_job_id=job.id if job else None)),
|
|
return render_template("job_form.html", job=job, ynh_apps=get_ynh_apps(exclude_app_ids=_used_app_ids(exclude_job_id=job.id if job else None)),
|
|
|
- destinations=Destination.query.filter_by(enabled=True).all())
|
|
|
|
|
|
|
+ destinations=Destination.query.filter_by(enabled=True).all(),
|
|
|
|
|
+ remote_instances=RemoteInstance.query.order_by(RemoteInstance.name).all())
|
|
|
excludes = [e.strip() for e in f.get("excludes", "").splitlines() if e.strip()]
|
|
excludes = [e.strip() for e in f.get("excludes", "").splitlines() if e.strip()]
|
|
|
restore_cfg = {}
|
|
restore_cfg = {}
|
|
|
user_name = f.get("restore_user_name", "").strip()
|
|
user_name = f.get("restore_user_name", "").strip()
|
|
@@ -395,7 +400,7 @@ def _save_job(job):
|
|
|
db.session.add(job)
|
|
db.session.add(job)
|
|
|
|
|
|
|
|
from scheduler import schedule_job, remove_job
|
|
from scheduler import schedule_job, remove_job
|
|
|
- dest_id = f.get("destination_id", "").strip()
|
|
|
|
|
|
|
+ transfer_target = f.get("transfer_target", "").strip()
|
|
|
job.name = name
|
|
job.name = name
|
|
|
job.type = job_type
|
|
job.type = job_type
|
|
|
job.config_json = json.dumps(cfg)
|
|
job.config_json = json.dumps(cfg)
|
|
@@ -405,7 +410,15 @@ def _save_job(job):
|
|
|
job.retention_value = int(f.get("retention_value", 7))
|
|
job.retention_value = int(f.get("retention_value", 7))
|
|
|
job.enabled = f.get("enabled") == "1"
|
|
job.enabled = f.get("enabled") == "1"
|
|
|
job.core_only = cfg.get("core_only", False)
|
|
job.core_only = cfg.get("core_only", False)
|
|
|
- job.destination_id = int(dest_id) if dest_id else None
|
|
|
|
|
|
|
+ if transfer_target.startswith("dest:"):
|
|
|
|
|
+ job.destination_id = int(transfer_target[5:])
|
|
|
|
|
+ job.remote_instance_id = None
|
|
|
|
|
+ elif transfer_target.startswith("inst:"):
|
|
|
|
|
+ job.destination_id = None
|
|
|
|
|
+ job.remote_instance_id = int(transfer_target[5:])
|
|
|
|
|
+ else:
|
|
|
|
|
+ job.destination_id = None
|
|
|
|
|
+ job.remote_instance_id = None
|
|
|
job.updated_at = datetime.utcnow()
|
|
job.updated_at = datetime.utcnow()
|
|
|
db.session.commit()
|
|
db.session.commit()
|
|
|
|
|
|