Skip to content

Commit

Permalink
Merge pull request #363 from xxwjj/replication_cli
Browse files Browse the repository at this point in the history
Add replication cli, and finished the dorado replication debuging
  • Loading branch information
xing-yang committed Apr 23, 2018
2 parents beda15f + 43014c7 commit b510a44
Show file tree
Hide file tree
Showing 19 changed files with 688 additions and 193 deletions.
14 changes: 8 additions & 6 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Client struct {
*PoolMgr
*VolumeMgr
*VersionMgr
*ReplicationMgr

cfg *Config
}
Expand Down Expand Up @@ -101,12 +102,13 @@ func NewClient(c *Config) *Client {

t := c.AuthOptions.GetTenantId()
return &Client{
cfg: c,
ProfileMgr: NewProfileMgr(r, c.Endpoint, t),
DockMgr: NewDockMgr(r, c.Endpoint, t),
PoolMgr: NewPoolMgr(r, c.Endpoint, t),
VolumeMgr: NewVolumeMgr(r, c.Endpoint, t),
VersionMgr: NewVersionMgr(r, c.Endpoint, t),
cfg: c,
ProfileMgr: NewProfileMgr(r, c.Endpoint, t),
DockMgr: NewDockMgr(r, c.Endpoint, t),
PoolMgr: NewPoolMgr(r, c.Endpoint, t),
VolumeMgr: NewVolumeMgr(r, c.Endpoint, t),
VersionMgr: NewVersionMgr(r, c.Endpoint, t),
ReplicationMgr: NewReplicationMgr(r, c.Endpoint, t),
}
}

Expand Down
130 changes: 130 additions & 0 deletions client/replication.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// Copyright (c) 2018 Huawei Technologies Co., Ltd. All Rights Reserved.
//
// 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"
)

type ReplicationBuilder *model.ReplicationSpec
type FailoverReplicationBuilder *model.FailoverReplicationSpec

// NewReplicationMgr
func NewReplicationMgr(r Receiver, edp string, tenantId string) *ReplicationMgr {
return &ReplicationMgr{
Receiver: r,
Endpoint: edp,
TenantId: tenantId,
}
}

// ReplicationMgr
type ReplicationMgr struct {
Receiver
Endpoint string
TenantId string
}

// CreateReplication
func (v *ReplicationMgr) CreateReplication(body ReplicationBuilder) (*model.ReplicationSpec, error) {
var res model.ReplicationSpec
url := strings.Join([]string{
v.Endpoint,
urls.GenerateReplicationURL(urls.Client, v.TenantId)}, "/")

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

return &res, nil
}

// GetReplication
func (v *ReplicationMgr) GetReplication(replicaId string) (*model.ReplicationSpec, error) {
var res model.ReplicationSpec
url := strings.Join([]string{
v.Endpoint,
urls.GenerateReplicationURL(urls.Client, v.TenantId, replicaId)}, "/")

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

return &res, nil
}

// ListReplications
func (v *ReplicationMgr) ListReplications() ([]*model.ReplicationSpec, error) {
var res []*model.ReplicationSpec
url := strings.Join([]string{
v.Endpoint,
urls.GenerateReplicationURL(urls.Client, v.TenantId, "detail")}, "/")

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

return res, nil
}

// DeleteReplication
func (v *ReplicationMgr) DeleteReplication(replicaId string, body ReplicationBuilder) error {
url := strings.Join([]string{
v.Endpoint,
urls.GenerateReplicationURL(urls.Client, v.TenantId, replicaId)}, "/")
return v.Recv(url, "DELETE", body, nil)
}

