yakumo.cinder.v2.consistency_group

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

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

      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 consistency group 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
     25  ATTRIBUTE_MAPPING = [
     26      ('id', 'id', mapper.Noop),
     27      ('name', 'name', mapper.Noop),
     28      ('description', 'display_description', mapper.Noop),
     29      ('volume_types', 'volume__types',
     30       mapper.List(mapper.Resource('cinder.volume_type'))),
     31      ('availability_zone', 'availability_zone',
     32       mapper.Resource('availability_zone')),
     33      ('status', 'status', mapper.Noop),
     34      ('created_at', 'created_at', mapper.DateTime),
     35  ]
     36
     37
     38 -class Resource(base.Resource):
     39      """resource class for consistency group on Block Storage V2 API"""
     40
     41 -    def update(self, name=UNDEF, description=UNDEF, add=UNDEF, remove=UNDEF):
     42          """
     43          Update properties of a consistency group
     44
     45          @keyword name: Consistency group name
     46          @type name: str
     47          @keyword description: Description
     48          @type description: str
     49          @keyword add: List of volumes to add
     50          @type add: [yakumo.cinder.v2.volume.Resource]
     51          @keyword remove: List of volumes to remove
     52          @type remove: [yakumo.cinder.v2.volume.Resource]
     53          @rtype: None
     54          """
     55          super(Resource, self).update(
     56              name=name,
     57              description=description,
     58              add=add,
     59              remove=remove)
     60
     61 -    def delete(self, force=False):
     62          """
     63          Delete a consistency group
     64
     65          @keyword force: Force delete
     66          @type force: boot
     67          @rtype: None
     68          """
     69          self._http.post(self._url_resource_path, self._id, 'delete',
     70                          data=utils.get_json_body("consistencygroup",
     71                                                   force=force))
     72
     73
     74 -class Manager(base.Manager):
     75      """manager class for consistency group on Block Storage V2 API"""
     76
     77      resource_class = Resource
     78      service_type = 'volume'
     79      _attr_mapping = ATTRIBUTE_MAPPING
     80      _json_resource_key = 'consistencygroup'
     81      _json_resources_key = 'consistencygroups'
     82      _url_resource_list_path = '/consistencygroups/detail'
     83      _url_resource_path = '/consistencygroups'
     84
     85 -    def create(self, name=UNDEF, description=UNDEF, volume_types=UNDEF,
     86                 availability_zone=False):
     87          """
     88          Create a consistency group
     89
     90          @keyword name: Consistency group name
     91          @type name: str
     92          @keyword description: Description
     93          @type description: str
     94          @keyword volume_types: List of volume types
     95          @type volume_types: [yakumo.cinder.v2.volume_type.Resource]
     96          @keyword availability_zone: Availability zone
     97          @type availability_zone: yakumo.availability_zone.Resource
     98          @return: Created volume object
     99          @rtype: yakumo.cinder.v2.consistency_group.Resource
    100          """
    101          return super(Manager, self).create(
    102              name=name,
    103              description=description,
    104              volume_types=volume_types,
    105              availability_zone=availability_zone)
    106
    107 -    def copy(self, name=None, description=None, source_cg=None,
    108               source_cg_snapshot=None, project=None, user=None):
    109          """
    110          Create a consistency group from source
    111
    112          @keyword name: Consistency group name
    113          @type name: str
    114          @keyword description: Description
    115          @type description: str
    116          @keyword source_cg: Source consistency group
    117          @type source_cg: yakumo.cinder.v2.consistency_group.Resource
    118          @keyword source_cg_snapshot: Source consistency group snapshot
    119          @type source_cg_snapshot:
    120          yakumo.cinder.v2.consistency_group_snapshot.Resource
    121          @keyword project: Project
    122          @type description: yakumo.project.Resource
    123          @keyword project: User
    124          @type description: yakumo.user.Resource
    125          @return: Copied volume object
    126          @rtype: yakumo.cinder.v2.consistency_group.Resource
    127          """
    128          ret = self._http.post(self._url_resource_path, self._id,
    129                                'create_from_src',
    130                                data=utils.get_json_body(
    131                                    "consistencygroup-from-src",
    132                                    name=name,
    133                                    description=description,
    134                                    cgsnapshot_id=source_cg_snapshot.get_id(),
    135                                    source_cgid=source_cg.get_id(),
    136                                    user_id=user.get_id(),
    137                                    project_id=project.get_id(),
    138                                    status=status))
    139          attrs = self._json2attr(ret)
    140          return self.get_empty(attrs[self._id_attr])
    141