mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-30 17:13:08 +08:00
support diable usb kbd
This commit is contained in:
@@ -1140,6 +1140,7 @@ func init() {
|
||||
ID string `help:"ID or name of VM"`
|
||||
DisableIsaSerial string `help:"disable isa serial device" choices:"true|false"`
|
||||
DisablePvpanic string `help:"disable pvpanic device" choices:"true|false"`
|
||||
DisableUsbKbd string `help:"disable usb kbd" choices:"true|false"`
|
||||
}
|
||||
|
||||
R(&ServerQemuParams{}, "server-set-qemu-params", "config qemu params", func(s *mcclient.ClientSession,
|
||||
@@ -1151,6 +1152,9 @@ func init() {
|
||||
if len(opts.DisablePvpanic) > 0 {
|
||||
params.Set("disable_pvpanic", jsonutils.NewString(opts.DisablePvpanic))
|
||||
}
|
||||
if len(opts.DisableUsbKbd) > 0 {
|
||||
params.Set("disable_usb_kbd", jsonutils.NewString(opts.DisableUsbKbd))
|
||||
}
|
||||
result, err := modules.Servers.PerformAction(s, opts.ID, "set-qemu-params", params)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -54,6 +54,7 @@ type ImageOptionalOptions struct {
|
||||
Hypervisor []string `help:"Prefer hypervisor type" choices:"kvm|esxi|baremetal|container|openstack|ctyun"`
|
||||
DiskDriver string `help:"Perfer disk driver" choices:"virtio|scsi|pvscsi|ide|sata"`
|
||||
NetDriver string `help:"Preferred network driver" choices:"virtio|e1000|vmxnet3"`
|
||||
DisableUsbKbd bool `help:"Disable usb keyboard on this image(for hypervisor kvm)"`
|
||||
}
|
||||
|
||||
func addImageOptionalOptions(s *mcclient.ClientSession, params *jsonutils.JSONDict, args ImageOptionalOptions) error {
|
||||
@@ -131,6 +132,9 @@ func addImageOptionalOptions(s *mcclient.ClientSession, params *jsonutils.JSONDi
|
||||
if len(args.Hypervisor) > 0 {
|
||||
params.Add(jsonutils.NewString(strings.Join(args.Hypervisor, ",")), "properties", "hypervisor")
|
||||
}
|
||||
if args.DisableUsbKbd {
|
||||
params.Add(jsonutils.NewString("true"), "properties", "disable_usb_kbd")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -471,7 +471,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
|
||||
|
||||
@@ -50,6 +50,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"
|
||||
)
|
||||
|
||||
@@ -3091,6 +3091,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
|
||||
}
|
||||
|
||||
|
||||
@@ -1149,6 +1149,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)
|
||||
@@ -1707,6 +1708,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