yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/objectstore/ceph/provider/provider.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 provider 16 17 import ( 18 api "yunion.io/x/cloudmux/pkg/apis/compute" 19 "yunion.io/x/cloudmux/pkg/cloudprovider" 20 "yunion.io/x/cloudmux/pkg/multicloud/objectstore" 21 "yunion.io/x/cloudmux/pkg/multicloud/objectstore/ceph" 22 s3provider "yunion.io/x/cloudmux/pkg/multicloud/objectstore/provider" 23 ) 24 25 type SCephRadosProviderFactory struct { 26 s3provider.SObjectStoreProviderFactory 27 } 28 29 func (self *SCephRadosProviderFactory) GetId() string { 30 return api.CLOUD_PROVIDER_CEPH 31 } 32 33 func (self *SCephRadosProviderFactory) GetName() string { 34 return api.CLOUD_PROVIDER_CEPH 35 } 36 37 func (self *SCephRadosProviderFactory) GetProvider(cfg cloudprovider.ProviderConfig) (cloudprovider.ICloudProvider, error) { 38 client, err := ceph.NewCephRados( 39 objectstore.NewObjectStoreClientConfig( 40 cfg.URL, cfg.Account, cfg.Secret, 41 ).CloudproviderConfig(cfg), 42 ) 43 if err != nil { 44 return nil, err 45 } 46 return s3provider.NewObjectStoreProvider(self, client, []string{ 47 string(cloudprovider.ACLPrivate), 48 string(cloudprovider.ACLPublicRead), 49 string(cloudprovider.ACLPublicReadWrite), 50 }), nil 51 } 52 53 func (self *SCephRadosProviderFactory) GetClientRC(info cloudprovider.SProviderInfo) (map[string]string, error) { 54 return map[string]string{ 55 "S3_ACCESS_KEY": info.Account, 56 "S3_SECRET": info.Secret, 57 "S3_ACCESS_URL": info.Url, 58 "S3_BACKEND": api.CLOUD_PROVIDER_CEPH, 59 }, nil 60 } 61 62 func init() { 63 factory := SCephRadosProviderFactory{} 64 cloudprovider.RegisterFactory(&factory) 65 }