Skip to content
Open
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 builder/libvirt/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions builder/libvirt/network/user.go
Original file line number Diff line number Diff line change
@@ -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{
},
}
}
9 changes: 8 additions & 1 deletion docs/builders/libvirt.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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.
Expand Down