<filename>otcextensions/sdk/css/v1/snapshot.py
from openstack import exceptions
from openstack import resource
from openstack import utils

from otcextensions.common import format as otc_format


class Snapshot(resource.Resource):
    base_path = '/clusters/%(cluster_id)s/index_snapshots'

    resources_key = 'backups'
    resource_key = '/index_snapshot'

    allow_create = True
    allow_list = True
    allow_commit = True
    allow_delete = True
    allow_fetch = True
    allow_patch = True

    project_id = resource.Body('project_id', type=str)
    cluster_id = resource.Body('cluster_id', type=str)
    name = resource.Body('name', type=str)
    description = resource.Body('description', type=str)
    indices = resource.Body('indices', type=str)

    backups = resource.Body('backups', type=list)  # obj
    datastore = resource.Body('datastore', type=str)  # obj
    created = resource.Body('created', type=str)
    id = resource.Body('id', type=str)
    clusterId = resource.Body('clusterId', type=str)
    clusterName = resource.Body('clusterName', type=str)
    name = resource.Body('name', type=str)
    status = resource.Body('status', type=str)
    updated = resource.Body('updated', type=str)
    backupType = resource.Body('backupType', type=str)
    backupMethod = resource.Body('backupMethod', type=str)
    backupExpectedStartTime = resource.Body('backupExpectedStartTime', type=str)
    backupKeepDay = resource.Body('backupKeepDay', type=int)
    backupPeriod = resource.Body('backupPeriod', type=str)
    indices = resource.Body('indices', type=str)

    version = resource.Body('version', type=str)
    restoreStatus = resource.Body('restoreStatus', type=str)
    startTime = resource.Body('startTime', type=str)

    endTime = resource.Body('endTime', type=str)

    bucketName = resource.Body('bucketName', type=str)

    totalShards = resource.Body('totalShards', type=int)
    failedShards = resource.Body('failedShards', type=int)
    # m_type = resource.Body('type', type=str)
    version = resource.Body('version', type=str)

    @classmethod
    def list(cls, session, paginated=True, base_path=None, **params):
        """This method is a generator which yields resource objects.

        This resource object list generator handles pagination and takes query
        params for response filtering.

        :param session: The session to use for making this request.
        :type session: :class:`~keystoneauth1.adapter.Adapter`
        :param bool paginated: ``True`` if a GET to this resource returns
                               a paginated series of responses, or ``False``
                               if a GET returns only one page of data.
                               **When paginated is False only one
                               page of data will be returned regardless
                               of the API's support of pagination.**
        :param str base_path: Base part of the URI for listing resources, if
                              different from
                              :data:`~openstack.resource.Resource.base_path`.
        :param dict params: These keyword arguments are passed through the
            :meth:`~openstack.resource.QueryParamter._transpose` method
            to find if any of them match expected query parameters to be
            sent in the *params* argument to
            :meth:`~keystoneauth1.adapter.Adapter.get`. They are additionally
            checked against the
            :data:`~openstack.resource.Resource.base_path` format string
            to see if any path fragments need to be filled in by the contents
            of this argument.

        :return: A generator of :class:`Resource` objects.
        :raises: :exc:`~openstack.exceptions.MethodNotSupported` if
                 :data:`Resource.allow_list` is not set to ``True``.
        :raises: :exc:`~openstack.exceptions.InvalidResourceQuery` if query
                 contains invalid params.
        """
        if not cls.allow_list:
            raise exceptions.MethodNotSupported(cls, "list")
        session = cls._get_session(session)
        microversion = cls._get_microversion_for_list(session)

        if base_path is None:
            base_path = cls.base_path
        cls._query_mapping._validate(params, base_path=base_path)
        query_params = cls._query_mapping._transpose(params, cls)

        uri = base_path % params

        # Copy query_params due to weird mock unittest interactions
        response = session.get(
            uri,
            headers={"Accept": "application/json",
                     "Content-type": "application/json"},
            params=query_params.copy(),
            microversion=microversion)
        exceptions.raise_from_response(response)
        data = response.json()

        resources = data['backups']
        for raw_resource in resources:
            raw_resource.pop("self", None)

            value = cls.existing(
                microversion=microversion,
                connection=session._get_connection(),
                # version="1.0",
                **raw_resource)
            yield value

    @classmethod
    def list2222(cls, session, paginated=True, base_path=None, cluster_id=None, **params):
        """This method is a generator which yields resource objects.

        This resource object list generator handles pagination and takes query
        params for response filtering.

        :param session: The session to use for making this request.
        :type session: :class:`~keystoneauth1.adapter.Adapter`
        :param bool paginated: ``True`` if a GET to this resource returns
                               a paginated series of responses, or ``False``
                               if a GET returns only one page of data.
                               **When paginated is False only one
                               page of data will be returned regardless
                               of the API's support of pagination.**
        :param str base_path: Base part of the URI for listing resources, if
                              different from
                              :data:`~openstack.resource.Resource.base_path`.
        :param dict params: These keyword arguments are passed through the
            :meth:`~openstack.resource.QueryParamter._transpose` method
            to find if any of them match expected query parameters to be
            sent in the *params* argument to
            :meth:`~keystoneauth1.adapter.Adapter.get`. They are additionally
            checked against the
            :data:`~openstack.resource.Resource.base_path` format string
            to see if any path fragments need to be filled in by the contents
            of this argument.

        :return: A generator of :class:`Resource` objects.
        :raises: :exc:`~openstack.exceptions.MethodNotSupported` if
                 :data:`Resource.allow_list` is not set to ``True``.
        :raises: :exc:`~openstack.exceptions.InvalidResourceQuery` if query
                 contains invalid params.
        """
        if not cls.allow_list:
            raise exceptions.MethodNotSupported(cls, "list")
        session = cls._get_session(session)
        microversion = cls._get_microversion_for_list(session)

        if base_path is None:
            base_path = cls.base_path
        cls._query_mapping._validate(params, base_path=base_path)
        query_params = cls._query_mapping._transpose(params, cls)
        uri = base_path % params

        # Copy query_params due to weird mock unittest interactions
        response = session.get(
            uri,
            headers={"Accept": "application/json",
                     "Content-type": "application/json"},
            params=query_params.copy(),
            microversion=microversion)
        exceptions.raise_from_response(response)
        data = response.json()

        resources = data['clusters']
        for raw_resource in resources:
            raw_resource.pop("self", None)
            value = cls.existing(
                microversion=microversion,
                connection=session._get_connection(),
                # version="1.0",
                **raw_resource)
            yield value

