yakumo.cinder.v2.volume_type

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

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

      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 types on Block Storage V2 API
     18  """
     19
     20  import copy
     21
     22  from yakumo import base
     23  from yakumo.constant import UNDEF
     24  from yakumo import mapper
     25  from yakumo import utils
     26
     27
     28  ATTRIBUTE_MAPPING = [
     29      ('id', 'id', mapper.Noop),
     30      ('name', 'name', mapper.Noop),
     31      ('description', 'description', mapper.Noop),
     32      ('metadata', 'extra_specs', mapper.Noop),
     33      ('is_public', 'is_public', mapper.Noop),
     34  ]
     35
     36
     37 -class Resource(base.Resource):
     38      """resource class for volume types on Block Storage V2 API"""
     39
     40 -    def set_metadata(self, **kwargs):
     41          """
     42          Remove metadata
     43
     44          **kwargs: key=value style metadata
     45          @rtype: None
     46          """
     47          self._http.post(self._url_resource_path, self._id, 'extra_specs',
     48                          data=utils.get_json_body("extra_specs", **kwargs))
     49          self.reload()
     50
     51 -    def unset_metadata(self, *keys):
     52          """
     53          Remove metadata
     54
     55          *keys: keys of metadata to remove
     56          @rtype: None
     57          """
     58          for key in keys:
     59              self._http.delete(self._url_resource_path, self._id,
     60                                'extra_specs', key)
     61          self.reload()
     62
     63 -    def add_project(self, project=None):
     64          """
     65          Add private volume type access
     66
     67          @keyword project: Project
     68          @type project: yakumo.project.Resource
     69          @rtype: None
     70          """
     71          self._http.post(self._url_resource_path, self._id, 'action',
     72                          data=utils.get_json_body("addProjectAccess",
     73                                                   project=project.get_id()))
     74
     75 -    def remove_project(self, project=None):
     76          """
     77          Remove private volume type access
     78
     79          @keyword project: Project
     80          @type project: yakumo.project.Resource
     81          @rtype: None
     82          """
     83          self._http.post(self._url_resource_path, self._id, 'action',
     84                          data=utils.get_json_body("removeProjectAccess",
     85                                                   project=project.get_id()))
     86
     87
     88 -class Manager(base.Manager):
     89      """manager class for volume types on Block Storage V2 API"""
     90
     91      resource_class = Resource
     92      service_type = 'volume'
     93      _attr_mapping = ATTRIBUTE_MAPPING
     94      _json_resource_key = 'volume_type'
     95      _json_resources_key = 'volume_types'
     96      _url_resource_list_path = '/types'
     97      _url_resource_path = '/types'
     98
     99 -    def create(self, name=UNDEF, description=UNDEF, metadata=UNDEF,
    100                 is_public=UNDEF):
    101          """
    102          Register a volume type
    103
    104          @keyword name: Volume type name
    105          @type name: str
    106          @keyword description: Description
    107          @type description: str
    108          @keyword metadata: Metadata (key=value)
    109          @type metadata: dict
    110          @keyword is_public: Whether volume type is public
    111          @type is_public: bool
    112          @return: Created volume type
    113          @rtype: yakumo.cinder.v2.volume_type.Resource
    114          """
    115          return super(Manager, self).create(name=name,
    116                                             description=description,
    117                                             metadata=metadata,
    118                                             is_public=is_public)
    119