Skip to content

Commit

Permalink
enhance the volume detachment process (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyingzhe authored and wisererik committed Jan 11, 2020
1 parent 41239dc commit 64284a2
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 15 deletions.
63 changes: 53 additions & 10 deletions contrib/drivers/huawei/oceanstor/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1021,9 +1021,14 @@ func (c *OceanStorClient) GetHostLunId(hostId, lunId string) (int, error) {
func (c *OceanStorClient) RemoveLunFromLunGroup(lunGrpId, lunId string) error {
url := fmt.Sprintf("/lungroup/associate?ID=%s&ASSOCIATEOBJTYPE=11&ASSOCIATEOBJID=%s", lunGrpId, lunId)
if err := c.request("DELETE", url, nil, nil); err != nil {
if c.checkErrorCode(err, ErrorObjectUnavailable) {
return nil
}

log.Errorf("Remove lun %s from lun group %s failed, %v", lunId, lunGrpId, err)
return err
}

log.Infof("Remove lun %s from lun group %s success", lunId, lunGrpId)
return nil
}
Expand All @@ -1033,16 +1038,23 @@ func (c *OceanStorClient) RemoveLunGroupFromMappingView(viewId, lunGrpId string)
log.Infof("Lun group %s has already been removed from mapping view %s", lunGrpId, viewId)
return nil
}

url := "/mappingview/REMOVE_ASSOCIATE"
data := map[string]interface{}{
"ASSOCIATEOBJTYPE": ObjectTypeLunGroup,
"ASSOCIATEOBJID": lunGrpId,
"TYPE": ObjectTypeMappingView,
"ID": viewId}

if err := c.request("PUT", url, data, nil); err != nil {
if c.checkErrorCode(err, ErrorLunGroupNotInMappingView) {
return nil
}

log.Errorf("Remove lun group %s from mapping view %s failed", lunGrpId, viewId)
return err
}

log.Infof("Remove lun group %s from mapping view %s success", lunGrpId, viewId)
return nil
}
Expand All @@ -1052,58 +1064,93 @@ func (c *OceanStorClient) RemoveHostGroupFromMappingView(viewId, hostGrpId strin
log.Infof("Host group %s has already been removed from mapping view %s", hostGrpId, viewId)
return nil
}

url := "/mappingview/REMOVE_ASSOCIATE"
data := map[string]interface{}{
"ASSOCIATEOBJTYPE": ObjectTypeHostGroup,
"ASSOCIATEOBJID": hostGrpId,
"TYPE": ObjectTypeMappingView,
"ID": viewId}

if err := c.request("PUT", url, data, nil); err != nil {
if c.checkErrorCode(err, ErrorHostGroupNotInMappingView) {
return nil
}

log.Errorf("Remove host group %s from mapping view %s failed", hostGrpId, viewId)
return err
}

log.Infof("Remove host group %s from mapping view %s success", hostGrpId, viewId)
return nil
}

func (c *OceanStorClient) RemoveHostFromHostGroup(hostGrpId, hostId string) error {

url := fmt.Sprintf("/host/associate?TYPE=14&ID=%s&ASSOCIATEOBJTYPE=21&ASSOCIATEOBJID=%s",
hostGrpId, hostId)
if err := c.request("DELETE", url, nil, nil); err != nil {
if c.checkErrorCode(err, ErrorHostNotInHostGroup) {
return nil
}

log.Errorf("Remove host %s from host group %s failed", hostId, hostGrpId)
return err
}

log.Infof("Remove host %s from host group %s success", hostId, hostGrpId)
return nil
}

func (c *OceanStorClient) RemoveIscsiFromHost(initiator string) error {

url := "/iscsi_initiator/remove_iscsi_from_host"
data := map[string]interface{}{"TYPE": ObjectTypeIscsiInitiator, "ID": initiator}
if err := c.request("PUT", url, data, nil); err != nil {
if c.checkErrorCode(err, ErrorInitiatorNotInHost) {
return nil
}

log.Errorf("Remove initiator %s failed", initiator)
return err
}

log.Infof("Remove initiator %s success", initiator)
return nil
}

func (c *OceanStorClient) DeleteHostGroup(id string) error {
return c.request("DELETE", "/hostgroup/"+id, nil, nil)
err := c.request("DELETE", "/hostgroup/"+id, nil, nil)
if err != nil && c.checkErrorCode(err, ErrorHostGroupNotExist) {
return nil
}

return err
}

