fix(region): GPU device type update supported (#14271)

This commit is contained in:
Zexi Li
2022-05-19 01:21:54 +08:00
committed by GitHub
parent d30cd018c6
commit 63bb93a89b
3 changed files with 11 additions and 1 deletions
@@ -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))
+1
View File
@@ -97,6 +97,7 @@ type IsolatedDeviceReservedResourceInput struct {
type IsolatedDeviceUpdateInput struct {
apis.StandaloneResourceBaseUpdateInput
IsolatedDeviceReservedResourceInput
DevType string `json:"dev_type"`
}
type IsolatedDeviceJsonDesc struct {
+9 -1
View File
@@ -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
}