Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the latest code #2

Merged
merged 3 commits into from
Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions install/devsds/lib/opensds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ osds::opensds::install(){

export OPENSDS_AUTH_STRATEGY=$OPENSDS_AUTH_STRATEGY
export OPENSDS_ENDPOINT=http://localhost:50040
build/out/bin/osdsctl profile create '{"name": "default", "description": "default policy", "storageType": "block"}'
build/out/bin/osdsctl profile create '{"name": "default", "description": "default policy", "storageType": "file", "provisioningProperties":{"ioConnectivity": {"accessProtocol": "NFS"},"DataStorage":{"StorageAccessCapability":["Read","Write","Execute"]}}}'
build/out/bin/osdsctl profile create '{"name": "default_block", "description": "default policy", "storageType": "block"}'
build/out/bin/osdsctl profile create '{"name": "default_file", "description": "default policy", "storageType": "file", "provisioningProperties":{"ioConnectivity": {"accessProtocol": "NFS"},"DataStorage":{"StorageAccessCapability":["Read","Write","Execute"]}}}'

if [ $? == 0 ]; then
osds::echo_summary devsds installed successfully !!
Expand Down
38 changes: 29 additions & 9 deletions pkg/db/drivers/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ import (
)

const (
defaultLimit = 50
defaultOffset = 0
defaultSortDir = "desc"
defaultSortKey = "ID"
defaultLimit = 50
defaultOffset = 0
defaultSortDir = "desc"
defaultSortKey = "ID"
defaultBlockProfileName = "default_block"
defaultFileProfileName = "default_file"
typeBlock = "block"
typeFile = "file"
)

var validKey = []string{"limit", "offset", "sortDir", "sortKey"}
Expand Down Expand Up @@ -1434,8 +1438,8 @@ func (c *Client) CreateProfile(ctx *c.Context, prf *model.ProfileSpec) (*model.P
prf.CreatedAt = time.Now().Format(constants.TimeFormat)
}

// profile name must be unique with the same storage type.
if _, err := c.getProfileByName(ctx, prf.Name, prf.StorageType); err == nil {
// profile name must be unique.
if _, err := c.getProfileByName(ctx, prf.Name); err == nil {
return nil, fmt.Errorf("the profile name '%s' already exists", prf.Name)
}

Expand Down Expand Up @@ -1476,7 +1480,23 @@ func (c *Client) GetProfile(ctx *c.Context, prfID string) (*model.ProfileSpec, e
return prf, nil
}

func (c *Client) getProfileByName(ctx *c.Context, name, storageType string) (*model.ProfileSpec, error) {
func (c *Client) getProfileByName(ctx *c.Context, name string) (*model.ProfileSpec, error) {
profiles, err := c.ListProfiles(ctx)
if err != nil {
log.Error("List profile failed: ", err)
return nil, err
}

for _, profile := range profiles {
if profile.Name == name {
return profile, nil
}
}
var msg = fmt.Sprintf("can't find profile(name: %s)", name)
return nil, model.NewNotFoundError(msg)
}

func (c *Client) getProfileByNameAndType(ctx *c.Context, name, storageType string) (*model.ProfileSpec, error) {
profiles, err := c.ListProfiles(ctx)
if err != nil {
log.Error("List profile failed: ", err)
Expand All @@ -1494,12 +1514,12 @@ func (c *Client) getProfileByName(ctx *c.Context, name, storageType string) (*mo

// GetDefaultProfile
func (c *Client) GetDefaultProfile(ctx *c.Context) (*model.ProfileSpec, error) {
return c.getProfileByName(ctx, "default", "block")
return c.getProfileByNameAndType(ctx, defaultBlockProfileName, typeBlock)
}

// GetDefaultProfileFileShare
func (c *Client) GetDefaultProfileFileShare(ctx *c.Context) (*model.ProfileSpec, error) {
return c.getProfileByName(ctx, "default", "file")
return c.getProfileByNameAndType(ctx, defaultFileProfileName, typeFile)
}

// ListProfiles
Expand Down