Package yakumo :: Package swift :: Package v1 :: Module container
[hide private]
[frames] | no frames]

Source Code for Module yakumo.swift.v1.container

  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 containers on Object Storage V1 API 
 18  """ 
 19   
 20  from yakumo import base 
 21  from yakumo.constant import UNDEF 
 22  from . import file_object 
 23  from yakumo import mapper 
 24  from yakumo import utils 
 25   
 26   
 27  ATTRIBUTE_MAPPING = [ 
 28      ('name', 'name', mapper.Noop), 
 29      ('object_count', 'x-container-object-count', mapper.IntStr), 
 30      ('used_bytes', 'x-container-bytes-used', mapper.IntStr), 
 31      ('temp_url_key', 'x-container-meta-temp-url-key', mapper.Noop), 
 32      ('temp_url_key2', 'x-container-meta-temp-url-key-2', mapper.Noop), 
 33      ('quota_count', 'x-container-meta-quota-count', mapper.IntStr), 
 34      ('quota_bytes', 'x-container-meta-quota-bytes', mapper.IntStr), 
 35      ('storage_policy', 'x-storage-policy', mapper.Noop), 
 36      ('read_acl', 'x-container-read', mapper.Noop), 
 37      ('write_acl', 'x-container-write', mapper.Noop), 
 38      ('acl_allow_origin', 'x-container-meta-access-control-allow-origin', 
 39       mapper.Noop), 
 40      ('acl_max_age', 'x-container-meta-access-control-max-age', mapper.IntStr), 
 41      ('acl_expose_headers', 'x-container-meta-access-control-expose-headers', 
 42       mapper.Noop), 
 43      ('sync_key', 'x-container-sync-key', mapper.Noop), 
 44      ('sync_to', 'x-container-sync-to', mapper.Noop), 
 45      ('versions', 'x-versions-location', mapper.Noop), 
 46      ('history', 'x-history-location', mapper.Noop), 
 47      ('timestamp', 'x-timestamp', mapper.FloatStr), 
 48      ('trans_id', 'x-trans-id', mapper.Noop), 
 49      ('trans_id_extra', 'x-trans-id-extra', mapper.Noop), 
 50      ('metadata', 'metadata', mapper.Noop), 
 51  ] 
 52   
 53   
54 -class Resource(base.SwiftV1Resource):
55 """resource class for containers on Object Storage V1 API""" 56 57 _sub_manager_list = { 58 'object': file_object.Manager 59 } 60
61 - def update(self, read_acl=UNDEF, write_acl=UNDEF, 62 sync_to=UNDEF, sync_key=UNDEF, 63 versions_location=UNDEF, history_location=UNDEF, 64 ac_allow_origin=UNDEF, ac_max_age=UNDEF, 65 quota_bytes=UNDEF, quota_count=UNDEF, 66 temp_url_key=UNDEF, temp_url_key2=UNDEF, 67 trans_id_extra=UNDEF, storage_policy=UNDEF):
68 """ 69 Update a container 70 71 @keyword read_acl: The ACL that grants read access 72 @type read_acl: str 73 @keyword write_acl: The ACL that grants write access 74 @type write_acl: str 75 @keyword sync_to: The destination for container synchronization 76 @type sync_to: str 77 @keyword sync_key: The secret key for container synchronization 78 @type sync_key: str 79 @keyword versions_location: The URL-encoded UTF-8 representation of 80 the container that stores previous versions of objects 81 @type versions_location: str 82 @keyword history_location: The URL-encoded UTF-8 representation of 83 the container that stores previous versions of objects 84 @type history_location: str 85 @keyword ac_allow_origin: Originating URLs allowed to make cross-origin 86 requests (CORS), separated by spaces. 87 @type ac_allow_origin: str 88 @keyword ac_max_age: Maximum time for the origin to hold the preflight 89 results 90 @type ac_max_age: 91 @keyword quota_bytes: The maximum size of the container, in bytes 92 @type quota_bytes: int 93 @keyword quota_count: The maximum object count of the container 94 @type qouta_count: int 95 @keyword temp_url_key: The secret key value for temporary URLs 96 @type temp_url_key: str 97 @keyword temp_url_key2: The 2nd secret key value for temporary URLs 98 @type temp_url_key2: str 99 @keyword trans_id_extra: Extra transaction information 100 @type trans_id_extra: str 101 @keyword storage_policy: Name of the storage policy 102 @type storage_policy: str 103 @return: Created container 104 @rtype: yakumo.swift.v1.container.Resource 105 """ 106 super(Resource, self).update( 107 read_acl=read_acl, 108 write_acl=write_acl, 109 sync_to=sync_to, 110 sync_key=sync_key, 111 versions_location=versions_location, 112 history_location=history_location, 113 ac_allow_origin=ac_allow_origin, 114 ac_max_age=ac_max_age, 115 quota_bytes=quota_bytes, 116 quota_count=quota_count, 117 temp_url_key=temp_url_key, 118 temp_url_key2=temp_url_key2, 119 trans_id_extra=trans_id_extra, 120 storage_policy=storage_policy)
121
122 - def set_metadata(self, **metadata):
123 """ 124 Update metadata of a volume 125 126 @keyword metadata: Key=value style metadata 127 @type metadata: dict 128 @rtype: None 129 """ 130 headers = {} 131 for key, value in metadata.items(): 132 x_key = "x-container-meta-" + key 133 headers[x_key] = str(value) 134 self._http.post_raw(self._url_resource_path, self._id, headers=headers) 135 self.reload()
136
137 - def unset_metadata(self, *keys):
138 """ 139 Delete metadata of a volume 140 141 @param key: Key of the metadata 142 @type keys: [str] 143 @rtype: None 144 """ 145 headers = {} 146 for key in keys: 147 x_key = "x-remove-container-meta-" + key 148 headers[x_key] = "x" 149 self._http.post_raw(self._url_resource_path, self._id, headers=headers) 150 self.reload()
151 152
153 -class Manager(base.SwiftV1Manager):
154 """manager class for containers on Object Storage V1 API""" 155 156 resource_class = Resource 157 service_type = 'object-store' 158 _attr_mapping = ATTRIBUTE_MAPPING 159 _has_detail = False 160 _url_resource_path = None 161 _json_resource_key = 'container' 162
163 - def create(self, name, read_acl=UNDEF, write_acl=UNDEF, 164 sync_to=UNDEF, sync_key=UNDEF, 165 versions_location=UNDEF, history_location=UNDEF, 166 ac_allow_origin=UNDEF, ac_max_age=UNDEF, 167 quota_bytes=UNDEF, quota_count=UNDEF, 168 temp_url_key=UNDEF, temp_url_key2=UNDEF, 169 trans_id_extra=UNDEF, storage_policy=UNDEF, metadata=UNDEF):
170 """ 171 Create a volume 172 173 @param name: Container name 174 @type name: str 175 @keyword read_acl: The ACL that grants read access 176 @type read_acl: str 177 @keyword write_acl: The ACL that grants write access 178 @type write_acl: str 179 @keyword sync_to: The destination for container synchronization 180 @type sync_to: str 181 @keyword sync_key: The secret key for container synchronization 182 @type sync_key: str 183 @keyword versions_location: The URL-encoded UTF-8 representation 184 @type history_location: str 185 @keyword ac_allow_origin: Originating URLs allowed to make cross-origin 186 requests (CORS), separated by spaces. 187 @type ac_allow_origin: int 188 @keyword ac_max_age: Maximum time for the origin to hold the preflight 189 results 190 @type ac_max_age: int 191 @keyword quota_bytes: The maximum size of the container, in bytes 192 @type quota_bytes: int 193 @keyword quota_count: The maximum object count of the container 194 @type qouta_count: int 195 @keyword temp_url_key: The secret key value for temporary URLs 196 @type temp_url_key: str 197 @keyword temp_url_key2: The 2nd secret key value for temporary URLs 198 @type temp_url_key2: str 199 @keyword trans_id_extra: Extra transaction information 200 @type trans_id_extra: str 201 @keyword storage_policy: Name of the storage policy 202 @type storage_policy: str 203 @keyword metadata: Key-value style metadata 204 @type metadata: dict 205 @return: Created container 206 @rtype: yakumo.swift.v1.container.Resource 207 """ 208 return super(Manager, self).create( 209 name, 210 read_acl=read_acl, 211 write_acl=write_acl, 212 sync_to=sync_to, 213 sync_key=sync_key, 214 versions_location=versions_location, 215 history_location=history_location, 216 ac_allow_origin=ac_allow_origin, 217 ac_max_age=ac_max_age, 218 quota_bytes=quota_bytes, 219 quota_count=quota_count, 220 temp_url_key=temp_url_key, 221 temp_url_key2=temp_url_key2, 222 trans_id_extra=trans_id_extra, 223 storage_policy=storage_policy, 224 metadata=metadata)
225