From 1c5d2543695a55742362cef8d8589ad163f57bcf Mon Sep 17 00:00:00 2001 From: wisererik Date: Fri, 27 Dec 2019 15:47:08 +0530 Subject: [PATCH 1/2] Fix connection info of attachment --- contrib/connector/fc/fibreChannel.go | 21 +++++++++---------- contrib/drivers/fujitsu/eternus/eternus.go | 15 +++++++------ .../drivers/fujitsu/eternus/eternus_test.go | 19 +++++++++-------- contrib/drivers/hpe/nimble/nimble.go | 6 +++--- .../huawei/fusionstorage/fusionstorage.go | 7 +++---- contrib/drivers/huawei/oceanstor/oceanstor.go | 12 +++++------ contrib/drivers/netapp/ontap/ontap_san.go | 9 ++++---- 7 files changed, 46 insertions(+), 43 deletions(-) diff --git a/contrib/connector/fc/fibreChannel.go b/contrib/connector/fc/fibreChannel.go index aeeba49d4..5657b5b78 100644 --- a/contrib/connector/fc/fibreChannel.go +++ b/contrib/connector/fc/fibreChannel.go @@ -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"` } @@ -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.") } @@ -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) } @@ -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) @@ -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 @@ -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) { diff --git a/contrib/drivers/fujitsu/eternus/eternus.go b/contrib/drivers/fujitsu/eternus/eternus.go index dfc18a6c1..f0b968489 100644 --- a/contrib/drivers/fujitsu/eternus/eternus.go +++ b/contrib/drivers/fujitsu/eternus/eternus.go @@ -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 @@ -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 diff --git a/contrib/drivers/fujitsu/eternus/eternus_test.go b/contrib/drivers/fujitsu/eternus/eternus_test.go index 3de8ecdbf..2e4f84139 100644 --- a/contrib/drivers/fujitsu/eternus/eternus_test.go +++ b/contrib/drivers/fujitsu/eternus/eternus_test.go @@ -17,6 +17,7 @@ package eternus import ( "fmt" "os" + "reflect" "strconv" "strings" "testing" @@ -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") } } @@ -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") } @@ -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") } } diff --git a/contrib/drivers/hpe/nimble/nimble.go b/contrib/drivers/hpe/nimble/nimble.go index a58d66b2d..b953da4f6 100755 --- a/contrib/drivers/hpe/nimble/nimble.go +++ b/contrib/drivers/hpe/nimble/nimble.go @@ -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 diff --git a/contrib/drivers/huawei/fusionstorage/fusionstorage.go b/contrib/drivers/huawei/fusionstorage/fusionstorage.go index 8ca4f026e..f0b5419b5 100644 --- a/contrib/drivers/huawei/fusionstorage/fusionstorage.go +++ b/contrib/drivers/huawei/fusionstorage/fusionstorage.go @@ -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, @@ -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, diff --git a/contrib/drivers/huawei/oceanstor/oceanstor.go b/contrib/drivers/huawei/oceanstor/oceanstor.go index d95d9ac30..6708aae71 100644 --- a/contrib/drivers/huawei/oceanstor/oceanstor.go +++ b/contrib/drivers/huawei/oceanstor/oceanstor.go @@ -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, }, @@ -564,12 +564,12 @@ 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 @@ -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) { diff --git a/contrib/drivers/netapp/ontap/ontap_san.go b/contrib/drivers/netapp/ontap/ontap_san.go index 27cba7724..734156b4e 100644 --- a/contrib/drivers/netapp/ontap/ontap_san.go +++ b/contrib/drivers/netapp/ontap/ontap_san.go @@ -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" @@ -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"}, From a3da36d7685bde16033fb78e45e012ba33be32ec Mon Sep 17 00:00:00 2001 From: zengyingzhe Date: Mon, 30 Dec 2019 19:09:38 +0800 Subject: [PATCH 2/2] Support vstore of Huawei OceanStor --- contrib/drivers/huawei/oceanstor/client.go | 20 +++++++++++++++---- contrib/drivers/huawei/oceanstor/common.go | 1 + contrib/drivers/huawei/oceanstor/constants.go | 9 +++++---- contrib/drivers/huawei/oceanstor/oceanstor.go | 8 ++++---- contrib/drivers/utils/utils.go | 12 +++++++++++ examples/driver/huawei_oceanstor_block.yaml | 1 + 6 files changed, 39 insertions(+), 12 deletions(-) diff --git a/contrib/drivers/huawei/oceanstor/client.go b/contrib/drivers/huawei/oceanstor/client.go index 64476b128..1320c087e 100644 --- a/contrib/drivers/huawei/oceanstor/client.go +++ b/contrib/drivers/huawei/oceanstor/client.go @@ -59,6 +59,7 @@ func IsNotFoundError(err error) bool { type OceanStorClient struct { user string passwd string + vstoreName string endpoints []string urlPrefix string deviceId string @@ -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 @@ -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" @@ -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) } diff --git a/contrib/drivers/huawei/oceanstor/common.go b/contrib/drivers/huawei/oceanstor/common.go index 687f09b71..bfcb9c020 100644 --- a/contrib/drivers/huawei/oceanstor/common.go +++ b/contrib/drivers/huawei/oceanstor/common.go @@ -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"` diff --git a/contrib/drivers/huawei/oceanstor/constants.go b/contrib/drivers/huawei/oceanstor/constants.go index 77a4d0593..2644b3f7e 100644 --- a/contrib/drivers/huawei/oceanstor/constants.go +++ b/contrib/drivers/huawei/oceanstor/constants.go @@ -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 diff --git a/contrib/drivers/huawei/oceanstor/oceanstor.go b/contrib/drivers/huawei/oceanstor/oceanstor.go index 6708aae71..2b57b371c 100644 --- a/contrib/drivers/huawei/oceanstor/oceanstor.go +++ b/contrib/drivers/huawei/oceanstor/oceanstor.go @@ -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 } @@ -575,8 +575,8 @@ func (d *Driver) InitializeConnectionFC(opt *pb.CreateVolumeAttachmentOpts) (*mo 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 { diff --git a/contrib/drivers/utils/utils.go b/contrib/drivers/utils/utils.go index 952db608f..a175f9458 100644 --- a/contrib/drivers/utils/utils.go +++ b/contrib/drivers/utils/utils.go @@ -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 +} diff --git a/examples/driver/huawei_oceanstor_block.yaml b/examples/driver/huawei_oceanstor_block.yaml index 63fb8d920..0acdec051 100644 --- a/examples/driver/huawei_oceanstor_block.yaml +++ b/examples/driver/huawei_oceanstor_block.yaml @@ -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.