Skip to content

Commit

Permalink
Merge ee13066 into fc709cb
Browse files Browse the repository at this point in the history
  • Loading branch information
BaiHuoYu committed May 30, 2019
2 parents fc709cb + ee13066 commit f0ae3c2
Show file tree
Hide file tree
Showing 12 changed files with 1,625 additions and 8 deletions.
4 changes: 3 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017 Huawei Technologies Co., Ltd. All Rights Reserved.
// Copyright (c) 2019 The OpenSDS Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,6 +41,7 @@ type Client struct {
*VolumeMgr
*VersionMgr
*ReplicationMgr
*FileShareMgr

cfg *Config
}
Expand Down Expand Up @@ -96,6 +97,7 @@ func NewClient(c *Config) (*Client, error) {
VolumeMgr: NewVolumeMgr(r, c.Endpoint, t),
VersionMgr: NewVersionMgr(r, c.Endpoint, t),
ReplicationMgr: NewReplicationMgr(r, c.Endpoint, t),
FileShareMgr: NewFileShareMgr(r, c.Endpoint, t),
}, nil
}

Expand Down
74 changes: 73 additions & 1 deletion client/fake.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018 Huawei Technologies Co., Ltd. All Rights Reserved.
// Copyright (c) 2019 The OpenSDS Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -59,6 +59,10 @@ func NewFakeClient(config *Config) *Client {
Receiver: NewFakeVersionReceiver(),
Endpoint: config.Endpoint,
},
FileShareMgr: &FileShareMgr{
Receiver: NewFakeFileShareReceiver(),
Endpoint: config.Endpoint,
},
}
})
return fakeClient
Expand Down Expand Up @@ -368,3 +372,71 @@ func (*fakeVersionReceiver) Recv(

return nil
}

func NewFakeFileShareReceiver() Receiver {
return &fakeFileShareReceiver{}
}

type fakeFileShareReceiver struct{}

func (*fakeFileShareReceiver) Recv(
string,
method string,
in interface{},
out interface{},
) error {
switch strings.ToUpper(method) {
case "POST", "PUT":
switch out.(type) {
case *model.FileShareSpec:
if err := json.Unmarshal([]byte(ByteFileShare), out); err != nil {
return err
}
case *model.FileShareSnapshotSpec:
if err := json.Unmarshal([]byte(ByteFileShareSnapshot), out); err != nil {
return err
}
case *model.FileShareAclSpec:
if err := json.Unmarshal([]byte(ByteFileShareAcl), out); err != nil {
return err
}
default:
return errors.New("output format not supported")
}
case "GET":
switch out.(type) {
case *model.FileShareSpec:
if err := json.Unmarshal([]byte(ByteFileShare), out); err != nil {
return err
}
case *[]*model.FileShareSpec:
if err := json.Unmarshal([]byte(ByteFileShares), out); err != nil {
return err
}
case *model.FileShareSnapshotSpec:
if err := json.Unmarshal([]byte(ByteFileShareSnapshot), out); err != nil {
return err
}
case *[]*model.FileShareSnapshotSpec:
if err := json.Unmarshal([]byte(ByteFileShareSnapshots), out); err != nil {
return err
}
case *model.FileShareAclSpec:
if err := json.Unmarshal([]byte(ByteFileShareAcl), out); err != nil {
return err
}
case *[]*model.FileShareAclSpec:
if err := json.Unmarshal([]byte(ByteFileSharesAcls), out); err != nil {
return err
}
default:
return errors.New("output format not supported")
}
case "DELETE":
break
default:
return errors.New("inputed method format not supported")
}

return nil
}
261 changes: 261 additions & 0 deletions client/fileshare.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
// Copyright (c) 2019 The OpenSDS Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package client

import (
"strings"

"github.com/opensds/opensds/pkg/model"
"github.com/opensds/opensds/pkg/utils/urls"
)

// FileShareBuilder contains request body of handling a fileshare request.
// Currently it's assigned as the pointer of FileShareSpec struct, but it
// could be discussed if it's better to define an interface.
type FileShareBuilder *model.FileShareSpec

// FileShareSnapshotBuilder contains request body of handling a fileshare snapshot request.
// Currently it's assigned as the pointer of FileShareSnapshotSpec struct, but it
// could be discussed if it's better to define an interface.
type FileShareSnapshotBuilder *model.FileShareSnapshotSpec

// FileShareAclBuilder contains request body of handling a fileshare acl request.
// Currently it's assigned as the pointer of FileShareAclSpec struct, but it
// could be discussed if it's better to define an interface.
type FileShareAclBuilder *model.FileShareAclSpec

// NewFileShareMgr implementation
func NewFileShareMgr(r Receiver, edp string, tenantID string) *FileShareMgr {
return &FileShareMgr{
Receiver: r,
Endpoint: edp,
TenantID: tenantID,
}
}

// FileShareMgr implementation
type FileShareMgr struct {
Receiver
Endpoint string
TenantID string
}

// CreateFileShare implementation
func (v *FileShareMgr) CreateFileShare(body FileShareBuilder) (*model.FileShareSpec, error) {
var res model.FileShareSpec

url := strings.Join([]string{
v.Endpoint,
urls.GenerateFileShareURL(urls.Client, v.TenantID)}, "/")

if err := v.Recv(url, "POST", body, &res); err != nil {
return nil, err
}

return &res, nil
}

// DeleteFileShare implementation
func (v *FileShareMgr) DeleteFileShare(ID string) error {
url := strings.Join([]string{
v.Endpoint,
urls.GenerateFileShareURL(urls.Client, v.TenantID, ID)}, "/")

return v.Recv(url, "DELETE", nil, nil)
}

