Пример #1
0
 def __init__(self, request, *args, **kwargs):
     super(CloneBackupJobNameAction, self).__init__(request, *args,
                                                    **kwargs)
     current_backup = get_backup_job(id=extract_object_id(request))
     if not current_backup:
         raise exceptions.NotAvailable("Object not found")
     self.fields[
         'name'].initial = constants.BACKUP_CLONE_DEFAULT_NAME_PATTERN.format(
             current_backup.name)
Пример #2
0
    def handle(self, request, context):
        current_backup_job = get_backup_job(id=extract_object_id(request))
        new_schedule_pattern = "{} {} {} {} {}".format(
            context['minute'],
            context['hour'],
            context['day'],
            context['month'],
            context['weekday'],
        )
        new_workflow_input = {
            'instance_pause': context['pause_instance'],
            'instance_stop': context['stop_instance'],
            'pattern': "{0}_backup_{1}",
            'instance': context['instance'] or None,
            'only_os': False,
            'cinder_backup': context['backup_mode'],
            'max_snapshots': context['max_snapshots'],
            'max_backups': context['max_backups'],
            'only_backup': not context['preserve_snapshot'],
            'backup_type': context['backup_type'],
            'metadata': {
                'key': context['metadata_key'],
                'value': context['metadata_value']
            } if context['metadata_key'] else None
        }

        changed_data = current_backup_job.schedule_pattern != new_schedule_pattern
        changed_data = changed_data or not workflow_are_equal(
            loads(current_backup_job.workflow_input), new_workflow_input)
        changed_data = changed_data or current_backup_job.name != context.get(
            'name')
        # if notification is not selected then it will be equal to the empty string and thus notification_value will
        # get the None value
        notification_value = context.get('notification') or None
        changed_data = changed_data or (current_backup_job.notification !=
                                        notification_value)
        if not changed_data:
            return True

        new_trigger = update_cron_trigger(
            request=self.request,
            current_backup_job=current_backup_job,
            new_name=context.get('name'),
            schedule_pattern=new_schedule_pattern,
            workflow_input=new_workflow_input)
        setattr(current_backup_job, 'cron_trigger_id', new_trigger.id)
        current_backup_job.workflow_input = dumps(new_workflow_input)
        current_backup_job.schedule_pattern = new_schedule_pattern
        current_backup_job.name = context.get('name')
        current_backup_job.notification = get_notification(
            id=context.get('notification'))
        current_backup_job.update_time = timezone.now()
        current_backup_job.save()
        return True
Пример #3
0
 def __init__(self, request, *args, **kwargs):
     super(UpdateBackupNotificationAction,
           self).__init__(request, *args, **kwargs)
     current_backup = get_backup_job(id=extract_object_id(request))
     if not current_backup:
         raise exceptions.NotAvailable("Object not found")
     self.fields['notification'].choices = [('', '')] + [
         (notif.id, notif.name) for notif in list_notifications()
     ]
     self.fields[
         'notification'].initial = current_backup.notification.id if current_backup.notification else ''
Пример #4
0
 def get_context_data(self, **kwargs):
     context = super(DetailView, self).get_context_data(**kwargs)
     backup_job = get_backup_job(id=kwargs['backup_job_id'])
     context['backup_job'] = backup_job
     context['list_url'] = reverse_lazy('horizon:custom_backup:jobs:index')
     cron_trigger_name = constants.NAME_PREFIX.format(backup_job.name)
     context['cron_trigger_name'] = cron_trigger_name
     context['cron_trigger_details_url'] = reverse(
         'horizon:mistral:cron_triggers:detail', args=[cron_trigger_name])
     context["custom_breadcrumb"] = ''
     return context
Пример #5
0
    def __init__(self, request, context, *args, **kwargs):
        super(UpdateScheduleAction, self).__init__(request, context, *args,
                                                   **kwargs)
        current_backup = get_backup_job(id=extract_object_id(request))
        if not current_backup:
            # TODO to improve
            raise exceptions.NotAvailable("Object not found")

        pattern_array = current_backup.schedule_pattern.split(' ')
        self.fields['minute'].initial = pattern_array[0]
        self.fields['hour'].initial = pattern_array[1]
        self.fields['day'].initial = pattern_array[2]
        self.fields['month'].initial = pattern_array[3]
        self.fields['weekday'].initial = pattern_array[4]
Пример #6
0
 def __init__(self, request, context, *args, **kwargs):
     super(UpdateNameAction, self).__init__(request, context, *args,
                                            **kwargs)
     current_backup = get_backup_job(id=extract_object_id(request))
     if not current_backup:
         raise exceptions.NotAvailable("Object not found")
     self.fields['name'].initial = current_backup.name
     workflow_input = loads(current_backup.workflow_input)
     self.fields['instance'].initial = workflow_input.get('instance')
     metadata = workflow_input.get('metadata')
     self.fields[
         'metadata_key'].initial = metadata['key'] if metadata else ''
     self.fields[
         'metadata_value'].initial = metadata['value'] if metadata else ''
Пример #7
0
    def handle(self, request, context):
        if not self.is_valid():
            return False

        current_backup = get_backup_job(id=extract_object_id(request))
        try:
            new_backup = create_backup_job(
                request=request,
                name=context.get('name'),
                workflow_input=loads(current_backup.workflow_input),
                schedule_pattern=current_backup.schedule_pattern,
                tenant_id=self.request.user.tenant_id,
                notification=current_backup.notification)
        except (IntegrityError, ValueError) as e:
            logger.error(e)
            return False

        return new_backup is not None
Пример #8
0
 def __init__(self, request, context, *args, **kwargs):
     super(UpdateInputAction, self).__init__(request, context, *args,
                                             **kwargs)
     current_backup = get_backup_job(id=extract_object_id(request))
     if not current_backup:
         raise exceptions.NotAvailable("Object not found")
     workflow_input = loads(current_backup.workflow_input)
     self.fields['stop_instance'].initial = workflow_input['instance_stop']
     self.fields['pause_instance'].initial = workflow_input[
         'instance_pause']
     self.fields['max_snapshots'].initial = int(
         workflow_input['max_snapshots']
     ) if workflow_input['max_snapshots'] else 0
     self.fields['max_backups'].initial = int(
         workflow_input['max_backups']
     ) if workflow_input['max_backups'] else 0
     self.fields[
         'preserve_snapshot'].initial = not workflow_input['only_backup']
     self.fields['backup_type'].initial = workflow_input['backup_type']
     self.fields['backup_mode'].initial = workflow_input['cinder_backup']