Skip to content

Commit

Permalink
Merge pull request #88 from HewlettPackard/tf-improv
Browse files Browse the repository at this point in the history
Update the storage controller
  • Loading branch information
manjunath-batakurki authored Jan 6, 2025
2 parents 649fc66 + 0ef78df commit 47dcc38
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 34 deletions.
4 changes: 2 additions & 2 deletions pkg/client/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/client/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"))
},
},
Expand Down Expand Up @@ -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,
Expand Down
52 changes: 27 additions & 25 deletions pkg/client/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions pkg/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions pkg/models/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
14 changes: 10 additions & 4 deletions pkg/models/library.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) Copyright 2021 Hewlett Packard Enterprise Development LP
// (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP

package models

Expand Down Expand Up @@ -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"`
}

0 comments on commit 47dcc38

Please sign in to comment.