[lxc-devel] [lxd/master] Allow for stable host interface names

stgraber on Github lxc-bot at linuxcontainers.org
Fri Apr 21 22:27:55 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170421/db6d4517/attachment.bin>
-------------- next part --------------
From 8644747f8ac41900328643855dec177b64520661 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 21 Apr 2017 18:26:17 -0400
Subject: [PATCH] Allow for stable host interface names
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #3143

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 doc/containers.md    | 21 +++++++++++----------
 lxd/container_lxc.go |  8 +++++++-
 shared/container.go  |  4 ++++
 3 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/doc/containers.md b/doc/containers.md
index b0e9c3d..af2f354 100644
--- a/doc/containers.md
+++ b/doc/containers.md
@@ -54,16 +54,17 @@ user.\*                              | string    | -             | n/a
 
 The following volatile keys are currently internally used by LXD:
 
-Key                         | Type      | Default       | Description
-:--                         | :---      | :------       | :----------
-volatile.\<name\>.hwaddr    | string    | -             | Network device MAC address (when no hwaddr property is set on the device itself)
-volatile.\<name\>.name      | string    | -             | Network device name (when no name propery is set on the device itself)
-volatile.apply\_template    | string    | -             | The name of a template hook which should be triggered upon next startup
-volatile.base\_image        | string    | -             | The hash of the image the container was created from, if any.
-volatile.idmap.base         | integer   | -             | The first id in the container's primary idmap range
-volatile.idmap.next         | string    | -             | The idmap to use next time the container starts
-volatile.last\_state.idmap  | string    | -             | Serialized container uid/gid map
-volatile.last\_state.power  | string    | -             | Container state as of last host shutdown
+Key                             | Type      | Default       | Description
+:--                             | :---      | :------       | :----------
+volatile.\<name\>.hwaddr        | string    | -             | Network device MAC address (when no hwaddr property is set on the device itself)
+volatile.\<name\>.name          | string    | -             | Network device name (when no name propery is set on the device itself)
+volatile.\<name\>.host\_name    | string    | -             | Network device name on the host (for nictype=bridged or nictype=p2p)
+volatile.apply\_template        | string    | -             | The name of a template hook which should be triggered upon next startup
+volatile.base\_image            | string    | -             | The hash of the image the container was created from, if any.
+volatile.idmap.base             | integer   | -             | The first id in the container's primary idmap range
+volatile.idmap.next             | string    | -             | The idmap to use next time the container starts
+volatile.last\_state.idmap      | string    | -             | Serialized container uid/gid map
+volatile.last\_state.power      | string    | -             | Container state as of last host shutdown
 
 
 Additionally, those user keys have become common with images (support isn't guaranteed):
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 4ed8847..a897c7a 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -5832,7 +5832,7 @@ func (c *containerLXC) fillNetworkDevice(name string, m types.Device) (types.Dev
 		newDevice["hwaddr"] = volatileHwaddr
 	}
 
-	// File in the name
+	// Fill in the name
 	if m["name"] == "" {
 		configKey := fmt.Sprintf("volatile.%s.name", name)
 		volatileName := c.localConfig[configKey]
@@ -5862,6 +5862,12 @@ func (c *containerLXC) fillNetworkDevice(name string, m types.Device) (types.Dev
 		newDevice["name"] = volatileName
 	}
 
+	// Fill in the host name (but don't generate a static one ourselves)
+	if m["host_name"] == "" && shared.StringInSlice(m["nictype"], []string{"bridged", "p2p"}) {
+		configKey := fmt.Sprintf("volatile.%s.host_name", name)
+		newDevice["host_name"] = c.localConfig[configKey]
+	}
+
 	return newDevice, nil
 }
 
diff --git a/shared/container.go b/shared/container.go
index 038a7cb..11e78fd 100644
--- a/shared/container.go
+++ b/shared/container.go
@@ -211,6 +211,10 @@ func ConfigKeyChecker(key string) (func(value string) error, error) {
 		if strings.HasSuffix(key, ".name") {
 			return IsAny, nil
 		}
+
+		if strings.HasSuffix(key, ".host_name") {
+			return IsAny, nil
+		}
 	}
 
 	if strings.HasPrefix(key, "environment.") {


More information about the lxc-devel mailing list