// GetFileShare implementation
func (v *FileShareMgr) GetFileShare(ID string) (*model.FileShareSpec, error) {
var res model.FileShareSpec
url := strings.Join([]string{
v.Endpoint,
urls.GenerateFileShareURL(urls.Client, v.TenantID, ID)}, "/")

if err := v.Recv(url, "GET", nil, &res); err != nil {
return nil, err
}

return &res, nil
}

// ListFileShares implementation
func (v *FileShareMgr) ListFileShares(args ...interface{}) ([]*model.FileShareSpec, error) {
url := strings.Join([]string{
v.Endpoint,
urls.GenerateFileShareURL(urls.Client, v.TenantID)}, "/")

param, err := processListParam(args)
if err != nil {
return nil, err
}

if param != "" {
url += "?" + param
}

var res []*model.FileShareSpec
if err := v.Recv(url, "GET", nil, &res); err != nil {
return nil, err
}
return res, nil
}

// UpdateFileShare implementation
func (v *FileShareMgr) UpdateFileShare(ID string, body FileShareBuilder) (*model.FileShareSpec, error) {
var res model.FileShareSpec
url := strings.Join([]string{
v.Endpoint,
urls.GenerateFileShareURL(urls.Client, v.TenantID, ID)}, "/")

if err := v.Recv(url, "PUT", body, &res); err != nil {
return nil, err
}

return &res, nil
}

// CreateFileShareSnapshot implementation
func (v *FileShareMgr) CreateFileShareSnapshot(body FileShareSnapshotBuilder) (*model.FileShareSnapshotSpec, error) {
var res model.FileShareSnapshotSpec

url := strings.Join([]string{
v.Endpoint,
urls.GenerateFileShareSnapshotURL(urls.Client, v.TenantID)}, "/")

if err := v.Recv(url, "POST", body, &res); err != nil {
return nil, err
}

return &res, nil
}

// DeleteFileShareSnapshot implementation
func (v *FileShareMgr) DeleteFileShareSnapshot(ID string) error {
url := strings.Join([]string{
v.Endpoint,
urls.GenerateFileShareSnapshotURL(urls.Client, v.TenantID, ID)}, "/")

return v.Recv(url, "DELETE", nil, nil)
}

// GetFileShareSnapshot implementation
func (v *FileShareMgr) GetFileShareSnapshot(ID string) (*model.FileShareSnapshotSpec, error) {
var res model.FileShareSnapshotSpec
url := strings.Join([]string{
v.Endpoint,
urls.GenerateFileShareSnapshotURL(urls.Client, v.TenantID, ID)}, "/")

if err := v.Recv(url, "GET", nil, &res); err != nil {
return nil, err
}

return &res, nil
}

// ListFileShareSnapshots implementation
func (v *FileShareMgr) ListFileShareSnapshots(args ...interface{}) ([]*model.FileShareSnapshotSpec, error) {
url := strings.Join([]string{
v.Endpoint,
urls.GenerateFileShareSnapshotURL(urls.Client, v.TenantID)}, "/")

param, err := processListParam(args)
if err != nil {
return nil, err
}

if param != "" {
url += "?" + param
}

var res []*model.FileShareSnapshotSpec
if err := v.Recv(url, "GET", nil, &res); err != nil {
return nil, err
}
return res, nil
}

// UpdateFileShareSnapshot implementation
func (v *FileShareMgr) UpdateFileShareSnapshot(ID string, body FileShareSnapshotBuilder) (*model.FileShareSnapshotSpec, error) {
var res model.FileShareSnapshotSpec
url := strings.Join([]string{
v.Endpoint,
urls.GenerateFileShareSnapshotURL(urls.Client, v.TenantID, ID)}, "/")

if err := v.Recv(url, "PUT", body, &res); err != nil {
return nil, err
}

return &res, nil
}

// CreateFileShareAcl implementation
func (v *FileShareMgr) CreateFileShareAcl(body FileShareAclBuilder) (*model.FileShareAclSpec, error) {
var res model.FileShareAclSpec

url := strings.Join([]string{
v.Endpoint,
urls.GenerateFileShareAclURL(urls.Client, v.TenantID)}, "/")

if err := v.Recv(url, "POST", body, &res); err != nil {
return nil, err
}

return &res, nil
}

// DeleteFileShareAcl implementation
func (v *FileShareMgr) DeleteFileShareAcl(ID string) error {
url := strings.Join([]string{
v.Endpoint,
urls.GenerateFileShareAclURL(urls.Client, v.TenantID, ID)}, "/")

return v.Recv(url, "DELETE", nil, nil)
}

// GetFileShareAcl implementation
func (v *FileShareMgr) GetFileShareAcl(ID string) (*model.FileShareAclSpec, error) {
var res model.FileShareAclSpec
url := strings.Join([]string{
v.Endpoint,
urls.GenerateFileShareAclURL(urls.Client, v.TenantID, ID)}, "/")

if err := v.Recv(url, "GET", nil, &res); err != nil {
return nil, err
}

return &res, nil
}

// ListFileSharesAcl implementation
func (v *FileShareMgr) ListFileSharesAcl(args ...interface{}) ([]*model.FileShareAclSpec, error) {
url := strings.Join([]string{
v.Endpoint,
urls.GenerateFileShareAclURL(urls.Client, v.TenantID)}, "/")

param, err := processListParam(args)
if err != nil {
return nil, err
}

if param != "" {
url += "?" + param
}

var res []*model.FileShareAclSpec
if err := v.Recv(url, "GET", nil, &res); err != nil {
return nil, err
}
return res, nil
}

0 comments on commit f0ae3c2

Please sign in to comment.