mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-30 18:23:35 +08:00
fix(region): GPU device type update supported (#14271)
This commit is contained in:
@@ -94,6 +94,7 @@ func init() {
|
||||
ReservedCpu *int `help:"reserved cpu for isolated device"`
|
||||
ReservedMem *int `help:"reserved mem for isolated device"`
|
||||
ReservedStorage *int `help:"reserved storage for isolated device"`
|
||||
DevType string `help:"Device type" choices:"GPU-HPC|GPU-VGA"`
|
||||
}
|
||||
R(&DeviceUpdateOptions{}, "isolated-device-update", "Update a isolated device", func(s *mcclient.ClientSession, args *DeviceUpdateOptions) error {
|
||||
res := modules.IsolatedDevices.BatchUpdate(s, args.ID, jsonutils.Marshal(args))
|
||||
|
||||
@@ -97,6 +97,7 @@ type IsolatedDeviceReservedResourceInput struct {
|
||||
type IsolatedDeviceUpdateInput struct {
|
||||
apis.StandaloneResourceBaseUpdateInput
|
||||
IsolatedDeviceReservedResourceInput
|
||||
DevType string `json:"dev_type"`
|
||||
}
|
||||
|
||||
type IsolatedDeviceJsonDesc struct {
|
||||
|
||||
@@ -130,7 +130,7 @@ func (manager *SIsolatedDeviceManager) ValidateCreateData(ctx context.Context,
|
||||
if input.DevType == "" {
|
||||
return input, httperrors.NewNotEmptyError("dev_type is empty")
|
||||
}
|
||||
if !utils.IsInStringArray(input.DevType, []string{api.GPU_HPC_TYPE, api.GPU_VGA_TYPE, api.USB_TYPE, api.NIC_TYPE}) {
|
||||
if !utils.IsInStringArray(input.DevType, api.VALID_PASSTHROUGH_TYPES) {
|
||||
return input, httperrors.NewInputParameterError("device type %q not supported", input.DevType)
|
||||
}
|
||||
|
||||
@@ -186,6 +186,14 @@ func (self *SIsolatedDevice) ValidateUpdateData(
|
||||
if input.ReservedStorage != nil && *input.ReservedStorage < 0 {
|
||||
return input, httperrors.NewInputParameterError("reserved storage must >= 0")
|
||||
}
|
||||
if input.DevType != "" {
|
||||
if !utils.IsInStringArray(input.DevType, api.VALID_GPU_TYPES) {
|
||||
return input, httperrors.NewInputParameterError("device type %q not support update", input.DevType)
|
||||
}
|
||||
if !self.IsGPU() {
|
||||
return input, httperrors.NewInputParameterError("Can't update for device %q", self.DevType)
|
||||
}
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user