<filename>otcextensions/sdk/css/v1/snapshot.py
from openstack import exceptions
from openstack import resource
from openstack import utils

from otcextensions.common import format as otc_format


class Snapshot(resource.Resource):
    base_path = '/clusters/%(cluster_id)s/index_snapshots'

    resources_key = 'backups'
    resource_key = '/index_snapshot'

    allow_create = True
    allow_list = True
    allow_commit = True
    allow_delete = True
    allow_fetch = True
    allow_patch = True

    project_id = resource.Body('project_id', type=str)
    cluster_id = resource.Body('cluster_id', type=str)
    name = resource.Body('name', type=str)
    description = resource.Body('description', type=str)
    indices = resource.Body('indices', type=str)

    backups = resource.Body('backups', type=list)  # obj
    datastore = resource.Body('datastore', type=str)  # obj
    created = resource.Body('created', type=str)
    id = resource.Body('id', type=str)
    clusterId = resource.Body('clusterId', type=str)
    clusterName = resource.Body('clusterName', type=str)
    name = resource.Body('name', type=str)
    status = resource.Body('status', type=str)
    updated = resource.Body('updated', type=str)
    backupType = resource.Body('backupType', type=str)
    backupMethod = resource.Body('backupMethod', type=str)
    backupExpectedStartTime = resource.Body('backupExpectedStartTime', type=str)
    backupKeepDay = resource.Body('backupKeepDay', type=int)
    backupPeriod = resource.Body('backupPeriod', type=str)
    indices = resource.Body('indices', type=str)

    version = resource.Body('version', type=str)
    restoreStatus = resource.Body('restoreStatus', type=str)
    startTime = resource.Body('startTime', type=str)

    endTime = resource.Body('endTime', type=str)

    bucketName = resource.Body('bucketName', type=str)

    totalShards = resource.Body('totalShards', type=int)
    failedShards = resource.Body('failedShards', type=int)
    # m_type = resource.Body('type', type=str)
    version = resource.Body('version', type=str)

    @classmethod
    def list(cls, session, paginated=True, base_path=None, **params):
        """This method is a generator which yields resource objects.

        This resource object list generator handles pagination and takes query
        params for response filtering.

        :param session: The session to use for making this request.
        :type session: :class:`~keystoneauth1.adapter.Adapter`
        :param bool paginated: ``True`` if a GET to this resource returns
                               a paginated series of responses, or ``False``
                               if a GET returns only one page of data.
                               **When paginated is False only one
                               page of data will be returned regardless
                               of the API's support of pagination.**
        :param str base_path: Base part of the URI for listing resources, if
                              different from
                              :data:`~openstack.resource.Resource.base_path`.
        :param dict params: These keyword arguments are passed through the
            :meth:`~openstack.resource.QueryParamter._transpose` method
            to find if any of them match expected query parameters to be
            sent in the *params* argument to
            :meth:`~keystoneauth1.adapter.Adapter.get`. They are additionally
            checked against the
            :data:`~openstack.resource.Resource.base_path` format string
            to see if any path fragments need to be filled in by the contents
            of this argument.

        :return: A generator of :class:`Resource` objects.
        :raises: :exc:`~openstack.exceptions.MethodNotSupported` if
                 :data:`Resource.allow_list` is not set to ``True``.
        :raises: :exc:`~openstack.exceptions.InvalidResourceQuery` if query
                 contains invalid params.
        """
        if not cls.allow_list:
            raise exceptions.MethodNotSupported(cls, "list")
        session = cls._get_session(session)
        microversion = cls._get_microversion_for_list(session)

        if base_path is None:
            base_path = cls.base_path
        cls._query_mapping._validate(params, base_path=base_path)
        query_params = cls._query_mapping._transpose(params, cls)

        uri = base_path % params

        # Copy query_params due to weird mock unittest interactions
        response = session.get(
            uri,
            headers={"Accept": "application/json",
                     "Content-type": "application/json"},
            params=query_params.copy(),
            microversion=microversion)
        exceptions.raise_from_response(response)
        data = response.json()

        resources = data['backups']
        for raw_resource in resources:
            raw_resource.pop("self", None)

            value = cls.existing(
                microversion=microversion,
                connection=session._get_connection(),
                # version="1.0",
                **raw_resource)
            yield value

    @classmethod
    def list2222(cls, session, paginated=True, base_path=None, cluster_id=None, **params):
        """This method is a generator which yields resource objects.

        This resource object list generator handles pagination and takes query
        params for response filtering.

        :param session: The session to use for making this request.
        :type session: :class:`~keystoneauth1.adapter.Adapter`
        :param bool paginated: ``True`` if a GET to this resource returns
                               a paginated series of responses, or ``False``
                               if a GET returns only one page of data.
                               **When paginated is False only one
                               page of data will be returned regardless
                               of the API's support of pagination.**
        :param str base_path: Base part of the URI for listing resources, if
                              different from
                              :data:`~openstack.resource.Resource.base_path`.
        :param dict params: These keyword arguments are passed through the
            :meth:`~openstack.resource.QueryParamter._transpose` method
            to find if any of them match expected query parameters to be
            sent in the *params* argument to
            :meth:`~keystoneauth1.adapter.Adapter.get`. They are additionally
            checked against the
            :data:`~openstack.resource.Resource.base_path` format string
            to see if any path fragments need to be filled in by the contents
            of this argument.

        :return: A generator of :class:`Resource` objects.
        :raises: :exc:`~openstack.exceptions.MethodNotSupported` if
                 :data:`Resource.allow_list` is not set to ``True``.
        :raises: :exc:`~openstack.exceptions.InvalidResourceQuery` if query
                 contains invalid params.
        """
        if not cls.allow_list:
            raise exceptions.MethodNotSupported(cls, "list")
        session = cls._get_session(session)
        microversion = cls._get_microversion_for_list(session)

        if base_path is None:
            base_path = cls.base_path
        cls._query_mapping._validate(params, base_path=base_path)
        query_params = cls._query_mapping._transpose(params, cls)
        uri = base_path % params

        # Copy query_params due to weird mock unittest interactions
        response = session.get(
            uri,
            headers={"Accept": "application/json",
                     "Content-type": "application/json"},
            params=query_params.copy(),
            microversion=microversion)
        exceptions.raise_from_response(response)
        data = response.json()

        resources = data['clusters']
        for raw_resource in resources:
            raw_resource.pop("self", None)
            value = cls.existing(
                microversion=microversion,
                connection=session._get_connection(),
                # version="1.0",
                **raw_resource)
            yield value