// UpdateReplication
func (v *ReplicationMgr) UpdateReplication(replicaId string, body ReplicationBuilder) (*model.ReplicationSpec, error) {
var res model.ReplicationSpec
url := strings.Join([]string{
v.Endpoint,
urls.GenerateReplicationURL(urls.Client, v.TenantId, replicaId)}, "/")

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

// EnableReplication
func (v *ReplicationMgr) EnableReplication(replicaId string) error {
url := strings.Join([]string{
v.Endpoint,
urls.GenerateReplicationURL(urls.Client, v.TenantId, replicaId, "action")}, "/")
body := map[string]interface{}{"enableReplication": map[string]interface{}{}}
return v.Recv(url, "PUT", body, nil)
}

// EnableReplication
func (v *ReplicationMgr) DisableReplication(replicaId string) error {
url := strings.Join([]string{
v.Endpoint,
urls.GenerateReplicationURL(urls.Client, v.TenantId, replicaId, "action")}, "/")
body := map[string]interface{}{"disableReplication": map[string]interface{}{}}
return v.Recv(url, "PUT", body, nil)
}

// EnableReplication
func (v *ReplicationMgr) FailoverReplication(replicaId string, body FailoverReplicationBuilder) error {
url := strings.Join([]string{
v.Endpoint,
urls.GenerateReplicationURL(urls.Client, v.TenantId, replicaId, "action")}, "/")
return v.Recv(url, "PUT", body, nil)
}
12 changes: 7 additions & 5 deletions contrib/drivers/huawei/dorado/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ func (c *DoradoClient) request(method, url string, in, out interface{}) error {
b, _, err = c.doRequest(method, c.urlPrefix+url, in)
if err == nil {
break
} else {
log.Errorf("URL:%s %s\n BODY:%v", method, c.urlPrefix+url, in)
}
if inErr, ok := err.(*ArrayInnerError); ok {
errCode := inErr.Err.Code
Expand Down Expand Up @@ -988,7 +990,7 @@ func (c *DoradoClient) GetArrayInfo() (*System, error) {

func (c *DoradoClient) ListRemoteDevices() (*[]RemoteDevice, error) {
dev := &RemoteDevicesResp{}
err := c.request("GET", "/remote_device/", nil, dev)
err := c.request("GET", "/remote_device", nil, dev)
if err != nil {
return nil, err
log.Error("List remote devices failed,", err)
Expand All @@ -1014,7 +1016,7 @@ func (c *DoradoClient) GetPair(id string) (*ReplicationPair, error) {

func (c *DoradoClient) SwitchPair(id string) error {
data := map[string]interface{}{"ID": id, "TYPE": "263"}
err := c.request("PUT", "/REPLICATIONPAIR/switch", nil, data)
err := c.request("PUT", "/REPLICATIONPAIR/switch", data, nil)
if err != nil {
log.Errorf("Switch pair failed, %v", err)
}
Expand All @@ -1023,7 +1025,7 @@ func (c *DoradoClient) SwitchPair(id string) error {

func (c *DoradoClient) SplitPair(id string) error {
data := map[string]interface{}{"ID": id, "TYPE": "263"}
err := c.request("PUT", "/REPLICATIONPAIR/split", nil, data)
err := c.request("PUT", "/REPLICATIONPAIR/split", data, nil)
if err != nil {
log.Errorf("Split pair failed, %v", err)
}
Expand All @@ -1032,7 +1034,7 @@ func (c *DoradoClient) SplitPair(id string) error {

func (c *DoradoClient) SyncPair(id string) error {
data := map[string]interface{}{"ID": id, "TYPE": "263"}
err := c.request("PUT", "/REPLICATIONPAIR/sync", nil, data)
err := c.request("PUT", "/REPLICATIONPAIR/sync", data, nil)
if err != nil {
log.Errorf("Sync pair failed, %v", err)
}
Expand All @@ -1041,7 +1043,7 @@ func (c *DoradoClient) SyncPair(id string) error {

func (c *DoradoClient) SetPairSecondAccess(id string, access string) error {
data := map[string]interface{}{"ID": id, "SECRESACCESS": access}
err := c.request("PUT", "/REPLICATIONPAIR/"+id, nil, data)
err := c.request("PUT", "/REPLICATIONPAIR/"+id, data, nil)
if err != nil {
log.Errorf("Set pair secondary access failed, %v", err)
}
Expand Down
16 changes: 16 additions & 0 deletions contrib/drivers/huawei/dorado/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ package dorado

import "time"

const (
defaultConfPath = "/etc/opensds/driver/huawei_dorado.yaml"
defaultAZ = "default"
)

const (
KLunId = "huaweiLunId"
KSnapId = "huaweiSnapId"
)

const (
KPairId = "huaweiReplicaPairId" // replication pair
KSecondaryLunId = "huaweiSecondaryLunId" // secondary lun id
KSecondaryLunWwn = "huaweiSecondaryLunWwn" // secondary lun wwn
)

const (
StatusHealth = "1"
StatusActive = "43"
Expand Down
17 changes: 5 additions & 12 deletions contrib/drivers/huawei/dorado/dorado.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,8 @@ import (
pb "github.com/opensds/opensds/pkg/dock/proto"
"github.com/opensds/opensds/pkg/model"
"github.com/opensds/opensds/pkg/utils/config"
)

const (
defaultConfPath = "/etc/opensds/driver/huawei_dorado.yaml"
defaultAZ = "default"
)

const (
KLunId = "huaweiLunId"
KSnapId = "huaweiSnapId"
"github.com/satori/go.uuid"
"os"
)

type Driver struct {
Expand Down Expand Up @@ -297,10 +289,11 @@ func (d *Driver) ListPools() ([]*model.StoragePoolSpec, error) {
if _, ok := c.Pool[p.Name]; !ok {
continue
}

host, _ := os.Hostname()
name := fmt.Sprintf("%s:%s:%s", host, d.conf.Endpoints, p.Id)
pol := &model.StoragePoolSpec{
BaseModel: &model.BaseModel{
Id: p.Id,
Id: uuid.NewV5(uuid.NamespaceOID, name).String(),
},
Name: p.Name,
TotalCapacity: Sector2Gb(p.UserTotalCapacity),
Expand Down

0 comments on commit b510a44

Please sign in to comment.