Skip to content

Commit

Permalink
Merge pull request #1157 from opensds/development
Browse files Browse the repository at this point in the history
Merge development into Master for Daito RC4-v0.9.0 release
  • Loading branch information
skdwriting authored Jan 3, 2020
2 parents dfac6a2 + 989a97c commit 51d7d74
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 55 deletions.
21 changes: 10 additions & 11 deletions contrib/connector/fc/fibreChannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ type ConnectorInfo struct {
AuthPass string `mapstructure:"authPassword"`
AuthMethod string `mapstructure:"authMethod"`
TgtDisco bool `mapstructure:"targetDiscovered"`
TargetWWN []string `mapstructure:"targetWWN"`
TargetWWNs []string `mapstructure:"targetWWNs"`
VolumeID string `mapstructure:"volumeId"`
TgtLun string `mapstructure:"targetLun"`
TgtLun int `mapstructure:"targetLun"`
Encrypted bool `mapstructure:"encrypted"`
}

Expand All @@ -48,7 +48,7 @@ func parseFCConnectInfo(connectInfo map[string]interface{}) (*ConnectorInfo, err
var con ConnectorInfo
mapstructure.Decode(connectInfo, &con)

if len(con.TargetWWN) == 0 || con.TgtLun == "0" {
if len(con.TargetWWNs) == 0 || con.TgtLun == 0 {
return nil, errors.New("fibrechannel connection data invalid.")
}

Expand All @@ -71,7 +71,7 @@ func connectVolume(connMap map[string]interface{}) (map[string]string, error) {
return nil, errors.New(errMsg)
}

devicePath, deviceName := volPathDiscovery(volPaths, tries, conn.TargetWWN, hbas)
devicePath, deviceName := volPathDiscovery(volPaths, tries, conn.TargetWWNs, hbas)
if devicePath != "" && deviceName != "" {
log.Printf("Found Fibre Channel volume name, devicePath is %s, deviceName is %s\n", devicePath, deviceName)
}
Expand All @@ -85,7 +85,7 @@ func connectVolume(connMap map[string]interface{}) (map[string]string, error) {
}

func getVolumePaths(conn *ConnectorInfo, hbas []map[string]string) []string {
wwnports := conn.TargetWWN
wwnports := conn.TargetWWNs
devices := getDevices(hbas, wwnports)
lun := conn.TgtLun
hostPaths := getHostDevices(devices, lun)
Expand All @@ -107,7 +107,7 @@ func volPathDiscovery(volPaths []string, tries int, tgtWWN []string, hbas []map[
return "", ""
}

func getHostDevices(devices []map[string]string, lun string) []string {
func getHostDevices(devices []map[string]string, lun int) []string {
var hostDevices []string
for _, device := range devices {
var hostDevice string
Expand Down Expand Up @@ -199,12 +199,11 @@ func getDevices(hbas []map[string]string, wwnports []string) []map[string]string
return device
}

func processLunID(lunID string) string {
lunIDInt, _ := strconv.Atoi(lunID)
if lunIDInt < 256 {
return lunID
func processLunID(lunID int) string {
if lunID < 256 {
return strconv.Itoa(lunID)
}
return fmt.Sprintf("0x%04x%04x00000000", lunIDInt&0xffff, lunIDInt>>16&0xffff)
return fmt.Sprintf("0x%04x%04x00000000", lunID&0xffff, lunID>>16&0xffff)
}

func getFChbasInfo() ([]map[string]string, error) {
Expand Down
15 changes: 9 additions & 6 deletions contrib/drivers/fujitsu/eternus/eternus.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,15 @@ func (d *Driver) initializeConnectionIscsi(opt *pb.CreateVolumeAttachmentOpts) (
}

log.Infof("initialize iscsi connection (%s) success.", opt.GetId())
targetLun, _ := strconv.Atoi(hostLun)
connInfo := &model.ConnectionInfo{
DriverVolumeType: ISCSIProtocol,
ConnectionData: map[string]interface{}{
"targetDiscovered": true,
"targetIQN": iscsiPortInfo.IscsiName,
"targetPortal": iscsiPortInfo.Ip + ":" + strconv.Itoa(iscsiPortInfo.TcpPort),
"targetIQN": []string{iscsiPortInfo.IscsiName},
"targetPortal": []string{iscsiPortInfo.Ip + ":" + strconv.Itoa(iscsiPortInfo.TcpPort)},
"discard": false,
"targetLun": hostLun,
"targetLun": targetLun,
},
}
return connInfo, nil
Expand Down Expand Up @@ -329,13 +330,15 @@ func (d *Driver) initializeConnectionFC(opt *pb.CreateVolumeAttachmentOpts) (*mo
}

log.Infof("initialize fc connection (%s) success.", opt.GetId())

targetLun, _ := strconv.Atoi(hostLun)
fcInfo := &model.ConnectionInfo{
DriverVolumeType: FCProtocol,
ConnectionData: map[string]interface{}{
"targetDiscovered": true,
"targetWwn": fcPortInfo.Wwpn,
"hostname": opt.GetHostInfo().Host,
"targetLun": hostLun,
"targetWWNs": []string{fcPortInfo.Wwpn},
"hostName": opt.GetHostInfo().Host,
"targetLun": targetLun,
},
}
return fcInfo, nil
Expand Down
19 changes: 10 additions & 9 deletions contrib/drivers/fujitsu/eternus/eternus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package eternus
import (
"fmt"
"os"
"reflect"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -519,9 +520,9 @@ func TestInitializeConnection_Iscsi(t *testing.T) {
t.Error("Test InitializeConnection failed")
}
connData := ret.ConnectionData
if connData["targetIQN"] != "iqn.eternus-dx1" ||
connData["targetPortal"] != "192.168.1.1:3260" ||
connData["targetLun"] != "21" {
if !reflect.DeepEqual(connData["targetIQN"], []string{"iqn.eternus-dx1"}) ||
!reflect.DeepEqual(connData["targetPortal"], []string{"192.168.1.1:3260"}) ||
connData["targetLun"] != 21 {
t.Error("Test InitializeConnection failed")
}
}
Expand Down Expand Up @@ -694,9 +695,9 @@ func TestInitializeConnection_FC(t *testing.T) {
t.Error("Test InitializeConnection failed")
}
connData := ret.ConnectionData
if connData["targetWwn"] != "0000000000000001" ||
connData["hostname"] != hostname ||
connData["targetLun"] != "21" {
if !reflect.DeepEqual(connData["targetWWNs"], []string{"0000000000000001"}) ||
connData["hostName"] != hostname ||
connData["targetLun"] != 21 {

t.Error("Test InitializeConnection failed")
}
Expand Down Expand Up @@ -797,9 +798,9 @@ func TestInitializeConnection_FCNoInitiator(t *testing.T) {
t.Error("Test InitializeConnection failed")
}
connData := ret.ConnectionData
if connData["targetWwn"] != "0000000000000001" ||
connData["hostname"] != hostname ||
connData["targetLun"] != "1" {
if !reflect.DeepEqual(connData["targetWWNs"], []string{"0000000000000001"}) ||
connData["hostName"] != hostname ||
connData["targetLun"] != 1 {
t.Error("Test InitializeConnection failed")
}
}
Expand Down
6 changes: 3 additions & 3 deletions contrib/drivers/hpe/nimble/nimble.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@ func (d *Driver) InitializeConnection(opt *pb.CreateVolumeAttachmentOpts) (*mode
DriverVolumeType: FCProtocol,
ConnectionData: map[string]interface{}{
"targetDiscovered": true,
"target_wwn": []string{tgtIqnWwn},
"volume_id": opt.GetVolumeId(),
"targetWWNs": []string{tgtIqnWwn},
"volumeId": opt.GetVolumeId(),
"description": "hpe",
"host_name": opt.GetHostInfo().Host,
"hostName": opt.GetHostInfo().Host,
"targetLun": attachRespBody.Lun,
},
}, nil
Expand Down
7 changes: 3 additions & 4 deletions contrib/drivers/huawei/fusionstorage/fusionstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (d *Driver) ListPools() ([]*StoragePoolSpec, error) {
Name: poolId,
TotalCapacity: p.TotalCapacity >> UnitGiShiftBit,
FreeCapacity: (p.TotalCapacity - p.UsedCapacity) >> UnitGiShiftBit,
ConsumedCapacity: p.UsedCapacity >> UnitGiShiftBit,
ConsumedCapacity: p.UsedCapacity >> UnitGiShiftBit,
StorageType: c.Pool[poolId].StorageType,
Extras: c.Pool[poolId].Extras,
AvailabilityZone: c.Pool[poolId].AvailabilityZone,
Expand Down Expand Up @@ -205,12 +205,11 @@ func (d *Driver) InitializeConnection(opt *pb.CreateVolumeAttachmentOpts) (*Conn
DriverVolumeType: opt.GetAccessProtocol(),
ConnectionData: map[string]interface{}{
"target_discovered": true,
"volume_id": opt.GetVolumeId(),
"volumeId": opt.GetVolumeId(),
"description": "huawei",
"host_name": hostName,
"hostName": hostName,
"targetLun": targetLunId,
"connect_type": FusionstorageIscsi,
"host": hostName,
"initiator": initiator,
"targetIQN": targetIQN,
"targetPortal": targetPortal,
Expand Down
20 changes: 16 additions & 4 deletions contrib/drivers/huawei/oceanstor/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func IsNotFoundError(err error) bool {
type OceanStorClient struct {
user string
passwd string
vstoreName string
endpoints []string
urlPrefix string
deviceId string
Expand All @@ -82,10 +83,11 @@ func NewClient(opt *AuthOptions) (*OceanStorClient, error) {
}

c := &OceanStorClient{
user: opt.Username,
passwd: pwdCiphertext,
endpoints: endpoints,
insecure: opt.Insecure,
user: opt.Username,
passwd: pwdCiphertext,
vstoreName: opt.VstoreName,
endpoints: endpoints,
insecure: opt.Insecure,
}
err := c.login()
return c, err
Expand Down Expand Up @@ -171,6 +173,11 @@ func (c *OceanStorClient) login() error {
"password": c.passwd,
"scope": "0",
}

if len(c.vstoreName) > 0 {
data["vstorename"] = c.vstoreName
}

c.deviceId = ""
for _, ep := range c.endpoints {
url := ep + "/xxxxx/sessions"
Expand Down Expand Up @@ -597,6 +604,11 @@ func (c *OceanStorClient) CreateHostGroup(groupName string) (string, error) {
if hostGrpResp.Error.Code != 0 {
log.Errorf("Create host group failed, group name: %s, error code:%d, description:%s",
groupName, hostGrpResp.Error.Code, hostGrpResp.Error.Description)

if hostGrpResp.Error.Code == ErrorObjectNameAlreadyExist {
return c.FindHostGroup(groupName)
}

return "", fmt.Errorf("code: %d, description: %s",
hostGrpResp.Error.Code, hostGrpResp.Error.Description)
}
Expand Down
1 change: 1 addition & 0 deletions contrib/drivers/huawei/oceanstor/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
type AuthOptions struct {
Username string `yaml:"username,omitempty"`
Password string `yaml:"password,omitempty"`
VstoreName string `yaml:"vstoreName,omitempty"`
PwdEncrypter string `yaml:"PwdEncrypter,omitempty"`
EnableEncrypted bool `yaml:"EnableEncrypted,omitempty"`
Endpoints string `yaml:"endpoints,omitempty"`
Expand Down
9 changes: 5 additions & 4 deletions contrib/drivers/huawei/oceanstor/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ const (

// Error Code
const (
ErrorConnectToServer = -403
ErrorUnauthorizedToServer = -401
ErrorObjectUnavailable = 1077948996
ErrorHostGroupNotExist = 1077937500
ErrorConnectToServer = -403
ErrorUnauthorizedToServer = -401
ErrorObjectUnavailable = 1077948996
ErrorHostGroupNotExist = 1077937500
ErrorObjectNameAlreadyExist = 1077948993
)

// misc
Expand Down
20 changes: 10 additions & 10 deletions contrib/drivers/huawei/oceanstor/oceanstor.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (d *Driver) CreateVolume(opt *pb.CreateVolumeOpts) (*model.VolumeSpec, erro
Size: Sector2Gb(lun.Capacity),
Description: opt.GetDescription(),
AvailabilityZone: opt.GetAvailabilityZone(),
Identifier: &model.Identifier{DurableName: lun.Wwn, DurableNameFormat: "NAA"},
Identifier: &model.Identifier{DurableName: lun.Wwn, DurableNameFormat: "NAA"},
Metadata: map[string]string{
KLunId: lun.Id,
},
Expand Down Expand Up @@ -541,8 +541,8 @@ func (d *Driver) InitializeConnectionFC(opt *pb.CreateVolumeAttachmentOpts) (*mo
}

// Not use FC switch
initiatorName := GetInitiatorName(opt.GetHostInfo().GetInitiators(), opt.GetAccessProtocol())
tgtPortWWNs, initTargMap, err := d.connectFCUseNoSwitch(opt, initiatorName, hostId)
initiators := GetInitiatorsByProtocol(opt.GetHostInfo().GetInitiators(), opt.GetAccessProtocol())
tgtPortWWNs, initTargMap, err := d.connectFCUseNoSwitch(opt, initiators, hostId)
if err != nil {
return nil, err
}
Expand All @@ -564,19 +564,19 @@ func (d *Driver) InitializeConnectionFC(opt *pb.CreateVolumeAttachmentOpts) (*mo
DriverVolumeType: opt.GetAccessProtocol(),
ConnectionData: map[string]interface{}{
"targetDiscovered": true,
"target_wwn": tgtPortWWNs,
"volume_id": opt.GetVolumeId(),
"targetWWNs": tgtPortWWNs,
"volumeId": opt.GetVolumeId(),
"initiator_target_map": initTargMap,
"description": "huawei",
"host_name": opt.GetHostInfo().Host,
"target_lun": tgtLun,
"hostName": opt.GetHostInfo().Host,
"targetLun": tgtLun,
},
}
return fcInfo, nil
}

func (d *Driver) connectFCUseNoSwitch(opt *pb.CreateVolumeAttachmentOpts, wwpns string, hostId string) ([]string, map[string][]string, error) {
wwns := strings.Split(wwpns, ",")
func (d *Driver) connectFCUseNoSwitch(opt *pb.CreateVolumeAttachmentOpts, initiators []string, hostId string) ([]string, map[string][]string, error) {
wwns := initiators

onlineWWNsInHost, err := d.client.GetHostOnlineFCInitiators(hostId)
if err != nil {
Expand Down Expand Up @@ -733,7 +733,7 @@ func (d *Driver) deleteZoneAndRemoveFCInitiators(wwns []string, hostId, hostGrpI
}
}

return fmt.Sprintf("driver_volume_type: fibre_channel, target_wwn: %s, initiator_target_map: %s", tgtPortWWNs, initTargMap), nil
return fmt.Sprintf("driver_volume_type: fibre_channel, target_wwns: %s, initiator_target_map: %s", tgtPortWWNs, initTargMap), nil
}

func (d *Driver) getMappedInfo(hostName string) (string, string, string, string, error) {
Expand Down
9 changes: 5 additions & 4 deletions contrib/drivers/netapp/ontap/ontap_san.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"strconv"
"strings"

"github.com/ghodss/yaml"
log "github.com/golang/glog"
uuid "github.com/satori/go.uuid"
"strconv"
"strings"

"github.com/netapp/trident/storage"
sa "github.com/netapp/trident/storage_attribute"
Expand Down Expand Up @@ -317,10 +318,10 @@ func (d *SANDriver) InitializeConnection(opt *pb.CreateVolumeAttachmentOpts) (*m
DriverVolumeType: opt.GetAccessProtocol(),
ConnectionData: map[string]interface{}{
"target_discovered": true,
"volume_id": opt.GetVolumeId(),
"volumeId": opt.GetVolumeId(),
"volume": name,
"description": "NetApp ONTAP Attachment",
"host": hostName,
"hostName": hostName,
"initiator": initiator,
"targetIQN": []string{publishInfo.IscsiTargetIQN},
"targetPortal": []string{hostInfo.GetIp() + ":3260"},
Expand Down
12 changes: 12 additions & 0 deletions contrib/drivers/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,15 @@ func GetInitiatorName(initiators []*pb.Initiator, protocol string) string {
}
return ""
}

func GetInitiatorsByProtocol(initiators []*pb.Initiator, protocol string) []string {
var protocolInitiators []string

for _, initiator := range initiators {
if initiator.Protocol == protocol {
protocolInitiators = append(protocolInitiators, initiator.PortName)
}
}

return protocolInitiators
}
1 change: 1 addition & 0 deletions examples/driver/huawei_oceanstor_block.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
authOptions:
username: "root"
password: "Admin@123"
vstoreName: ""
# Whether to encrypt the password. If enabled, the value of the password must be ciphertext.
EnableEncrypted: false
# Encryption and decryption tool. Default value is aes. The decryption tool can only decrypt the corresponding ciphertext.
Expand Down

0 comments on commit 51d7d74

Please sign in to comment.