Skip to content

Commit

Permalink
add rng device: to be squashed
Browse files Browse the repository at this point in the history
  • Loading branch information
mabeett committed May 26, 2023
1 parent 6807697 commit 40426cd
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 1 deletion.
2 changes: 2 additions & 0 deletions builder/proxmox/clone/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion builder/proxmox/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: MPL-2.0

//go:generate packer-sdc struct-markdown
//go:generate packer-sdc mapstructure-to-hcl2 -type Config,NICConfig,diskConfig,vgaConfig,additionalISOsConfig,efiConfig
//go:generate packer-sdc mapstructure-to-hcl2 -type Config,NICConfig,diskConfig,rng0Config,vgaConfig,additionalISOsConfig,efiConfig

package proxmox

Expand Down Expand Up @@ -59,6 +59,7 @@ type Config struct {
EFIConfig efiConfig `mapstructure:"efi_config"`
EFIDisk string `mapstructure:"efidisk"`
Machine string `mapstructure:"machine"`
Rng0 rng0Config `mapstructure:"rng0"`
VGA vgaConfig `mapstructure:"vga"`
NICs []NICConfig `mapstructure:"network_adapters"`
Disks []diskConfig `mapstructure:"disks"`
Expand Down Expand Up @@ -114,6 +115,13 @@ type efiConfig struct {
PreEnrolledKeys bool `mapstructure:"pre_enrolled_keys"`
EFIType string `mapstructure:"efi_type"`
}

type rng0Config struct {
Source string `mapstructure:"source"`
MaxBytes int `mapstructure:"max_bytes"`
Period int `mapstructure:"period"`
}

type vgaConfig struct {
Type string `mapstructure:"type"`
Memory int `mapstructure:"memory"`
Expand Down Expand Up @@ -391,6 +399,18 @@ func (c *Config) Prepare(upper interface{}, raws ...interface{}) ([]string, []st
errs = packersdk.MultiErrorAppend(errs, errors.New("efi_storage_pool not set for efi_config"))
}
}
if c.Rng0.Source != "" {
if !(c.Rng0.Source == "/dev/urandom" || c.Rng0.Source == "/dev/random" || c.Rng0.Source == "/dev/hwrng") {
errs = packersdk.MultiErrorAppend(errs, errors.New("source must be one of \"/dev/urandom\", \"/dev/random\", \"/dev/hwrng\""))
}
// FIXME might be not declared by the user then not send to proxmox PVE API
if c.Rng0.MaxBytes < 0 {
errs = packersdk.MultiErrorAppend(errs, errors.New("max_bytes must be greather or equal than 0"))
}
if !(c.Rng0.Period > 0) {
errs = packersdk.MultiErrorAppend(errs, errors.New("period must be greather than 0"))
}
}

if errs != nil && len(errs.Errors) > 0 {
return nil, warnings, errs
Expand Down
29 changes: 29 additions & 0 deletions builder/proxmox/common/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions builder/proxmox/common/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ func TestAdditionalISOs(t *testing.T) {

}

// FIXME Tests for Rng0

func TestSerials(t *testing.T) {
serialsTest := []struct {
name string
Expand Down
14 changes: 14 additions & 0 deletions builder/proxmox/common/step_start_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func (s *stepStartVM) Run(ctx context.Context, state multistep.StateBag) multist
Bios: c.BIOS,
EFIDisk: generateProxmoxEfi(c.EFIConfig),
Machine: c.Machine,
RNGDrive: generateProxmoxRng0(c.Rng0),
QemuVga: generateProxmoxVga(c.VGA),
QemuNetworks: generateProxmoxNetworkAdapters(c.NICs),
QemuDisks: generateProxmoxDisks(c.Disks),
Expand Down Expand Up @@ -295,6 +296,19 @@ func generateProxmoxSerials(serials []string) proxmox.QemuDevices {
return devs
}

func generateProxmoxRng0(rng0 rng0Config) proxmox.QemuDevice {
dev := make(proxmox.QemuDevice)
setDeviceParamIfDefined(dev, "source", rng0.Source)

if rng0.MaxBytes > 0 {
dev["max_bytes"] = rng0.MaxBytes
}
if rng0.Period > 0 {
dev["period"] = rng0.Period
}
return dev
}

func generateProxmoxVga(vga vgaConfig) proxmox.QemuDevice {
dev := make(proxmox.QemuDevice)
setDeviceParamIfDefined(dev, "type", vga.Type)
Expand Down
2 changes: 2 additions & 0 deletions builder/proxmox/iso/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs-partials/builder/proxmox/common/Config-not-required.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

- `machine` (string) - Machine

- `rng0` (rng0Config) - Rng 0

- `vga` (vgaConfig) - VGA

- `network_adapters` ([]NICConfig) - NI Cs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!-- Code generated from the comments of the rng0Config struct in builder/proxmox/common/config.go; DO NOT EDIT MANUALLY -->

- `source` (string) - Source

- `max_bytes` (int) - Max Bytes

- `period` (int) - Period

<!-- End of code generated from the comments of the rng0Config struct in builder/proxmox/common/config.go; -->
17 changes: 17 additions & 0 deletions docs/builders/clone.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,23 @@ or responding to pattern `/dev/.+`. Example:

- `machine` - (string) - Set the machine type. Supported values are 'pc' or 'q35'.

- `rng0` (object) - TODO

```json
{
"source": "xxx",
"max_bytes": xxx,
"period": xx
}
```

- `source` (string) - TODO

- `max_bytes` (int) - TODO

- `period` (int) - TODO


## Example: Cloud-Init enabled Debian

Here is a basic example creating a Debian 10 server image. This assumes
Expand Down
2 changes: 2 additions & 0 deletions docs/builders/iso.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ or responding to pattern `/dev/.+`. Example:

- `machine` - (string) - Set the machine type. Supported values are 'pc' or 'q35'.

- `rng0` (object) - TODO

## Boot Command

@include 'packer-plugin-sdk/bootcommand/BootConfig.mdx'
Expand Down

0 comments on commit 40426cd

Please sign in to comment.