yakumo.cinder.v2.volume_transfer

Package yakumo :: Package cinder :: Package v2 :: Module volume_transfer |
[hide private]
[frames] | no frames]

# Source Code for Module yakumo.cinder.v2.volume_transfer

     1  # Copyright 2014-2017 by Akira Yoshiyama <akirayoshiyama@gmail.com>.
     2  # All Rights Reserved.
     3  #
     4  #    Licensed under the Apache License, Version 2.0 (the "License"); you may
     5  #    not use this file except in compliance with the License. You may obtain
     6  #    a copy of the License at
     7  #
     8  #         http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  #    Unless required by applicable law or agreed to in writing, software
    11  #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    12  #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    13  #    License for the specific language governing permissions and limitations
    14  #    under the License.
    15
    16  """
    17  Resource class and its manager for volume transfer on Block Storage V2 API
    18  """
    19
    20  from yakumo import base
    21  from yakumo.constant import UNDEF
    22  from yakumo import mapper
    23
    24  from . import volume
    25
    26
    27  ATTRIBUTE_MAPPING = [
    28      ('id', 'id', mapper.Noop),
    29      ('name', 'name', mapper.Noop),
    30      ('auth_key', 'auth_key', mapper.Noop),
    31      ('volume', 'volume_id', mapper.Resource('cinder.volume')),
    32      ('created_at', 'created_at', mapper.DateTime),
    33  ]
    34
    35
    36 -class Resource(base.Resource):
    37      """resource class for volume transfer on Block Storage V2 API"""
    38
    39 -    def accept(self, auth_key):
    40          """
    41          Accept a volume transfer
    42
    43          @keyword auth_key: authentication key for a transfer
    44          @type auth_key: str
    45          @return: Accepted volume
    46          @rtype: yakumo.cinder.v2.volume.Resource
    47          """
    48          ret = self._http.post(self._url_resource_path, self._id, 'accept',
    49                                data=utils.get_json_body("accept",
    50                                                         auth_key=auth_key))
    51          volume_id = ret['volume_id']
    52          return self._client.cinder.volume.get_empty(volume_id)
    53
    54
    55 -class Manager(base.Manager):
    56      """manager class for volume transfer on Block Storage V2 API"""
    57
    58      resource_class = Resource
    59      service_type = 'volume'
    60      _attr_mapping = ATTRIBUTE_MAPPING
    61      _json_resource_key = 'transfer'
    62      _json_resources_key = 'transfers'
    63      _hidden_methods = ["update"]
    64      _url_resource_list_path = '/os-volume-transfer/detail'
    65      _url_resource_path = '/os-volume-transfer'
    66
    67 -    def create(self, name=UNDEF, volume=UNDEF):
    68          """
    69          Create a volume transfer
    70
    71          @keyword name: Volume transfer name (optional)
    72          @type name: str
    73          @keyword volume: Volume to send
    74          @type volume: yakumo.cinder.v2.volume.Resource
    75          @return: Created volume transfer
    76          @rtype: yakumo.cinder.v2.volume_transfer.Resource
    77          """
    78          return super(Manager, self).create(name=name, volume=volume)
    79