# obj # obj # m_type = resource.Body('type', type=str) This method is a generator which yields resource objects.          This resource object list generator handles pagination and takes query         params for response filtering.          :param session: The session to use for making this request.         :type session: :class:`~keystoneauth1.adapter.Adapter`         :param bool paginated: ``True`` if a GET to this resource returns                                a paginated series of responses, or ``False``                                if a GET returns only one page of data.                                **When paginated is False only one                                page of data will be returned regardless                                of the API's support of pagination.**         :param str base_path: Base part of the URI for listing resources, if                               different from                               :data:`~openstack.resource.Resource.base_path`.         :param dict params: These keyword arguments are passed through the             :meth:`~openstack.resource.QueryParamter._transpose` method             to find if any of them match expected query parameters to be             sent in the *params* argument to             :meth:`~keystoneauth1.adapter.Adapter.get`. They are additionally             checked against the             :data:`~openstack.resource.Resource.base_path` format string             to see if any path fragments need to be filled in by the contents             of this argument.          :return: A generator of :class:`Resource` objects.         :raises: :exc:`~openstack.exceptions.MethodNotSupported` if                  :data:`Resource.allow_list` is not set to ``True``.         :raises: :exc:`~openstack.exceptions.InvalidResourceQuery` if query                  contains invalid params. # Copy query_params due to weird mock unittest interactions # version="1.0", This method is a generator which yields resource objects.          This resource object list generator handles pagination and takes query         params for response filtering.          :param session: The session to use for making this request.         :type session: :class:`~keystoneauth1.adapter.Adapter`         :param bool paginated: ``True`` if a GET to this resource returns                                a paginated series of responses, or ``False``                                if a GET returns only one page of data.                                **When paginated is False only one                                page of data will be returned regardless                                of the API's support of pagination.**         :param str base_path: Base part of the URI for listing resources, if                               different from                               :data:`~openstack.resource.Resource.base_path`.         :param dict params: These keyword arguments are passed through the             :meth:`~openstack.resource.QueryParamter._transpose` method             to find if any of them match expected query parameters to be             sent in the *params* argument to             :meth:`~keystoneauth1.adapter.Adapter.get`. They are additionally             checked against the             :data:`~openstack.resource.Resource.base_path` format string             to see if any path fragments need to be filled in by the contents             of this argument.          :return: A generator of :class:`Resource` objects.         :raises: :exc:`~openstack.exceptions.MethodNotSupported` if                  :data:`Resource.allow_list` is not set to ``True``.         :raises: :exc:`~openstack.exceptions.InvalidResourceQuery` if query                  contains invalid params. # Copy query_params due to weird mock unittest interactions # version="1.0",