#
#
# =================================================================
# =================================================================

"""LogicalPartition interface."""

from paxes_cinder.k2aclient import _
from paxes_cinder.k2aclient import base
from paxes_cinder.k2aclient.v1 import k2uom
from paxes_cinder.k2aclient.v1 import k2web

from paxes_cinder.k2aclient.exceptions import K2JobFailure

from eventlet import greenthread


class LogicalPartitionManager(base.ManagerWithFind):
    """Manage :class:`LogicalPartition` resources."""
    resource_class = k2uom.LogicalPartition

    def new(self):
        return self.resource_class(self, None)

    def list(self, managedsystem, xa=None):
        """Get a list of all LogicalPartitions for a particular
        ManagedSystem accessed through a particular hmc.

        :rtype: list of :class:`LogicalPartition`.
        """
        return self._list("/rest/api/uom/ManagedSystem/%s/LogicalPartition"
                          % managedsystem,
                          xa=xa)

    def listasroot(self, xa=None):
        """Get a list of all LogicalPartitions
        accessed through a particular hmc.

        :rtype: list of :class:`LogicalPartition`.
        """
        return self._list("/rest/api/uom/LogicalPartition", xa=xa)

    def get(self, managedsystem, logicalpartition, xa=None):
        """Given managedsytem, get a specific LogicalPartition.

        :param logicalpartition: The ID of the :class:`LogicalPartition`.
        :rtype: :class:`LogicalPartition`
        """
        return self._get("/rest/api/uom/ManagedSystem/%s/LogicalPartition/%s"
                         % (managedsystem, logicalpartition,),
                         xa=xa)

    def getasroot(self, logicalpartition, xa=None):
        """Get a specific LogicalPartition.

        :param logicalpartition: The ID of the :class:`LogicalPartition`.
        :rtype: :class:`LogicalPartition`
        """
        return self._get("/rest/api/uom/LogicalPartition/%s" %
                         logicalpartition,
                         xa=xa)

    def create(self, logicalpartition, child=None, xa=None):
        """Create the specified instance
        """
        return self._create("uom", logicalpartition,
                            child=child,
                            xa=xa)

    def delete(self, logicalpartition, child=None, xa=None):
        """Delete the specified instance