Exemple #1
0
    def handle(self, request, context):
        try:
            if context['original_name'] == '':

                # for each action_id get the action object and append it
                # to context['job_actions']
                actions = actions_in_job(context.pop('actions', []))
                actions_for_job = []
                for action in actions:
                    a = freezer_api.action_get(request, action)
                    a = {
                        'action_id': a['action_id'],
                        'freezer_action': a['freezer_action']
                    }
                    actions_for_job.append(a)

                context['job_actions'] = actions_for_job

                for client in context['clients']:
                    context['client_id'] = client
                    freezer_api.job_create(request, context)
            else:
                actions = actions_in_job(context.pop('actions', []))
                actions_for_job = []

                job_id = context['original_name']
                job = freezer_api.job_get(request, job_id)

                del job[0].data_dict['job_actions']

                for action in actions:
                    a = freezer_api.action_get(request, action)
                    a = {
                        'action_id': a['action_id'],
                        'freezer_action': a['freezer_action']
                    }
                    actions_for_job.append(a)

                context['job_actions'] = actions_for_job

                return freezer_api.job_edit(request, context)
            return True
        except Exception:
            exceptions.handle(request)
            return False
Exemple #2
0
    def handle(self, request, context):
        try:
            if context["original_name"] == "":

                # for each action_id get the action object and append it
                # to context['job_actions']
                actions = actions_in_job(context.pop("actions", []))
                actions_for_job = []
                for action in actions:
                    a = freezer_api.action_get(request, action)
                    a = {"action_id": a["action_id"], "freezer_action": a["freezer_action"]}
                    actions_for_job.append(a)

                context["job_actions"] = actions_for_job

                for client in context["clients"]:
                    context["client_id"] = client
                    freezer_api.job_create(request, context)
            else:
                actions = actions_in_job(context.pop("actions", []))
                actions_for_job = []

                job_id = context["original_name"]
                job = freezer_api.job_get(request, job_id)

                del job[0].data_dict["job_actions"]

                for action in actions:
                    a = freezer_api.action_get(request, action)
                    a = {"action_id": a["action_id"], "freezer_action": a["freezer_action"]}
                    actions_for_job.append(a)

                context["job_actions"] = actions_for_job

                return freezer_api.job_edit(request, context)
            return True
        except Exception:
            exceptions.handle(request)
            return False
Exemple #3
0
    def handle(self, request, data):
        try:
            backup_id = data['backup_id']
            client_id = data['client']
            client = freezer_api.client_get(request, client_id)
            backup = freezer_api.backup_get(request, backup_id)
            name = "Restore job for {0}".format(client_id)

            # 1st step is to create a job
            restore_job = {
                "description": name,
                "client_id": client_id,
                "schedule_end_date": None,
                "schedule_interval": None,
                "schedule_start_date": None
            }
            job = freezer_api.job_create(request, restore_job)

            # 2nd step is to create an action for this job
            restore_action = {
                "original_name":
                job,  # this is the job_id
                "action":
                "restore",
                "backup_name":
                backup.data_dict[0]['backup_metadata']['backup_name'],
                "restore_abs_path":
                data['path'],
                "container":
                backup.data_dict[0]['backup_metadata']['container'],
                "restore_from_host":
                client.hostname,
                "max_retries":
                3,
                "max_retries_interval":
                60,
                "mandatory":
                False
            }
            return freezer_api.action_create(request, restore_action)
        except Exception:
            exceptions.handle(request)
            return False
Exemple #4
0
    def handle(self, request, data):
        try:
            backup_id = data['backup_id']
            client_id = data['client']
            client = freezer_api.client_get(request, client_id)
            backup = freezer_api.backup_get(request, backup_id)
            name = "Restore job for {0}".format(client_id)

            # 1st step is to create a job
            restore_job = {
                "description": name,
                "client_id": client_id,
                "schedule_end_date": None,
                "schedule_interval": None,
                "schedule_start_date": None
            }
            job = freezer_api.job_create(request, restore_job)

            # 2nd step is to create an action for this job
            restore_action = {
                "original_name": job,  # this is the job_id
                "action": "restore",
                "backup_name":
                    backup.data_dict[0]['backup_metadata']['backup_name'],
                "restore_abs_path": data['path'],
                "container":
                    backup.data_dict[0]['backup_metadata']['container'],
                "restore_from_host": client.hostname,
                "max_retries": 3,
                "max_retries_interval": 60,
                "mandatory": False
            }
            return freezer_api.action_create(request, restore_action)
        except Exception:
            exceptions.handle(request)
            return False