Skip to content

Commit

Permalink
add checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mahesh-hpe committed Oct 16, 2024
1 parent 78c0fcb commit a5234ae
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions pkg/client/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,24 +473,36 @@ func (a *InstancesAPIService) GetStorageVolTypeID(ctx context.Context, cloudID,

func (a *InstancesAPIService) GetStorageControllerMount(ctx context.Context, instanceID int, controllerType string,
busNumber, unitNumber int) (ControllerMount string, err error) {
controllerType = strings.ToLower(controllerType)
controllerTypeInput := strings.ToLower(controllerType)
if controllerTypeInput == "ide" {
controllerTypeInput = fmt.Sprintf("%s %d", controllerTypeInput, busNumber)
} else if controllerTypeInput == "scsi" {
controllerTypeInput = fmt.Sprintf("%s controller %d", controllerTypeInput, busNumber)
} else {
err = fmt.Errorf("invalid controller type '%s'", controllerType)
return
}
instanceResp, err := a.GetASpecificInstance(ctx, instanceID)
if err != nil {
return
}
if instanceResp.Instance.Controllers == nil {
err = fmt.Errorf("no controllers found in the instance response")
err = fmt.Errorf("no storage controllers found in the instance response")
return
}
for _, controller := range instanceResp.Instance.Controllers {
if strings.ToLower(controller.Type.Name) == controllerType {
controllerName := strings.TrimSpace(strings.ToLower(controller.Name))
if controllerName == controllerTypeInput {
if controller.MaxDevices <= unitNumber {
err = fmt.Errorf("max allowed devices exceed for controller '%s'", controllerType)
err = fmt.Errorf("max allowed devices exceed for controller '%s'", controllerTypeInput)
return
}
ControllerMount = fmt.Sprintf("%d:%d:%d:%d", controller.ID, busNumber, controller.Type.ID, unitNumber)
break
}
}

if ControllerMount == "" {
err = fmt.Errorf("storage controller '%s' not found", controllerTypeInput)
}
return
}

0 comments on commit a5234ae

Please sign in to comment.