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

Source Code for Module yakumo.cinder.v2.volume_backup

  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 backup on Block Storage V2 API 
 18  """ 
 19   
 20  from yakumo import base 
 21  from yakumo.constant import UNDEF 
 22  from yakumo import mapper 
 23  from . import volume_transfer 
 24   
 25   
 26  ATTRIBUTE_MAPPING = [ 
 27      ('id', 'id', mapper.Noop), 
 28      ('name', 'display_name', mapper.Noop), 
 29      ('description', 'description', mapper.Noop), 
 30      ('availability_zone', 'availability_zone', 
 31       mapper.Resource('availability_zone')), 
 32      ('source_volume', 'volume_id', mapper.Resource('cinder.volume')), 
 33      ('size', 'size', mapper.Noop), 
 34      ('object_count', 'object_count', mapper.Noop), 
 35      ('container', 'container', mapper.Noop), 
 36      ('created_at', 'created_at', mapper.DateTime), 
 37      ('updated_at', 'updated_at', mapper.DateTime), 
 38      ('status', 'status', mapper.Noop), 
 39      ('fail_reason', 'fail_reason', mapper.Noop), 
 40      ('has_dependent_backups', 'has_dependent_backups', mapper.Noop), 
 41      ('is_incremental', 'incremental', mapper.Noop), 
 42      ('is_incremental', 'is_incremental', mapper.Noop), 
 43  ] 
 44   
 45   
46 -class Resource(base.Resource):
47 """resource class for volume backups on Block Storage V2 API""" 48 49 _stable_state = ['available', 'error', 'error_deleting'] 50
51 - def restore(self, volume=None, transfer=None):
52 """ 53 Restore a volume from a volume backup 54 55 @keyword volume: Destination volume 56 @type volume: yakumo.cinder.v2.volume.Resource 57 @keyword transfer: Volume transfer 58 @type transfer: yakumo.cinder.v2.volume_transfer.Resource 59 @rtype: None 60 """ 61 transfer_name = None 62 if isinstance(transfer, volume_transfer.Resource): 63 transfer_name = transfer.name 64 self._http.post(self._url_resource_path, self._id, 'restore', 65 data=utils.get_json_body("restore", 66 volume=volume.get_id(), 67 name=transfer_name))
68
69 - def delete(self, force=False):
70 """ 71 Delete a volume backup 72 73 @keyword force: Whether the deletion is forced 74 @type force: bool 75 @rtype: None 76 """ 77 if not force: 78 super(Resource. self).delete() 79 return 80 81 self._http.post(self._url_resource_path, self._id, 'action', 82 data=utils.get_json_body("os-force_delete"))
83 84
85 -class Manager(base.Manager):
86 """manager class for volume backups on Block Storage V2 API""" 87 88 resource_class = Resource 89 service_type = 'volume' 90 _attr_mapping = ATTRIBUTE_MAPPING 91 _json_resource_key = 'backup' 92 _json_resources_key = 'backups' 93 _hidden_methods = ["update"] 94 _url_resource_list_path = '/backups/detail' 95 _url_resource_path = '/backups' 96
97 - def create(self, name=UNDEF, description=UNDEF, source_volume=UNDEF, 98 container=UNDEF, is_incremental=UNDEF):
99 """ 100 Create a backup of a volume 101 102 @keyword name: Snapshot name 103 @type name: str 104 @keyword description: Description 105 @type description: str 106 @keyword source_volume: Source volume 107 @type source_volume: yakumo.cinder.v2.volume.Resource 108 @keyword container: Container for store a volume backup 109 @type source_volume: str 110 @keyword is_incremental: Whether the backup is incremental 111 @type is_incremental: bool 112 @return: Created volume object 113 @rtype: yakumo.cinder.v2.snapshot.Resource 114 """ 115 return super(Manager, self).create(name=name, 116 description=description, 117 source_volume=source_volume, 118 container=container, 119 is_incremental=is_incremental)
120