Skip to content

Commit

Permalink
Merge pull request #80 from HewlettPackard/add-storage-controller
Browse files Browse the repository at this point in the history
Add storage controller mount
  • Loading branch information
manjunath-batakurki authored Oct 24, 2024
2 parents fb2edb9 + 89a5da4 commit c0874ac
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 22 deletions.
37 changes: 37 additions & 0 deletions pkg/client/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"fmt"
"reflect"
"strings"

"github.com/antihax/optional"

Expand Down Expand Up @@ -469,3 +470,39 @@ 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
}
if instanceResp.Instance.Controllers == nil {
err = fmt.Errorf("no storage controllers found in the instance response")
return
}
for _, controller := range instanceResp.Instance.Controllers {
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)
break
}
}
if ControllerMount == "" {
err = fmt.Errorf("storage controller '%s' not found", controllerTypeInput)
}
return
}
1 change: 1 addition & 0 deletions pkg/models/instance_tf.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type TFInstanceVolume struct {
ID int `tf:"id"`
Root bool `tf:"root"`
StorageType int `tf:"storage_type"`
Controller string `tf:"controller"`
}

type TFInstanceNetwork struct {
Expand Down
61 changes: 39 additions & 22 deletions pkg/models/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ type CreateInstanceBodyVolumes struct {
Size int `json:"size,omitempty"`
StorageType int `json:"storageType,omitempty"`
// The ID of the specific datastore. Auto selection can be specified as auto or autoCluster (for clusters).
DatastoreID interface{} `json:"datastoreId,omitempty"`
DatastoreID interface{} `json:"datastoreId,omitempty"`
ControllerMountPoint string `json:"controllerMountPoint,omitempty"`
}

type Instances struct {
Expand Down Expand Up @@ -176,6 +177,19 @@ type GetInstanceResponseInstance struct {
EnvironmentPrefix string `json:"environmentPrefix"`
InstanceContext string `json:"instanceContext"`
ContainerDetails []GetInstanceContainer `json:"containerDetails"`
Controllers []InstanceStorageController `json:"controllers,omitempty"`
}

type InstanceStorageController struct {
ID int64 `json:"id"`
Name string `json:"name"`
Type struct {
ID int `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
} `json:"type"`
MaxDevices int `json:"maxDevices"`
ReservedUnitNumber int `json:"reservedUnitNumber"`
}

// GetInstanceResponseInstanceCloud
Expand Down Expand Up @@ -315,14 +329,15 @@ type GetInstanceResponseInstanceTenant struct {

// GetInstanceResponseInstanceVolumes
type GetInstanceResponseInstanceVolumes struct {
Size int `json:"size,omitempty"`
Name string `json:"name,omitempty"`
RootVolume bool `json:"rootVolume,omitempty"`
StorageType int `json:"storageType,omitempty"`
ID int `json:"id,omitempty"`
DatastoreID interface{} `json:"datastoreId,omitempty"`
MaxStorage float64 `json:"maxStorage,omitempty"`
DeviceDisplayName string `json:"deviceDisplayName,omitempty"`
Size int `json:"size,omitempty"`
Name string `json:"name,omitempty"`
RootVolume bool `json:"rootVolume,omitempty"`
StorageType int `json:"storageType,omitempty"`
ID int `json:"id,omitempty"`
DatastoreID interface{} `json:"datastoreId,omitempty"`
MaxStorage float64 `json:"maxStorage,omitempty"`
DeviceDisplayName string `json:"deviceDisplayName,omitempty"`
ControllerMountPoint string `json:"controllerMountPoint,omitempty"`
}

// ResizeInstanceBody
Expand All @@ -346,13 +361,14 @@ type ResizeInstanceBodyInstancePlan struct {

// ResizeInstanceBodyInstanceVolumes
type ResizeInstanceBodyInstanceVolumes struct {
ID json.Number `json:"id"`
RootVolume bool `json:"rootVolume"`
Name string `json:"name"`
Size int `json:"size"`
SizeID interface{} `json:"sizeId,omitempty"`
StorageType interface{} `json:"storageType,omitempty"`
DatastoreID interface{} `json:"datastoreId,omitempty"`
ID json.Number `json:"id"`
RootVolume bool `json:"rootVolume"`
Name string `json:"name"`
Size int `json:"size"`
SizeID interface{} `json:"sizeId,omitempty"`
StorageType interface{} `json:"storageType,omitempty"`
DatastoreID interface{} `json:"datastoreId,omitempty"`
ControllerMountPoint string `json:"controllerMountPoint,omitempty"`
}

type ResizeInstanceResponse struct {
Expand All @@ -371,12 +387,13 @@ type ResizeInstanceResponseInstance struct {
}

type GetInstanceResposeResizeVolumes struct {
ID json.Number `json:"id,omitempty"`
RootVolume interface{} `json:"rootVolume,omitempty"`
Name string `json:"name,omitempty"`
Size json.Number `json:"size,omitempty"`
StorageType json.Number `json:"storageType,omitempty"`
DatastoreID interface{} `json:"datastoreId,omitempty"`
ID json.Number `json:"id,omitempty"`
RootVolume interface{} `json:"rootVolume,omitempty"`
Name string `json:"name,omitempty"`
Size json.Number `json:"size,omitempty"`
StorageType json.Number `json:"storageType,omitempty"`
DatastoreID interface{} `json:"datastoreId,omitempty"`
ControllerMountPoint string `json:"controllerMountPoint,omitempty"`
}

// SnapshotBody
Expand Down

0 comments on commit c0874ac

Please sign in to comment.