def __init__(self, request, context, *args, **kwargs): super(UpdateNotificationAction, self).__init__(request, context, *args, **kwargs) current_notification = get_notification(id=extract_object_id(request)) for field_name, field in self.fields.items(): field.required = False if hasattr(current_notification, field_name): field.initial = getattr(current_notification, field_name)
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)
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
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 ''
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]
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 ''
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
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']
def get_object(self): return get_notification(id=extract_object_id(self.request))
def current_object_id(self): return extract_object_id(self.request)