0
      0
 ?÷     # Copyright (C) 2011-2013 Red Hat, Inc.
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; If not, see <http://www.gnu.org/licenses/>.
#
# Author: tasleson

from abc import ABCMeta as _ABCMeta
from abc import abstractmethod as _abstractmethod
from lsm import LsmError, ErrorNumber
from six import with_metaclass


class IPlugin(with_metaclass(_ABCMeta, object)):
    """
    Plug-in interface that all plug-ins must implement for basic
    operation.
    """

    @_abstractmethod
    def plugin_register(self, uri, password, timeout, flags=0):
        """
        Method first called to setup the plug-in (except for plugin_info)

        This would be the place to make a connection to the array.

        Returns None on success, else LsmError exception
        """
        pass

    @_abstractmethod
    def time_out_set(self, ms, flags=0):
        """
        Sets any time-outs for the plug-in (ms)

        Returns None on success, else LsmError exception
        """
        pass

    @_abstractmethod
    def time_out_get(self, flags=0):
        """
        Retrieves the current time-out

        Returns time-out in ms, else raise LsmError
        """
        pass

    @_abstractmethod
    def plugin_unregister(self, flags=0):
        """
        Called when the client wants to finish up or the socket goes eof.
        Plug-in should clean up all resources.  Note: In the case where
        the socket goes EOF and the plugin_unregister runs into errors the
        exception(s) will not be delivered to the client!

        Returns None on success, else LsmError exception
        """
        pass

    @_abstractmethod
    def job_status(self, job_id, flags=0):
        """
        Returns the stats of the given job.

        Returns a tuple ( status (enumeration), percent_complete,
                            completed item).
        else LsmError exception.
        """
        pass

    @_abstractmethod
    def job_free(self, job_id, flags=0):
        """
        Frees resources for a given job.

        Returns None on success, else raises an LsmError
        """
        pass

    @_abstractmethod
    def capabilities(self, system, flags=0):
        """
        Returns the capabilities for the selected system, raises LsmError
        """
        pass

    @_abstractmethod
    def plugin_info(self, flags=0):
        """
        Returns the description and version for plug-in, raises LsmError

        Note: Make sure plugin can handle this call before plugin_register is
        called.
        """
        pass

    @_abstractmethod
    def pools(self, search_key=None, search_value=None, flags=0):
        """
        Returns an array of pool objects.  Pools are used in both block and
        file system interfaces, thus the reason they are in the base class.

        Raises LsmError on error
        """
        pass

    @_abstractmethod
    def systems(self, flags=0):
        """
        Returns an array of system objects.  System information is used to
        distinguish resources from on storage array to another when the plug=in
        supports the ability to have more than one array managed by it

        Raises LsmError on error
        """
        pass


class IStorageAreaNetwork(IPlugin):

    def volumes(self, search_key=None, search_value=None, flags=0):
        """
        Returns an array of volume objects

        Raises LsmError on error
        """
        raise LsmError(ErrorNumber.NO_SUPPORT, "Not supported")

    def volume_create(self, pool, volume_name, siz