diff --git a/README.md b/README.md index 002708fd..7093cdce 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,11 @@ createQemu JSON Sample: "tag": -1 } }, + "rng0": { + "source": "/dev/urandom", + "max_bytes": "1024", + "period": "1000" + }, "usb": { "0": { "host": "0658:0200", diff --git a/proxmox/config_qemu.go b/proxmox/config_qemu.go index 2f3e8d5b..42156f52 100644 --- a/proxmox/config_qemu.go +++ b/proxmox/config_qemu.go @@ -48,6 +48,7 @@ type ConfigQemu struct { Description string `json:"description,omitempty"` Disks *QemuStorages `json:"disks,omitempty"` EFIDisk QemuDevice `json:"efidisk,omitempty"` // TODO should be a struct + RNGDrive QemuDevice `json:"rng0,omitempty"` // TODO should be a struct FullClone *int `json:"fullclone,omitempty"` // TODO should probably be a bool HaGroup string `json:"hagroup,omitempty"` HaState string `json:"hastate,omitempty"` // TODO should be custom type with enum @@ -179,6 +180,9 @@ func (config ConfigQemu) CreateVm(vmr *VmRef, client *Client) (err error) { // Create EFI disk config.CreateQemuEfiParams(params) + // Create VirtIO RNG + config.CreateQemuRngParams(params) + // Create vga config. vgaParam := QemuDeviceParam{} vgaParam = vgaParam.createDeviceParam(config.QemuVga, nil) @@ -226,6 +230,9 @@ func (config *ConfigQemu) defaults() { if config.Bios == "" { config.Bios = "seabios" } + if config.RNGDrive == nil { + config.RNGDrive = QemuDevice{} + } if config.EFIDisk == nil { config.EFIDisk = QemuDevice{} } @@ -419,6 +426,9 @@ func (config ConfigQemu) mapToApiValues(currentConfig ConfigQemu) (rebootRequire // Create EFI disk config.CreateQemuEfiParams(params) + // Create VirtIO RNG + config.CreateQemuRngParams(params) + // Create networks config. config.CreateQemuNetworksParams(params) @@ -1503,6 +1513,25 @@ func (c ConfigQemu) CreateIpconfigParams(params map[string]interface{}) error { return nil } +// Create RNG parameter. +func (c ConfigQemu) CreateQemuRngParams(params map[string]interface{}) { + rngParam := QemuDeviceParam{} + rngParam = rngParam.createDeviceParam(c.RNGDrive, nil) + + if len(rngParam) > 0 { + rng_info := []string{} + rng := "" + for _, param := range rngParam { + key := strings.Split(param, "=") + rng_info = append(rng_info, fmt.Sprintf("%s=%s", key[0], key[1])) + } + if len(rng_info) > 0 { + rng = strings.Join(rng_info, ",") + params["rng0"] = rng + } + } +} + // Create efi parameter. func (c ConfigQemu) CreateQemuEfiParams(params map[string]interface{}) { efiParam := QemuDeviceParam{} @@ -1614,6 +1643,8 @@ func (p QemuDeviceParam) createDeviceParam( confValue = sValue } else if iValue, ok := value.(int); ok && iValue > 0 { confValue = iValue + } else if iValue, ok := value.(float64); ok && iValue > 0 { + confValue = iValue } if confValue != nil { deviceConf := fmt.Sprintf("%v=%v", key, confValue)