mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
Merge pull request #7549 from wanyaoqi/automated-cherry-pick-of-#7547-upstream-release-3.2
Automated cherry pick of #7547: support diable usb kbd
This commit is contained in:
@@ -466,7 +466,8 @@ type ServerCreateInput struct {
|
||||
|
||||
// swagger:ignore
|
||||
OsType string `json:"os_type"`
|
||||
|
||||
// swagger:ignore
|
||||
DisableUsbKbd bool `json:"disable_usb_kbd"`
|
||||
// swagger:ignore
|
||||
OsProfile jsonutils.JSONObject `json:"__os_profile__"`
|
||||
// swagger:ignore
|
||||
|
||||
@@ -48,6 +48,7 @@ const (
|
||||
IMAGE_IS_READONLY = "is_readonly"
|
||||
IMAGE_PARTITION_TYPE = "partition_type"
|
||||
IMAGE_INSTALLED_CLOUDINIT = "installed_cloud_init"
|
||||
IMAGE_DISABLE_USB_KBD = "disable_usb_kbd"
|
||||
|
||||
IMAGE_STATUS_UPDATING = "updating"
|
||||
)
|
||||
|
||||
@@ -3056,6 +3056,13 @@ func (self *SGuest) PerformSetQemuParams(ctx context.Context, userCred mcclient.
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
usbKbd, err := data.GetString("disable_usb_kbd")
|
||||
if err == nil {
|
||||
err = self.SetMetadata(ctx, "disable_usb_kbd", usbKbd, userCred)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1107,6 +1107,7 @@ func (manager *SGuestManager) validateCreateData(
|
||||
if len(imgProperties) == 0 {
|
||||
imgProperties = map[string]string{"os_type": "Linux"}
|
||||
}
|
||||
input.DisableUsbKbd = imgProperties[imageapi.IMAGE_DISABLE_USB_KBD] == "true"
|
||||
|
||||
osType := input.OsType
|
||||
osProf, err = osprofile.GetOSProfileFromImageProperties(imgProperties, hypervisor)
|
||||
@@ -1665,6 +1666,9 @@ func (guest *SGuest) PostCreate(ctx context.Context, userCred mcclient.TokenCred
|
||||
if osProfileJson != nil {
|
||||
guest.setOSProfile(ctx, userCred, osProfileJson)
|
||||
}
|
||||
if jsonutils.QueryBoolean(data, imageapi.IMAGE_DISABLE_USB_KBD, false) {
|
||||
guest.SetMetadata(ctx, imageapi.IMAGE_DISABLE_USB_KBD, "true", userCred)
|
||||
}
|
||||
|
||||
userData, _ := data.GetString("user_data")
|
||||
if len(userData) > 0 {
|
||||
|
||||
@@ -79,6 +79,11 @@ func (s *SKVMGuestInstance) getOsname() string {
|
||||
return osName
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) disableUsbKbd() bool {
|
||||
val, _ := s.Desc.GetString("metadata", "disable_usb_kbd")
|
||||
return val == "true"
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) getOsDistribution() string {
|
||||
osDis, _ := s.Desc.GetString("metadata", "os_distribution")
|
||||
return osDis
|
||||
@@ -499,7 +504,7 @@ func (s *SKVMGuestInstance) _generateStartScript(data *jsonutils.JSONDict) (stri
|
||||
|
||||
cmd += " -device virtio-serial"
|
||||
cmd += " -usb"
|
||||
if !utils.IsInStringArray(s.getOsDistribution(), []string{OS_NAME_OPENWRT, OS_NAME_CIRROS}) {
|
||||
if !utils.IsInStringArray(s.getOsDistribution(), []string{OS_NAME_OPENWRT, OS_NAME_CIRROS}) && !s.disableUsbKbd() {
|
||||
cmd += " -device usb-kbd"
|
||||
}
|
||||
// # if osname == self.OS_NAME_ANDROID:
|
||||
|
||||
Reference in New Issue
Block a user