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

Network: add mtu setting #501

Merged
merged 1 commit into from Mar 4, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions libvirt/network.go
Expand Up @@ -166,3 +166,11 @@ func getDomainFromResource(d *schema.ResourceData) *libvirtxml.NetworkDomain {

return domain
}

func getMTUFromResource(d *schema.ResourceData) *libvirtxml.NetworkMTU {
if mtu, ok := d.GetOk("mtu"); ok {
return &libvirtxml.NetworkMTU{Size: uint(mtu.(int))}
}

return nil
}
11 changes: 11 additions & 0 deletions libvirt/resource_libvirt_network.go
Expand Up @@ -68,6 +68,11 @@ func resourceLibvirtNetwork() *schema.Resource {
Computed: true,
ForceNew: false,
},
"mtu": {
Type: schema.TypeInt,
Optional: true,
Required: false,
},
"addresses": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -366,6 +371,8 @@ func resourceLibvirtNetworkCreate(d *schema.ResourceData, meta interface{}) erro
// use a bridge provided by the user, or create one otherwise (libvirt will assign on automatically when empty)
networkDef.Bridge = getBridgeFromResource(d)

networkDef.MTU = getMTUFromResource(d)

// check the network mode
networkDef.Forward = &libvirtxml.NetworkForward{
Mode: getNetModeFromResource(d),
Expand Down Expand Up @@ -518,6 +525,10 @@ func resourceLibvirtNetworkRead(d *schema.ResourceData, meta interface{}) error
d.Set("name", networkDef.Name)
d.Set("bridge", networkDef.Bridge.Name)

if networkDef.MTU != nil {
d.Set("mtu", networkDef.MTU.Size)
}

if networkDef.Forward != nil {
d.Set("mode", networkDef.Forward.Mode)
}
Expand Down
28 changes: 28 additions & 0 deletions libvirt/resource_libvirt_network_test.go
Expand Up @@ -474,3 +474,31 @@ func TestAccLibvirtNetwork_Autostart(t *testing.T) {
},
})
}

func TestAccLibvirtNetwork_MTU(t *testing.T) {
var network libvirt.Network
randomNetworkResource := acctest.RandString(10)
randomNetworkName := acctest.RandString(10)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLibvirtNetworkDestroy,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(`
resource "libvirt_network" "%s" {
name = "%s"
mode = "nat"
domain = "k8s.local"
addresses = ["10.17.3.0/24"]
autostart = true
mtu = 9999
}`, randomNetworkResource, randomNetworkName),
Check: resource.ComposeTestCheckFunc(
testAccCheckNetworkExists("libvirt_network."+randomNetworkResource, &network),
resource.TestCheckResourceAttr("libvirt_network."+randomNetworkResource, "mtu", "9999"),
),
},
},
})
}
7 changes: 7 additions & 0 deletions website/docs/r/network.markdown
Expand Up @@ -34,6 +34,10 @@ resource "libvirt_network" "kube_network" {
# (only necessary in "bridge" mode)
# bridge = "br7"

# (optional) the MTU for the network. If not supplied, the underlying device's
# default is used (usually 1500)
# mtu = 9000

# (Optional) DNS configuration
dns {
# (Optional, default false)
Expand Down Expand Up @@ -111,6 +115,9 @@ The following arguments are supported:
* `bridge` - (Optional) The bridge device defines the name of a bridge
device which will be used to construct the virtual network (when not provided,
it will be automatically obtained by libvirt in `none`, `nat` and `route` modes).
* `mtu` - (Optional) The MTU to set for the underlying network interfaces. When
not supplied, libvirt will use the default for the interface, usually 1500.
Libvirt version 5.1 and greater will advertise this value to nodes via DHCP.
* `autostart` - (Optional) Set to `true` to start the network on host boot up.
If not specified `false` is assumed.
* `routes` - (Optional) a list of static routes. A `cidr` and a `gateway` must
Expand Down