# Path: nasman/snapshots/utils/base.py
# class BaseUtil(metaclass=abc.ABCMeta):
#     timezone_name = get_default_timezone_name()
# 
#     @classmethod
#     @abc.abstractmethod
#     def get_filesystems(cls):
#         """
#         Gets a list of filesystems
#         :return: A list of `BaseFilesystem` objects
#         :rtype: list
#         """
# 
#     @classmethod
#     @abc.abstractmethod
#     def get_snapshots(cls):
#         """
#         Gets a list of snapshots
#         :return: A list of `BaseSnapshot`
#         :rtype: list
#         """
# 
# class BaseFilesystem(metaclass=abc.ABCMeta):
# 
#     def __init__(self, name, mountpoint=''):
#         self._name = name
#         self._mountpoint = mountpoint
# 
#     @property
#     @abc.abstractmethod
#     def name(self):
#         """
#         :return: The name of the filesystem
#         :rtype: basestring
#         """
# 
#     @property
#     @abc.abstractmethod
#     def mountpoint(self):
#         """
#         :return: The mountpoint of the filesystem
#         :rtype: basestring
#         """
# 
# class BaseSnapshot(metaclass=abc.ABCMeta):
# 
#     def __init__(self, name, timestamp=None, filesystem=None):
#         self._name = name
#         self._filesystem = filesystem
#         if timestamp is not None:
#             self._timestamp = timestamp
#         else:
#             self._timestamp = now()
# 
#     @property
#     @abc.abstractmethod
#     def name(self):
#         """
#         :return: The name of the snapshot
#         :rtype: basestring
#         """
# 
#     @property
#     @abc.abstractmethod
#     def timestamp(self):
#         """
#         :return: The creation time of this snapshot
#         :rtype: `datetime.datetime`
#         """
# 
#     @property
#     @abc.abstractmethod
#     def filesystem(self):
#         """
#         :return: The parent filesystem of this snapshot
#         :rtype: `BaseFilesystem`
#         """


from datetime import datetime
from subprocess import check_output, CalledProcessError, STDOUT
from pathlib import Path
from django.core.cache import cache
from .base import BaseUtil, BaseFilesystem, BaseSnapshot
import logging
import pytz

    def mount(self):
        """
        If this file system is not already mounted, mount it using ZFS
        """
        try:
            _parse_cmd_output(
                ['zfs', 'mount', self.name]
            )
        except CalledProcessError as e:
            if 'already mounted' in str(e.output):
                return True
            raise
        return True

    def unmount(self):
        """
        If this filesystem is mounted, unmount it using ZFS
        """
        if not self.is_mounted:
            return True
        parsed = _parse_cmd_output(
            ['zfs', 'unmount', self.name]
        )
        return True

    def __repr__(self):
        return self.name



# Path: nasman/snapshots/utils/base.py
# class BaseUtil(metaclass=abc.ABCMeta):
#     timezone_name = get_default_timezone_name()
# 
#     @classmethod
#     @abc.abstractmethod
#     def get_filesystems(cls):
#         """
#         Gets a list of filesystems
#         :return: A list of `BaseFilesystem` objects
#         :rtype: list
#         """
# 
#     @classmethod
#     @abc.abstractmethod
#     def get_snapshots(cls):
#         """
#         Gets a list of snapshots
#         :return: A list of `BaseSnapshot`
#         :rtype: list
#         """
# 
# class BaseFilesystem(metaclass=abc.ABCMeta):
# 
#     def __init__(self, name, mountpoint=''):
#         self._name = name
#         self._mountpoint = mountpoint
# 
#     @property
#     @abc.abstractmethod
#     def name(self):
#         """
#         :return: The name of the filesystem
#         :rtype: basestring
#         """
# 
#     @property
#     @abc.abstractmethod
#     def mountpoint(self):
#         """
#         :return: The mountpoint of the filesystem
#         :rtype: basestring
#         """
# 
# class BaseSnapshot(metaclass=abc.ABCMeta):
# 
#     def __init__(self, name, timestamp=None, filesystem=None):
#         self._name = name
#         self._filesystem = filesystem
#         if timestamp is not None:
#             self._timestamp = timestamp
#         else:
#             self._timestamp = now()
# 
#     @property
#     @abc.abstractmethod
#     def name(self):
#         """
#         :return: The name of the snapshot
#         :rtype: basestring
#         """
# 
#     @property
#     @abc.abstractmethod
#     def timestamp(self):
#         """
#         :return: The creation time of this snapshot
#         :rtype: `datetime.datetime`
#         """
# 
#     @property
#     @abc.abstractmethod
#     def filesystem(self):
#         """
#         :return: The parent filesystem of this snapshot
#         :rtype: `BaseFilesystem`
#         """


# Path: nasman/snapshots/utils/zfs.py
from datetime import datetime
from subprocess import check_output, CalledProcessError, STDOUT
from pathlib import Path
from django.core.cache import cache
from .base import BaseUtil, BaseFilesystem, BaseSnapshot
import logging
import pytz


    def mount(self):
        """
        If this file system is not already mounted, mount it using ZFS
        """
        try:
            _parse_cmd_output(
                ['zfs', 'mount', self.name]
            )
        except CalledProcessError as e:
            if 'already mounted' in str(e.output):
                return True
            raise
        return True

    def unmount(self):
        """
        If this filesystem is mounted, unmount it using ZFS
        """
        if not self.is_mounted:
            return True
        parsed = _parse_cmd_output(
            ['zfs', 'unmount', self.name]
        )
        return True

    def __repr__(self):
        return self.name



class ZFSUtil(BaseUtil):