From a5234ae572d2342ec65b53ec7b8c982d1437a025 Mon Sep 17 00:00:00 2001 From: Mahesh N Date: Wed, 16 Oct 2024 14:52:56 +0530 Subject: [PATCH] add checks --- pkg/client/instances.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/pkg/client/instances.go b/pkg/client/instances.go index 271ef54..c0e0334 100644 --- a/pkg/client/instances.go +++ b/pkg/client/instances.go @@ -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 }