diff --git a/pkg/client/instances.go b/pkg/client/instances.go index 2b7c199..c0e0334 100644 --- a/pkg/client/instances.go +++ b/pkg/client/instances.go @@ -7,6 +7,7 @@ import ( "encoding/json" "fmt" "reflect" + "strings" "github.com/antihax/optional" @@ -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 +} diff --git a/pkg/models/instance_tf.go b/pkg/models/instance_tf.go index edb7a24..bce23cc 100644 --- a/pkg/models/instance_tf.go +++ b/pkg/models/instance_tf.go @@ -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 { diff --git a/pkg/models/instances.go b/pkg/models/instances.go index b9a832c..7396e0a 100644 --- a/pkg/models/instances.go +++ b/pkg/models/instances.go @@ -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 { @@ -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 @@ -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 @@ -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 { @@ -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