[lxc-devel] [lxd/master] Networks: Adds mtu and vlan options for macvlan and sriov networks
tomponline on Github
lxc-bot at linuxcontainers.org
Mon Jul 27 16:40:16 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 642 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200727/80600f56/attachment.bin>
-------------- next part --------------
From a03b2edbc6b6ceaf5b15d9d4f4b1d9244c9af7ab Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 27 Jul 2020 17:10:14 +0100
Subject: [PATCH 01/12] shared/validate: Adds Optional() validate wrapper
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
shared/validate/validate.go | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/shared/validate/validate.go b/shared/validate/validate.go
index 224f8ff9d1..0ebbec75a3 100644
--- a/shared/validate/validate.go
+++ b/shared/validate/validate.go
@@ -20,6 +20,17 @@ func stringInSlice(key string, list []string) bool {
return false
}
+// Optional wraps a validator function to make it an optional field.
+func Optional(f func(value string) error) func(value string) error {
+ return func(value string) error {
+ if value == "" {
+ return nil
+ }
+
+ return f(value)
+ }
+}
+
// IsInt64 validates whether the string can be converted to an int64.
func IsInt64(value string) error {
if value == "" {
From 01ce2230aee60cf3706b550bc56eb9240662d256 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 27 Jul 2020 17:16:20 +0100
Subject: [PATCH 02/12] shared/validate: Makes IsInt64 non-optional
Expected to use validate.Optional() wrapper.
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
shared/validate/validate.go | 4 ----
1 file changed, 4 deletions(-)
diff --git a/shared/validate/validate.go b/shared/validate/validate.go
index 0ebbec75a3..61912b7b47 100644
--- a/shared/validate/validate.go
+++ b/shared/validate/validate.go
@@ -33,10 +33,6 @@ func Optional(f func(value string) error) func(value string) error {
// IsInt64 validates whether the string can be converted to an int64.
func IsInt64(value string) error {
- if value == "" {
- return nil
- }
-
_, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return fmt.Errorf("Invalid value for an integer %q", value)
From bf18e9c535603dfb91eefb1a9e4e33e906ed947f Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 27 Jul 2020 17:16:50 +0100
Subject: [PATCH 03/12] lxd/network/driver/bridge: Add validate.Optional()
wrapper for validate.IsInt64 usage
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/network/driver_bridge.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lxd/network/driver_bridge.go b/lxd/network/driver_bridge.go
index f87585e333..e92772fdd9 100644
--- a/lxd/network/driver_bridge.go
+++ b/lxd/network/driver_bridge.go
@@ -152,7 +152,7 @@ func (n *bridge) Validate(config map[string]string) error {
return validate.IsNetworkMAC(value)
},
- "bridge.mtu": validate.IsInt64,
+ "bridge.mtu": validate.Optional(validate.IsInt64),
"bridge.mode": func(value string) error {
return validate.IsOneOf(value, []string{"standard", "fan"})
},
@@ -252,7 +252,7 @@ func (n *bridge) Validate(config map[string]string) error {
case "group":
rules[k] = validate.IsNetworkAddress
case "id":
- rules[k] = validate.IsInt64
+ rules[k] = validate.Optional(validate.IsInt64)
case "inteface":
rules[k] = ValidNetworkName
case "ttl":
From 85d327cd5fc648e8356c6117514e79d596108a79 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 27 Jul 2020 17:17:24 +0100
Subject: [PATCH 04/12] lxd/storage/utils: Adds validate.Optional() wrapper for
validate.IsInt64 usage
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/storage/utils.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lxd/storage/utils.go b/lxd/storage/utils.go
index f6fb3e40d7..9c93f8e69c 100644
--- a/lxd/storage/utils.go
+++ b/lxd/storage/utils.go
@@ -479,7 +479,7 @@ func validateVolumeCommonRules(vol drivers.Volume) map[string]func(string) error
// volatile.rootfs.size is only used for image volumes.
if vol.Type() == drivers.VolumeTypeImage {
- rules["volatile.rootfs.size"] = validate.IsInt64
+ rules["volatile.rootfs.size"] = validate.Optional(validate.IsInt64)
}
return rules
From 363359fb6862d0b35198fbff8cc7e613a1bd9759 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 27 Jul 2020 17:17:54 +0100
Subject: [PATCH 05/12] shared/instance: Adds validate.Optional() wrapper for
validate.IsInt64 usage
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
shared/instance.go | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/shared/instance.go b/shared/instance.go
index 4dba7607ac..9ba5760dcf 100644
--- a/shared/instance.go
+++ b/shared/instance.go
@@ -72,10 +72,10 @@ var HugePageSizeSuffix = [...]string{"64KB", "1MB", "2MB", "1GB"}
// given value is syntactically legal.
var KnownInstanceConfigKeys = map[string]func(value string) error{
"boot.autostart": validate.IsBool,
- "boot.autostart.delay": validate.IsInt64,
- "boot.autostart.priority": validate.IsInt64,
- "boot.stop.priority": validate.IsInt64,
- "boot.host_shutdown_timeout": validate.IsInt64,
+ "boot.autostart.delay": validate.Optional(validate.IsInt64),
+ "boot.autostart.priority": validate.Optional(validate.IsInt64),
+ "boot.stop.priority": validate.Optional(validate.IsInt64),
+ "boot.host_shutdown_timeout": validate.Optional(validate.IsInt64),
"limits.cpu": func(value string) error {
if value == "" {
@@ -172,7 +172,7 @@ var KnownInstanceConfigKeys = map[string]func(value string) error{
"limits.network.priority": validate.IsPriority,
- "limits.processes": validate.IsInt64,
+ "limits.processes": validate.Optional(validate.IsInt64),
"linux.kernel_modules": validate.IsAny,
From 29af215073d02b49e38f6c86b3b388a73fd316f8 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 27 Jul 2020 17:31:57 +0100
Subject: [PATCH 06/12] lxd/device/device/utils/network: Removes
networkValidVLAN
Being moved into shared/validate.
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/device/device_utils_network.go | 14 --------------
1 file changed, 14 deletions(-)
diff --git a/lxd/device/device_utils_network.go b/lxd/device/device_utils_network.go
index f74af864c9..7d112c2696 100644
--- a/lxd/device/device_utils_network.go
+++ b/lxd/device/device_utils_network.go
@@ -551,20 +551,6 @@ func networkValidGateway(value string) error {
return fmt.Errorf("Invalid gateway: %s", value)
}
-// networkValidVLAN validates a VLAN ID.
-func networkValidVLAN(value string) error {
- vlanID, err := strconv.Atoi(value)
- if err != nil {
- return fmt.Errorf("Invalid VLAN ID: %s", value)
- }
-
- if vlanID < 0 || vlanID > 4094 {
- return fmt.Errorf("Out of range (0-4094) VLAN ID: %s", value)
- }
-
- return nil
-}
-
// networkValidVLANList validates a comma delimited list of VLAN IDs.
func networkValidVLANList(value string) error {
for _, vlanID := range strings.Split(value, ",") {
From a1f23902e840071eafbd2ef4d9670c8b3045f63a Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 27 Jul 2020 17:32:21 +0100
Subject: [PATCH 07/12] shared/validate: Adds IsNetworkVLAN
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
shared/validate/validate.go | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/shared/validate/validate.go b/shared/validate/validate.go
index 61912b7b47..586f0c9e35 100644
--- a/shared/validate/validate.go
+++ b/shared/validate/validate.go
@@ -350,3 +350,17 @@ func IsNetworkV6List(value string) error {
return nil
}
+
+// IsNetworkVLAN validates a VLAN ID.
+func IsNetworkVLAN(value string) error {
+ vlanID, err := strconv.Atoi(value)
+ if err != nil {
+ return fmt.Errorf("Invalid VLAN ID: %s", value)
+ }
+
+ if vlanID < 0 || vlanID > 4094 {
+ return fmt.Errorf("Out of range (0-4094) VLAN ID: %s", value)
+ }
+
+ return nil
+}
From 6c666877ee442c802dbc2df94d64baf206969ae7 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 27 Jul 2020 17:32:43 +0100
Subject: [PATCH 08/12] lxd/device/device/utils/network: validate.IsNetworkVLAN
usage
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/device/device_utils_network.go | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lxd/device/device_utils_network.go b/lxd/device/device_utils_network.go
index 7d112c2696..01306bd716 100644
--- a/lxd/device/device_utils_network.go
+++ b/lxd/device/device_utils_network.go
@@ -23,6 +23,7 @@ import (
"github.com/lxc/lxd/shared"
"github.com/lxc/lxd/shared/logger"
"github.com/lxc/lxd/shared/units"
+ "github.com/lxc/lxd/shared/validate"
)
// Instances can be started in parallel, so lock the creation of VLANs.
@@ -555,7 +556,7 @@ func networkValidGateway(value string) error {
func networkValidVLANList(value string) error {
for _, vlanID := range strings.Split(value, ",") {
vlanID = strings.TrimSpace(vlanID)
- err := networkValidVLAN(vlanID)
+ err := validate.IsNetworkVLAN(vlanID)
if err != nil {
return err
}
From 8a390baed5bcf21af61567daf4ba4087e317cb22 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 27 Jul 2020 17:33:28 +0100
Subject: [PATCH 09/12] lxd/device/nic: validate.IsNetworkVLAN usage
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/device/nic.go | 2 +-
lxd/device/nic_bridged.go | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/lxd/device/nic.go b/lxd/device/nic.go
index b94d672f17..09ec02cf23 100644
--- a/lxd/device/nic.go
+++ b/lxd/device/nic.go
@@ -12,7 +12,7 @@ func nicValidationRules(requiredFields []string, optionalFields []string) map[st
"parent": validate.IsAny,
"network": validate.IsAny,
"mtu": validate.IsAny,
- "vlan": networkValidVLAN,
+ "vlan": validate.IsNetworkVLAN,
"hwaddr": validate.IsNetworkMAC,
"host_name": validate.IsAny,
"limits.ingress": validate.IsAny,
diff --git a/lxd/device/nic_bridged.go b/lxd/device/nic_bridged.go
index 0317386e4e..aaa375f3af 100644
--- a/lxd/device/nic_bridged.go
+++ b/lxd/device/nic_bridged.go
@@ -32,6 +32,7 @@ import (
"github.com/lxc/lxd/shared/api"
log "github.com/lxc/lxd/shared/log15"
"github.com/lxc/lxd/shared/logger"
+ "github.com/lxc/lxd/shared/validate"
)
type nicBridged struct {
@@ -166,7 +167,7 @@ func (d *nicBridged) validateConfig(instConf instance.ConfigReader) error {
return nil
}
- return networkValidVLAN(value)
+ return validate.IsNetworkVLAN(value)
}
// Add bridge specific vlan.tagged validation.
From 104547b7e190f5d3e8e50e0ea8e382c1438befda Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 27 Jul 2020 17:33:49 +0100
Subject: [PATCH 10/12] lxd/network/driver: Adds mtu and vlan support for
macvlan and sriov network types
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/network/driver_macvlan.go | 2 ++
lxd/network/driver_sriov.go | 2 ++
2 files changed, 4 insertions(+)
diff --git a/lxd/network/driver_macvlan.go b/lxd/network/driver_macvlan.go
index c1061a379d..549672049d 100644
--- a/lxd/network/driver_macvlan.go
+++ b/lxd/network/driver_macvlan.go
@@ -26,6 +26,8 @@ func (n *macvlan) Validate(config map[string]string) error {
return nil
},
+ "mtu": validate.Optional(validate.IsInt64),
+ "vlan": validate.Optional(validate.IsNetworkVLAN),
"maas.subnet.ipv4": validate.IsAny,
"maas.subnet.ipv6": validate.IsAny,
}
diff --git a/lxd/network/driver_sriov.go b/lxd/network/driver_sriov.go
index 3d09b3e639..87eb4f37e5 100644
--- a/lxd/network/driver_sriov.go
+++ b/lxd/network/driver_sriov.go
@@ -26,6 +26,8 @@ func (n *sriov) Validate(config map[string]string) error {
return nil
},
+ "mtu": validate.Optional(validate.IsInt64),
+ "vlan": validate.Optional(validate.IsNetworkVLAN),
"maas.subnet.ipv4": validate.IsAny,
"maas.subnet.ipv6": validate.IsAny,
}
From 5d312f9284848c296d71a7cc299c4f97f486a29a Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 27 Jul 2020 17:34:23 +0100
Subject: [PATCH 11/12] lxd/device/nic: Inherit mtu and vlan settings from
network for macvlan and sriov NICs
If network option used.
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/device/nic_macvlan.go | 4 ++--
lxd/device/nic_sriov.go | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lxd/device/nic_macvlan.go b/lxd/device/nic_macvlan.go
index 9941fccea9..788584f2cd 100644
--- a/lxd/device/nic_macvlan.go
+++ b/lxd/device/nic_macvlan.go
@@ -41,7 +41,7 @@ func (d *nicMACVLAN) validateConfig(instConf instance.ConfigReader) error {
if d.config["network"] != "" {
requiredFields = append(requiredFields, "network")
- bannedKeys := []string{"nictype", "parent", "mtu", "maas.subnet.ipv4", "maas.subnet.ipv6"}
+ bannedKeys := []string{"nictype", "parent", "mtu", "vlan", "maas.subnet.ipv4", "maas.subnet.ipv6"}
for _, bannedKey := range bannedKeys {
if d.config[bannedKey] != "" {
return fmt.Errorf("Cannot use %q property in conjunction with %q property", bannedKey, "network")
@@ -68,7 +68,7 @@ func (d *nicMACVLAN) validateConfig(instConf instance.ConfigReader) error {
d.config["parent"] = netConfig["parent"]
// Copy certain keys verbatim from the network's settings.
- inheritKeys := []string{"maas.subnet.ipv4", "maas.subnet.ipv6"}
+ inheritKeys := []string{"mtu", "vlan", "maas.subnet.ipv4", "maas.subnet.ipv6"}
for _, inheritKey := range inheritKeys {
if _, found := netConfig[inheritKey]; found {
d.config[inheritKey] = netConfig[inheritKey]
diff --git a/lxd/device/nic_sriov.go b/lxd/device/nic_sriov.go
index 83f7294254..6bfcf3bd4d 100644
--- a/lxd/device/nic_sriov.go
+++ b/lxd/device/nic_sriov.go
@@ -51,7 +51,7 @@ func (d *nicSRIOV) validateConfig(instConf instance.ConfigReader) error {
if d.config["network"] != "" {
requiredFields = append(requiredFields, "network")
- bannedKeys := []string{"nictype", "parent", "mtu", "maas.subnet.ipv4", "maas.subnet.ipv6"}
+ bannedKeys := []string{"nictype", "parent", "mtu", "vlan", "maas.subnet.ipv4", "maas.subnet.ipv6"}
for _, bannedKey := range bannedKeys {
if d.config[bannedKey] != "" {
return fmt.Errorf("Cannot use %q property in conjunction with %q property", bannedKey, "network")
@@ -78,7 +78,7 @@ func (d *nicSRIOV) validateConfig(instConf instance.ConfigReader) error {
d.config["parent"] = netConfig["parent"]
// Copy certain keys verbatim from the network's settings.
- inheritKeys := []string{"maas.subnet.ipv4", "maas.subnet.ipv6"}
+ inheritKeys := []string{"mtu", "vlan", "maas.subnet.ipv4", "maas.subnet.ipv6"}
for _, inheritKey := range inheritKeys {
if _, found := netConfig[inheritKey]; found {
d.config[inheritKey] = netConfig[inheritKey]
From 5a497e5d827e179ca3f8cf6ab1f4b7b9b1f13170 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 27 Jul 2020 17:37:43 +0100
Subject: [PATCH 12/12] doc/networks: Adds mtu and vlan options for macvlan and
sriov network types
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
doc/networks.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/doc/networks.md b/doc/networks.md
index 00cd21063d..23d4ea2770 100644
--- a/doc/networks.md
+++ b/doc/networks.md
@@ -226,6 +226,8 @@ Network configuration properties:
Key | Type | Condition | Default | Description
:-- | :-- | :-- | :-- | :--
parent | string | - | - | Parent interface to create macvlan NICs on
+mtu | integer | - | - | The MTU of the new interface
+vlan | integer | - | - | The VLAN ID to attach to
maas.subnet.ipv4 | string | ipv4 address | - | MAAS IPv4 subnet to register instances in (when using `network` property on nic)
maas.subnet.ipv6 | string | ipv6 address | - | MAAS IPv6 subnet to register instances in (when using `network` property on nic)
@@ -240,5 +242,7 @@ Network configuration properties:
Key | Type | Condition | Default | Description
:-- | :-- | :-- | :-- | :--
parent | string | - | - | Parent interface to create sriov NICs on
+mtu | integer | - | - | The MTU of the new interface
+vlan | integer | - | - | The VLAN ID to attach to
maas.subnet.ipv4 | string | ipv4 address | - | MAAS IPv4 subnet to register instances in (when using `network` property on nic)
maas.subnet.ipv6 | string | ipv6 address | - | MAAS IPv6 subnet to register instances in (when using `network` property on nic)
More information about the lxc-devel
mailing list