diff --git a/pkg/client/broker.go b/pkg/client/broker.go index ec607f1..05e2158 100644 --- a/pkg/client/broker.go +++ b/pkg/client/broker.go @@ -52,8 +52,8 @@ func (a *BrokerAPIService) GetMorpheusDetails(ctx context.Context) (models.TFMor }, } - // No query params needed - if err := morpheusTokenAPI.do(ctx, nil, nil); err != nil { + // for edge pass location in query params + if err := morpheusTokenAPI.do(ctx, nil, a.Cfg.DefaultQueryParams); err != nil { return models.TFMorpheusDetails{}, fmt.Errorf("error getting Morpheus token: %v", err) } diff --git a/pkg/client/broker_test.go b/pkg/client/broker_test.go index 628efed..d668f90 100644 --- a/pkg/client/broker_test.go +++ b/pkg/client/broker_test.go @@ -100,7 +100,7 @@ func TestBrokerAPIService_GetMorpheusDetails(t *testing.T) { // mock the context only since it is not validated in this function m.EXPECT().getVersion().Return(999999) m.EXPECT().prepareRequest(gomock.Any(), pathToken, method, nil, headers, - url.Values{}, url.Values{}, "", nil).Return(reqToken, nil) + getURLValues(queryParams), url.Values{}, "", nil).Return(reqToken, nil) m.EXPECT().callAPI(reqToken).Return(&http.Response{ StatusCode: 200, @@ -186,7 +186,7 @@ func TestBrokerAPIService_GetMorpheusDetails(t *testing.T) { // mock the context only since it is not validated in this function m.EXPECT().getVersion().Return(999999) m.EXPECT().prepareRequest(gomock.Any(), pathToken, method, nil, headers, - url.Values{}, url.Values{}, "", nil). + getURLValues(queryParams), url.Values{}, "", nil). Return(nil, errors.New("error in prepare request")) }, }, @@ -233,7 +233,7 @@ func TestBrokerAPIService_GetMorpheusDetails(t *testing.T) { // mock the context only since it is not validated in this function m.EXPECT().getVersion().Return(999999) m.EXPECT().prepareRequest(gomock.Any(), pathToken, method, nil, headers, - url.Values{}, url.Values{}, "", nil).Return(reqToken, nil) + getURLValues(queryParams), url.Values{}, "", nil).Return(reqToken, nil) m.EXPECT().callAPI(reqToken).Return(&http.Response{ StatusCode: 500, diff --git a/pkg/client/instances.go b/pkg/client/instances.go index c0e0334..27ecb29 100644 --- a/pkg/client/instances.go +++ b/pkg/client/instances.go @@ -471,38 +471,40 @@ func (a *InstancesAPIService) GetStorageVolTypeID(ctx context.Context, cloudID, return StorageVol, err } -func (a *InstancesAPIService) GetStorageControllerMount(ctx context.Context, instanceID int, controllerType string, - busNumber, unitNumber int) (ControllerMount string, err error) { - 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 +func (a *InstancesAPIService) GetStorageControllerTypes(ctx context.Context, layoutID string, +) (models.StorageControllerTypesResp, error) { + StorageControllers := models.StorageControllerTypesResp{} + + apiCaller := &api{ + method: "GET", + path: consts.StorageControllerTypesPath, + client: a.Client, + + jsonParser: func(body []byte) error { + return json.Unmarshal(body, &StorageControllers) + }, } - if instanceResp.Instance.Controllers == nil { - err = fmt.Errorf("no storage controllers found in the instance response") - return + queryParams := map[string]string{ + "layoutId": layoutID, } - for _, controller := range instanceResp.Instance.Controllers { + err := apiCaller.do(ctx, nil, queryParams) + + return StorageControllers, err +} +func (a *InstancesAPIService) GetStorageControllerMount(ctx context.Context, layoutID string, controllerName string, + busNumber, unitNumber int) (ControllerMount string, err error) { + controllerNameInput := strings.TrimSpace(strings.ToLower(controllerName)) + controllerRest, err := a.GetStorageControllerTypes(ctx, layoutID) + for _, controller := range controllerRest.Data { controllerName := strings.TrimSpace(strings.ToLower(controller.Name)) - if controllerName == controllerTypeInput { - if controller.MaxDevices <= unitNumber { - 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) + if controllerName == controllerNameInput { + + ControllerMount = fmt.Sprintf("%d:%d:%d:%d", -1, busNumber, controller.Value, unitNumber) break } } if ControllerMount == "" { - err = fmt.Errorf("storage controller '%s' not found", controllerTypeInput) + err = fmt.Errorf("invalid controller type '%s'", controllerName) } return } diff --git a/pkg/common/constants.go b/pkg/common/constants.go index 46d8b28..5410321 100644 --- a/pkg/common/constants.go +++ b/pkg/common/constants.go @@ -28,6 +28,8 @@ const ( ServicePlansPath = "service-plans" // Instance Service Plan for storage vol type InstancePlanPath = "instances/service-plans" + // Storage Controller Types for a layout + StorageControllerTypesPath = "options/storageControllerTypes" // CloudsPath CloudsPath = "clouds" // ZonePath diff --git a/pkg/models/instances.go b/pkg/models/instances.go index 16d706c..e78ed71 100644 --- a/pkg/models/instances.go +++ b/pkg/models/instances.go @@ -645,3 +645,11 @@ type InstanceStorageType struct { VolumeCategory string `json:"volumeCategory"` ExternalID string `json:"externalId"` } +type ValueName struct { + Value int `json:"value"` + Name string `json:"name"` +} + +type StorageControllerTypesResp struct { + Data []ValueName `json:"data"` +} diff --git a/pkg/models/library.go b/pkg/models/library.go index 699f840..5040d9e 100644 --- a/pkg/models/library.go +++ b/pkg/models/library.go @@ -1,4 +1,4 @@ -// (C) Copyright 2021 Hewlett Packard Enterprise Development LP +// (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP package models @@ -248,12 +248,18 @@ type InstanceTypeRespBody struct { Featured bool `json:"featured"` Versions []string `json:"versions"` Instancetypelayouts []struct { - ID int `json:"id"` - Name string `json:"name"` - Provisiontypecode string `json:"provisionTypeCode"` + ID int `json:"id"` + Name string `json:"name"` + Provisiontypecode string `json:"provisionTypeCode"` + ProvisionType ProvisionType `json:"provisionType"` } `json:"instanceTypeLayouts"` } +type ProvisionType struct { + ID int `json:"id"` + Name string `json:"name"` + Code string `json:"code"` +} type InstanceTypesResp struct { InstanceTypes []InstanceTypeRespBody `json:"instanceTypes"` }