Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support VM VirtIO-based Random Number Generator configuration #263

Merged
merged 1 commit into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ createQemu JSON Sample:
"tag": -1
}
},
"rng0": {
"source": "/dev/urandom",
"max_bytes": "1024",
"period": "1000"
},
"usb": {
"0": {
"host": "0658:0200",
Expand Down
31 changes: 31 additions & 0 deletions proxmox/config_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{}
}
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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)
Expand Down