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

Source Code for Module yakumo.cinder.v2.quota_set

  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 Quota sets in Block Storage 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      ('volumes', 'volumes', mapper.Noop), 
 29      ('per_volume_gigabytes', 'per_volume_gigabytes', mapper.Noop), 
 30      ('snapshots', 'snapshots', mapper.Noop), 
 31      ('gigabytes', 'gigabytes', mapper.Noop), 
 32      ('backups', 'backups', mapper.Noop), 
 33      ('backup_gigabytes', 'backup_gigabytes', mapper.Noop), 
 34  ] 
 35   
 36   
37 -class Resource(base.Resource):
38 """Resource class for Quota sets in Block Storage API v2"""
39 40
41 -class Manager(base.Manager):
42 """Manager class for Quota sets in Block Storage API v2""" 43 44 resource_class = Resource 45 service_type = 'volume' 46 _attr_mapping = ATTRIBUTE_MAPPING 47 _hidden_methods = ["create"] 48 _json_resource_key = 'quota_set' 49 _url_resource_path = '/os-quota-sets' 50
51 - def get(self, project=None, user=None):
52 """ 53 Get quota set for a project 54 55 @keyword project: Project (required) 56 @type project: yakumo.project.Resource 57 @keyword user: User 58 @type user: yakumo.user.Resource 59 @rtype: yakumo.cinder.v2.quota_set.Resource 60 """ 61 if project is None: 62 project = self._project 63 params = {} 64 if user: 65 params = dict(user_id=user.get_id()) 66 try: 67 ret = self._http.get(self._url_resource_path, project._id, 68 params=params) 69 json_params = ret.get(self._json_resource_key) 70 attrs = self._json2attr(json_params) 71 return self.resource_class(self, **attrs) 72 except: 73 return None
74
75 - def update(self, project=UNDEF, user=UNDEF, volumes=UNDEF, 76 per_volume_gigabytes=UNDEF, snapshots=UNDEF, gigabytes=UNDEF, 77 backups=UNDEF, backup_gigabytes=UNDEF):
78 """ 79 Update quota set for a project 80 81 @keyword project: Project object (required) 82 @type project: yakumo.project.Resource 83 @keyword user: User object 84 @type user: yakumo.user.Resource 85 @keyword volumes: Max number of volumes 86 @type volumes: int 87 @keyword per_volume_gigabytes: Max size of a volume in GB 88 @type per_volume_gigabytes: int 89 @keyword snapshots: Max number of snapshots 90 @type snapshots: int 91 @keyword gigabytes: Max total size of volumes in GB 92 @type gigabytes:int 93 @keyword backups: Max number of volume backups 94 @type backups: int 95 @keyword backup_gigabytes: max total size of volume backup in GB 96 @type backup_gigabytes: int 97 @rtype: None 98 """ 99 if project is None: 100 project = self._project 101 params = {} 102 if user: 103 params = dict(user_id=user._id) 104 kwargs = dict(volumes=volumes, 105 per_volume_gigabytes=per_volume_gigabytes, 106 snapshots=snapshots, 107 gigabytes=gigabytes, 108 backups=backups, 109 backup_gigabytes=backup_gigabytes) 110 json_params = self._attr2json(kwargs) 111 self._http.put(self._url_resource_path, project._id, 112 params=params, 113 data=utils.get_json_body(self._json_resource_key, 114 **json_params))
115
116 - def delete(self, project=None, user=None):
117 """ 118 Delete quota set for a project 119 120 @keyword project: Project 121 @type project: yakumo.project.Resource 122 @keyword user: User 123 @type user: yakumo.user.Resource 124 @rtype: None 125 """ 126 if project is None: 127 project = self._project 128 params = {} 129 if user: 130 params = dict(user_id=user._id) 131 self._http.delete(self._url_resource_path, project._id, 132 params=params)
133
134 - def get_default(self, project=None):
135 """ 136 Get default quota set for a project 137 138 @keyword project: Project 139 @type project: yakumo.project.Resource 140 @return: Default quota set 141 @rtype: yakumo.cinder.v2.quota_set.Resource 142 """ 143 if project is None: 144 project = self._project 145 try: 146 ret = self._http.get(self._url_resource_path, project._id) 147 json_params = ret.get(self._json_resource_key) 148 attrs = self._json2attr(json_params) 149 return self.resource_class(self, **attrs) 150 except: 151 return None
152