yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/objectstore/ceph/bucket.go (about) 1 // Copyright 2019 Yunion 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package ceph 16 17 import ( 18 "context" 19 "strconv" 20 21 "yunion.io/x/cloudmux/pkg/cloudprovider" 22 "yunion.io/x/onecloud/pkg/httperrors" 23 "yunion.io/x/cloudmux/pkg/multicloud/objectstore" 24 ) 25 26 type SCephRadosBucket struct { 27 *objectstore.SBucket 28 } 29 30 func (b *SCephRadosBucket) GetStats() cloudprovider.SBucketStats { 31 _, hdr, _ := b.GetIBucketProvider().S3Client().BucketExists(b.Name) 32 if hdr != nil { 33 sizeBytesStr := hdr.Get("X-Rgw-Bytes-Used") 34 sizeBytes, _ := strconv.ParseInt(sizeBytesStr, 10, 64) 35 objCntStr := hdr.Get("X-Rgw-Object-Count") 36 objCnt, _ := strconv.ParseInt(objCntStr, 10, 64) 37 return cloudprovider.SBucketStats{ 38 SizeBytes: sizeBytes, 39 ObjectCount: int(objCnt), 40 } 41 } 42 return b.SBucket.GetStats() 43 } 44 45 func (b *SCephRadosBucket) GetLimit() cloudprovider.SBucketStats { 46 if cephCli, ok := b.GetIBucketProvider().(*SCephRadosClient); ok { 47 quota, err := cephCli.adminApi.GetBucketQuota(context.Background(), cephCli.GetAccountId(), b.Name) 48 if err == nil { 49 limit := cloudprovider.SBucketStats{} 50 if quota.Enabled.IsTrue() { 51 limit.SizeBytes = quota.MaxSize 52 limit.ObjectCount = quota.MaxObjects 53 } 54 return limit 55 } 56 } 57 return b.SBucket.GetLimit() 58 } 59 60 func (b *SCephRadosBucket) SetLimit(limit cloudprovider.SBucketStats) error { 61 /*if cephCli, ok := b.GetIBucketProvider().(*SCephRadosClient); ok { 62 err := cephCli.adminApi.SetBucketQuota(context.Background(), cephCli.GetAccountId(), b.Name, limit.SizeBytes, limit.ObjectCount) 63 return errors.Wrap(err, "cephCli.adminApi.SetBucketQuota") 64 } 65 return b.SBucket.SetLimit(limit)*/ 66 return httperrors.ErrNotSupported 67 }