From f6fc04fad74c4dcc6e34e28e0f4a0fe79909665c Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Sun, 17 Oct 2021 22:09:39 +0800 Subject: [PATCH] fix: update server vdi and vga with correlation --- pkg/compute/models/guests.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index ebb2f7a74d..7cbca100cb 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -976,6 +976,38 @@ func (self *SGuest) ValidateUpdateData(ctx context.Context, userCred mcclient.To return input, httperrors.NewInputParameterError("name is too short") } + if input.Vdi != nil { + if !utils.IsInStringArray(*input.Vdi, []string{"vnc", "spice"}) { + return input, httperrors.NewInputParameterError("unsupported vdi protocol") + } + } + + if input.Vga != nil || input.Vdi != nil { + vdi := self.Vdi + if input.Vdi != nil { + vdi = *input.Vdi + } + if vdi != "vnc" && vdi != "spice" { + vdi = "vnc" + input.Vdi = &vdi + } + var candidateVga []string + switch vdi { + case "vnc": + candidateVga = []string{"std", "qxl", "virtio"} + case "spice": + candidateVga = []string{"qxl", "virtio"} + } + vga := self.Vga + if input.Vga != nil { + vga = *input.Vga + } + if !utils.IsInStringArray(vga, candidateVga) { + vga = candidateVga[0] + input.Vga = &vga + } + } + var err error input.VirtualResourceBaseUpdateInput, err = self.SVirtualResourceBase.ValidateUpdateData(ctx, userCred, query, input.VirtualResourceBaseUpdateInput) if err != nil {