diff --git a/builder/libvirt/network/network.go b/builder/libvirt/network/network.go index 8a4c239..ae721ca 100644 --- a/builder/libvirt/network/network.go +++ b/builder/libvirt/network/network.go @@ -25,6 +25,7 @@ type NetworkInterface struct { Bridge BridgeNetworkInterface `mapstructure:",squash"` Managed ManagedNetworkInterface `mapstructure:",squash"` + User UserNetworkInterface `mapstructure:",squash"` } func (ni *NetworkInterface) PrepareConfig(ctx *interpolate.Context) (warnings []string, errs []error) { @@ -46,6 +47,8 @@ func (ni *NetworkInterface) PrepareConfig(ctx *interpolate.Context) (warnings [] w, e = ni.Managed.PrepareConfig(ctx) case "bridge": w, e = ni.Bridge.PrepareConfig(ctx) + case "user": + w, e = ni.User.PrepareConfig(ctx) default: errs = append(errs, fmt.Errorf("unsupported network interface type '%s'", ni.Type)) return @@ -78,6 +81,8 @@ func (ni NetworkInterface) DomainInterface() *libvirtxml.DomainInterface { ni.Bridge.UpdateDomainInterface(&domainInterface) case "managed": ni.Managed.UpdateDomainInterface(&domainInterface) + case "user": + ni.User.UpdateDomainInterface(&domainInterface) } return &domainInterface diff --git a/builder/libvirt/network/user.go b/builder/libvirt/network/user.go new file mode 100644 index 0000000..f302e77 --- /dev/null +++ b/builder/libvirt/network/user.go @@ -0,0 +1,23 @@ +package network + +import ( + "github.com/hashicorp/packer-plugin-sdk/template/interpolate" + "libvirt.org/go/libvirtxml" +) + +type UserNetworkInterface struct { + Dev string `mapstructure:"dev" required:"false"` +} + +func (ni *UserNetworkInterface) PrepareConfig(ctx *interpolate.Context) (warnings []string, errs []error) { + if ni.Dev == "" { + } + return +} + +func (ni *UserNetworkInterface) UpdateDomainInterface(domainInterface *libvirtxml.DomainInterface) { + domainInterface.Source = &libvirtxml.DomainInterfaceSource{ + User: &libvirtxml.DomainInterfaceSourceUser{ + }, + } +} \ No newline at end of file diff --git a/docs/builders/libvirt.mdx b/docs/builders/libvirt.mdx index 2f05300..5f1f16e 100644 --- a/docs/builders/libvirt.mdx +++ b/docs/builders/libvirt.mdx @@ -250,7 +250,7 @@ volume { ### Network Network interfaces can be attached to a builder domain by adding a `network_interface { }` block for each. -Currently only `managed` and `bridge` networks are supported. +Currently only `managed`, `bridge`, and `user` networks are supported. @include 'builder/libvirt/network/NetworkInterface-required.mdx' @include 'builder/libvirt/network/NetworkInterface-not-required.mdx' @@ -293,6 +293,13 @@ network_interface { } ``` +For usermode networking +```hcl +network_interface { + type = "user" +} +``` + ### Graphics and video, headless domains Libvirt builder creates a headless domain by default with no video card or monitor attached to it. Most linux distributions and cloud images are fine with this setup, but you might need to add a video card and a graphical interface to your machine.