Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions zol.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ def _execute(self, *cmd, **kwargs):
command = ' '.join(cmd)
return self._run_ssh(command, check_exit_code)

def create_snapshot(self, snapshot):
"""Creates a snapshot."""
zfs_poolname = self._build_zfs_poolname(snapshot['volume_name'])
snap_path = "%s@%s" % (zfs_poolname, snapshot['name'])
self._execute(self.ZFSCMD, 'snapshot', snap_path,
run_as_root=True)

def delete_snapshot(self, snapshot):
"""Deletes a snapshot."""
zfs_poolname = self._build_zfs_poolname(snapshot['volume_name'])
snap_path = "%s@%s" % (zfs_poolname, snapshot['name'])
if self._volume_not_present(snapshot['volume_name']):
# If the snapshot isn't present, then don't attempt to delete
LOG.debug("SNAPSHOT NOT FOUND %s",(snap_path))
return True
self._execute(self.ZFSCMD, 'destroy', snap_path,
run_as_root=True)

def _create_volume(self, volume_name, sizestr):
zfs_poolname = self._build_zfs_poolname(volume_name)

Expand All @@ -113,6 +131,8 @@ def _create_volume(self, volume_name, sizestr):

def _volume_not_present(self, volume_name):
zfs_poolname = self._build_zfs_poolname(volume_name)
LOG.debug("ZFS_POOLNAME (%s)" % (zfs_poolname))

try:
out, err = self._execute(self.ZFSCMD, 'list', '-H',
zfs_poolname, run_as_root=True)
Expand All @@ -135,6 +155,7 @@ def delete_volume(self, volume):
"""Deletes a volume."""
if self._volume_not_present(volume['name']):
# If the volume isn't present, then don't attempt to delete
LOG.debug("VOLUME NOT FOUND (%s)" % (volume['name']))
return True
zfs_poolname = self._build_zfs_poolname(volume['name'])
self._execute(self.ZFSCMD, 'destroy', zfs_poolname, run_as_root=True)
Expand Down