From 96dea8025561b79bd6287baf08f08f3b2ba3f859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= Date: Wed, 22 May 2024 16:15:02 -0400 Subject: [PATCH] incus/network: Align attach-profile with attach MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #870 Signed-off-by: Stéphane Graber --- cmd/incus/network.go | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/cmd/incus/network.go b/cmd/incus/network.go index 84839a876a1..7ca6c145b7f 100644 --- a/cmd/incus/network.go +++ b/cmd/incus/network.go @@ -288,15 +288,27 @@ func (c *cmdNetworkAttachProfile) Run(cmd *cobra.Command, args []string) error { return err } - // Prepare the profile's device entry - device := map[string]string{ - "type": "nic", - "nictype": "macvlan", - "parent": resource.name, - } + // Prepare the instance's device entry + var device map[string]string + if network.Managed && resource.server.HasExtension("instance_nic_network") { + // If network is managed, use the network property rather than nictype, so that the network's + // inherited properties are loaded into the NIC when started. + device = map[string]string{ + "type": "nic", + "network": network.Name, + } + } else { + // If network is unmanaged default to using a macvlan connected to the specified interface. + device = map[string]string{ + "type": "nic", + "nictype": "macvlan", + "parent": resource.name, + } - if network.Type == "bridge" { - device["nictype"] = "bridged" + if network.Type == "bridge" { + // If the network type is an unmanaged bridge, use bridged NIC type. + device["nictype"] = "bridged" + } } if len(args) > 3 {