def remove(self): """Remove the LVM snapshot""" self.run_callback('preremove', self.snapshot) try: self.snapshot.refresh() total_snapshot_space = int(self.snapshot.lv_size) snap_percent_used = float(self.snapshot.snap_percent) used_snapshot_space = total_snapshot_space*(snap_percent_used/100.0) LOGGER.info("Final snapshot size %s [%.2f%% of %s]", format_bytes(used_snapshot_space), snap_percent_used, format_bytes(total_snapshot_space) ) except LVMError, exc: LOGGER.info("Failed to refresh snapshot: %s", exc)
def create_snapshot(self): """Snapshot the target LVM volume Before the snapshot is taken, a 'presnapshot' callback will be run. After the snapshot is taken, a postsnapshot callback will be run. """ LOGGER.info("Running pre-snapshot tasks") self.run_callback('presnapshot') try: self.snapshot = self.logical_volume.snapshot(self.snapshot_name, self.snapshot_size) LOGGER.info("Created snapshot /dev/%s/%s [%s] from logical volume" " /dev/%s/%s", self.snapshot.vg_name, self.snapshot.lv_name, format_bytes(int(self.snapshot.lv_size)), self.logical_volume.vg_name, self.logical_volume.lv_name) except EnvironmentError, exc: # covers LVMError,OSError, etc. # Log error # go to 'remove' state LOGGER.error("Failed to snapshot %s/%s: %s", self.logical_volume.vg_name, self.logical_volume.lv_name, exc) return self.cleanup()