def post(self): self._check_vm_status() apiview, detail = self._get_apiview_detail() request, vm, snap = self.request, self.vm, self.snap snap.status = snap.PENDING snap.define_id = self.snap_define_id snap.type = self.snaptype ser = SnapshotSerializer(request, snap, data=self.data) fsfreeze = '' if not ser.is_valid(): return FailureTaskResponse(request, ser.errors, vm=vm) if vm.is_hvm() and self.data.get('fsfreeze', False): qga_socket = vm.qga_socket_path if qga_socket: snap.fsfreeze = True if vm.status != vm.STOPPED: fsfreeze = '"%s"' % qga_socket self._check_snap_limit() self._check_snap_size_limit() # Issue #chili-848 self._check_snap_dc_size_limit() # Issue #chili-848 snap.zpool = vm.node.nodestorage_set.get(zpool=self.zpool) snap.save() detail += ', type=%s, fsfreeze=%s' % (self.snaptype, str( snap.fsfreeze).lower()) msg = LOG_SNAP_CREATE lock = self.LOCK % (vm.uuid, snap.disk_id) cmd = 'esnapshot create "%s@%s" "es:snapname=%s" %s 2>&1' % ( self.zfs_filesystem, snap.zfs_name, snap.name, fsfreeze) tid, err = execute(request, vm.owner.id, cmd, meta=snap_meta(vm, msg, apiview, detail), lock=lock, callback=snap_callback(vm, snap), queue=vm.node.fast_queue, tt=self.tt) if err: snap.delete() return FailureTaskResponse(request, err, vm=vm) else: return TaskResponse(request, tid, msg=msg, vm=vm, api_view=apiview, detail=detail, data=self.data)
def _update_note(self): # Changing snapshot note instead of rollback (not logging) request = self.request ser = SnapshotSerializer(request, self.snap, data=self.data, partial=True) if ser.is_valid(): ser.object.save() return SuccessTaskResponse(request, ser.data, vm=self.vm) else: return FailureTaskResponse(request, ser.errors, vm=self.vm)
def get(self): request, data, vm = self.request, self.data, self.vm # Prepare filter dict snap_filter = {'vm': vm} filter_disk_id(vm, snap_filter, data) filter_snap_type(snap_filter, data) filter_snap_define(snap_filter, data) # TODO: check indexes snapqs = Snapshot.objects.select_related('vm', 'define').filter(**snap_filter).order_by(*self.order_by) if self.full or self.extended: if snapqs: res = SnapshotSerializer(request, snapqs, many=True).data else: res = [] else: res = list(snapqs.values_list('name', flat=True)) return SuccessTaskResponse(request, res, vm=vm)
def delete(self): self._check_vm_status() self._check_snap_status(lost_ok=True) request, vm, snap = self.request, self.vm, self.snap apiview, detail = self._get_apiview_detail() msg = LOG_SNAP_DELETE if snap.status == Snapshot.LOST: snap.delete() res = {'message': 'Snapshot successfully deleted from DB'} return SuccessTaskResponse(request, res, msg=msg, vm=vm, detail=detail) SnapshotSerializer(request, snap) lock = self.LOCK % (vm.uuid, snap.disk_id) cmd = 'esnapshot destroy "%s@%s" 2>&1' % (self.zfs_filesystem, snap.zfs_name) tid, err = execute(request, vm.owner.id, cmd, meta=snap_meta(vm, msg, apiview, detail), lock=lock, callback=snap_callback(vm, snap), queue=vm.node.fast_queue, tt=self.tt) if err: return FailureTaskResponse(request, err, vm=vm) else: snap.save_status(snap.PENDING) return TaskResponse(request, tid, msg=msg, vm=vm, api_view=apiview, detail=detail, data=self.data)
def get(self): ser = SnapshotSerializer(self.request, self.snap) return SuccessTaskResponse(self.request, ser.data, vm=self.vm)