func (c *OceanStorClient) DeleteLunGroup(id string) error {
return c.request("DELETE", "/LUNGroup/"+id, nil, nil)
err := c.request("DELETE", "/LUNGroup/"+id, nil, nil)
if err != nil && c.checkErrorCode(err, ErrorObjectUnavailable) {
return nil
}

return err
}

func (c *OceanStorClient) DeleteHost(id string) error {
return c.request("DELETE", "/host/"+id, nil, nil)
err := c.request("DELETE", "/host/"+id, nil, nil)
if err != nil && c.checkErrorCode(err, ErrorHostNotExist) {
return nil
}

return err
}

func (c *OceanStorClient) DeleteMappingView(id string) error {
return c.request("DELETE", "/mappingview/"+id, nil, nil)
err := c.request("DELETE", "/mappingview/"+id, nil, nil)
if err != nil && c.checkErrorCode(err, ErrorMappingViewNotExist) {
return nil
}

return err
}

func (c *OceanStorClient) GetArrayInfo() (*System, error) {
Expand Down Expand Up @@ -1303,10 +1350,6 @@ func (c *OceanStorClient) IsHostAssociatedToHostgroup(hostId string) (bool, erro
return false, nil
}

func (c *OceanStorClient) RemoveHost(hostId string) error {
return c.request("DELETE", fmt.Sprintf("/host/%s", hostId), nil, nil)
}

func (c *OceanStorClient) AddFCPortTohost(hostId string, wwn string) error {
url := fmt.Sprintf("/fc_initiator/%s", wwn)
data := map[string]interface{}{
Expand Down
6 changes: 6 additions & 0 deletions contrib/drivers/huawei/oceanstor/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ const (
ErrorHostGroupAlreadyInMappingView = 1073804556
ErrorLunGroupAlreadyInMappingView = 1073804560
ErrorLunNotExist = 1077936859
ErrorLunGroupNotInMappingView = 1073804554
ErrorHostGroupNotInMappingView = 1073804552
ErrorHostNotInHostGroup = 1073745412
ErrorHostNotExist = 1077937498
ErrorMappingViewNotExist = 1077951819
ErrorInitiatorNotInHost = 1077950342
)

// misc
Expand Down
17 changes: 12 additions & 5 deletions contrib/drivers/huawei/oceanstor/oceanstor.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ func (d *Driver) connectFCUseNoSwitch(opt *pb.CreateVolumeAttachmentOpts, initia
}

if wwnsInHost == nil && iqnsInHost == nil && flag == false {
if err = d.client.RemoveHost(hostId); err != nil {
if err = d.client.DeleteHost(hostId); err != nil {
return nil, nil, err
}
}
Expand Down Expand Up @@ -746,19 +746,26 @@ func (d *Driver) deleteZoneAndRemoveFCInitiators(wwns []string, hostId, hostGrpI
func (d *Driver) getMappedInfo(hostName string) (string, string, string, string, error) {
hostId, err := d.client.GetHostIdByName(hostName)
if err != nil {
if IsNotFoundError(err) {
log.Warningf("host(%s) has been removed already, ignore it.", hostName)
return "", "", "", "", nil
}

return "", "", "", "", err
}

lunGrpId, err := d.client.FindLunGroup(PrefixLunGroup + hostId)
if err != nil {
if err != nil && !IsNotFoundError(err) {
return "", "", "", "", err
}

hostGrpId, err := d.client.FindHostGroup(PrefixHostGroup + hostId)
if err != nil {
if err != nil && !IsNotFoundError(err) {
return "", "", "", "", err
}

viewId, err := d.client.FindMappingView(PrefixMappingView + hostId)
if err != nil {
if err != nil && !IsNotFoundError(err) {
return "", "", "", "", err
}

Expand Down Expand Up @@ -806,7 +813,7 @@ func (d *Driver) clearHostRelatedResource(lunGrpId, viewId, hostId, hostGrpId st
return err
}
if !flag {
if err := d.client.RemoveHost(hostId); err != nil {
if err := d.client.DeleteHost(hostId); err != nil {
return err
}
}
Expand Down

0 comments on commit 64284a2

Please sign in to comment.