From 78c0fcb757424210212c7228b51cf0bd173c2535 Mon Sep 17 00:00:00 2001 From: Mahesh N Date: Wed, 16 Oct 2024 13:04:18 +0530 Subject: [PATCH 1/3] Add storage controller mount --- pkg/client/instances.go | 25 +++++++++++++++++++++++++ pkg/models/instance_tf.go | 1 + pkg/models/instances.go | 30 ++++++++++++++++++++++-------- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/pkg/client/instances.go b/pkg/client/instances.go index 2b7c199..271ef54 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,27 @@ 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) { + controllerType = strings.ToLower(controllerType) + 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") + return + } + for _, controller := range instanceResp.Instance.Controllers { + if strings.ToLower(controller.Type.Name) == controllerType { + if controller.MaxDevices <= unitNumber { + err = fmt.Errorf("max allowed devices exceed for controller '%s'", controllerType) + return + } + ControllerMount = fmt.Sprintf("%d:%d:%d:%d", controller.ID, busNumber, controller.Type.ID, unitNumber) + } + } + + 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..e4cf2a3 100644 --- a/pkg/models/instances.go +++ b/pkg/models/instances.go @@ -176,6 +176,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 +328,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 From a5234ae572d2342ec65b53ec7b8c982d1437a025 Mon Sep 17 00:00:00 2001 From: Mahesh N Date: Wed, 16 Oct 2024 14:52:56 +0530 Subject: [PATCH 2/3] 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 } From 89a5da4e47090939c2595869e5f8919572238d02 Mon Sep 17 00:00:00 2001 From: Mahesh N Date: Wed, 16 Oct 2024 15:10:43 +0530 Subject: [PATCH 3/3] update schema --- pkg/models/instances.go | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/pkg/models/instances.go b/pkg/models/instances.go index e4cf2a3..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 { @@ -360,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 { @@ -385,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