1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from openstack import exceptions
from openstack import resource
from openstack import utils
class Transfer(resource.Resource):
resource_key = "transfer"
resources_key = "transfers"
base_path = "/volume-transfers"
# capabilities
allow_create = True
allow_delete = True
allow_fetch = True
allow_list = True
allow_get = True
# Properties
#: UUID of the transfer.
id = resource.Body("id")
#: The date and time when the resource was created.
created_at = resource.Body("created_at")
#: Name of the volume to transfer.
name = resource.Body("name")
#: ID of the volume to transfer.
volume_id = resource.Body("volume_id")
#: Auth key for the transfer.
auth_key = resource.Body("auth_key")
#: A list of links associated with this volume. *Type: list*
links = resource.Body("links")
#: Whether to transfer snapshots or not
no_snapshots = resource.Body("no_snapshots")
_max_microversion = "3.55"
def create(
self,
session,
prepend_key=True,
base_path=None,
*,
resource_request_key=None,
resource_response_key=None,
microversion=None,
**params,
):
"""Create a volume transfer.
:param session: The session to use for making this request.
:type session: :class:`~keystoneauth1.adapter.Adapter`
:param prepend_key: A boolean indicating whether the resource_key
should be prepended in a resource creation request. Default to
True.
:param str base_path: Base part of the URI for creating resources, if
different from :data:`~openstack.resource.Resource.base_path`.
:param str resource_request_key: Overrides the usage of
self.resource_key when prepending a key to the request body.
Ignored if `prepend_key` is false.
:param str resource_response_key: Overrides the usage of
self.resource_key when processing response bodies.
Ignored if `prepend_key` is false.
:param str microversion: API version to override the negotiated one.
:param dict params: Additional params to pass.
:return: This :class:`Resource` instance.
:raises: :exc:`~openstack.exceptions.MethodNotSupported` if
:data:`Resource.allow_create` is not set to ``True``.
"""
# With MV 3.55 we introduced new API for volume transfer
# (/volume-transfers). Prior to that (MV < 3.55), we use
# the old API (/os-volume-transfer)
if not utils.supports_microversion(session, '3.55'):
base_path = '/os-volume-transfer'
# With MV 3.55, we also introduce the ability to transfer
# snapshot along with the volume. If MV < 3.55, we should
# not send 'no_snapshots' parameter in the request.
if 'no_snapshots' in params:
params.pop('no_snapshots')
return super().create(
session,
prepend_key=prepend_key,
base_path=base_path,
resource_request_key=resource_request_key,
resource_response_key=resource_response_key,
microversion=microversion,
**params,
)
def fetch(
self,
session,
requires_id=True,
base_path=None,
error_message=None,
skip_cache=False,
*,
resource_response_key=None,
microversion=None,
**params,
):
"""Get volume transfer.
:param session: The session to use for making this request.
:type session: :class:`~keystoneauth1.adapter.Adapter`
:param boolean requires_id: A boolean indicating whether resource ID
should be part of the requested URI.
:param str base_path: Base part of the URI for fetching resources, if
different from :data:`~openstack.resource.Resource.base_path`.
:param str error_message: An Error message to be returned if
requested object does not exist.
:param bool skip_cache: A boolean indicating whether optional API
cache should be skipped for this invocation.
:param str resource_response_key: Overrides the usage of
self.resource_key when processing the response body.
:param str microversion: API version to override the negotiated one.
:param dict params: Additional parameters that can be consumed.
:return: This :class:`Resource` instance.
:raises: :exc:`~openstack.exceptions.MethodNotSupported` if
:data:`Resource.allow_fetch` is not set to ``True``.
:raises: :exc:`~openstack.exceptions.NotFoundException` if
the resource was not found.
"""
if not utils.supports_microversion(session, '3.55'):
base_path = '/os-volume-transfer'
return super().fetch(
session,
requires_id=requires_id,
base_path=base_path,
error_message=error_message,
skip_cache=skip_cache,
resource_response_key=resource_response_key,
microversion=microversion,
**params,
)
def delete(
self, session, error_message=None, *, microversion=None, **kwargs
):
"""Delete a volume transfer.
:param session: The session to use for making this request.
:type session: :class:`~keystoneauth1.adapter.Adapter`
:param str microversion: API version to override the negotiated one.
:param dict kwargs: Parameters that will be passed to
_prepare_request()
:return: This :class:`Resource` instance.
:raises: :exc:`~openstack.exceptions.MethodNotSupported` if
:data:`Resource.allow_commit` is not set to ``True``.
:raises: :exc:`~openstack.exceptions.NotFoundException` if
the resource was not found.
"""
if not utils.supports_microversion(session, '3.55'):
kwargs['base_path'] = '/os-volume-transfer'
return super().delete(
session,
error_message=error_message,
microversion=microversion,
**kwargs,
)
def accept(self, session, *, auth_key=None):
"""Accept a volume transfer.
:param session: The session to use for making this request.
:param auth_key: The authentication key for the volume transfer.
:return: This :class:`Transfer` instance.
"""
body = {'accept': {'auth_key': auth_key}}
path = self.base_path
if not utils.supports_microversion(session, '3.55'):
path = '/os-volume-transfer'
url = utils.urljoin(path, self.id, 'accept')
microversion = self._get_microversion(session, action='commit')
resp = session.post(
url,
json=body,
microversion=microversion,
)
exceptions.raise_from_response(resp)
transfer = Transfer()
transfer._translate_response(resp)
return transfer
|