yakumo.nova.v2.volume_attachment

Package yakumo :: Package nova :: Package v2 :: Module volume_attachment |
[hide private]
[frames] | no frames]

# Source Code for Module yakumo.nova.v2.volume_attachment

     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 attachment in Compute API v2
    18  """
    19
    20  from yakumo import base
    21  from yakumo.constant import UNDEF
    22  from yakumo import mapper
    23  from yakumo import utils
    24
    25
    26  ATTRIBUTE_MAPPING = [
    27      ('id', 'id', mapper.Noop),
    28      ('device', 'device', mapper.Noop),
    29      ('server', 'serverId', mapper.Resource('nova.server')),
    30      ('volume', 'volumeId', mapper.Resource('volume')),
    31  ]
    32
    33
    34 -class Resource(base.Resource):
    35      """Resource class for volume attachment in Compute API v2"""
    36
    37 -    def detach(self):
    38          """
    39          Detach a volume
    40
    41          @rtype: None
    42          """
    43          super(Resource, self).delete()
    44
    45
    46 -class Manager(base.SubManager):
    47      """Manager class for volume attachment in Compute API v2"""
    48
    49      resource_class = Resource
    50      service_type = 'compute'
    51      _attr_mapping = ATTRIBUTE_MAPPING
    52      _hidden_methods = ["create", "update"]
    53      _json_resource_key = 'volumeAttachment'
    54      _json_resources_key = 'volumeAttachments'
    55      _url_resource_path = '/servers/%s/os-volume_attachments'
    56
    57 -    def attach(self, device=UNDEF, volume=UNDEF):
    58          """
    59          Attach a volume
    60
    61          @keyword device: device path on the guest OS (e.q. '/dev/sda')
    62          @type device: str
    63          @keyword volume: Volume (required)
    64          @type volume: yakumo.volume.Resource
    65          """
    66          return super(Manager, self).create(device=device,
    67                                             volume=volume)
    68