From 9d1604a1c96ea5de4ba3c968008c349a1dccae1b Mon Sep 17 00:00:00 2001 From: David Edler Date: Fri, 8 Nov 2024 10:58:47 +0100 Subject: [PATCH] Network: add target parameter for GET 1.0/networks and network_get_target api extension. fixes #14406 Signed-off-by: David Edler --- doc/api-extensions.md | 4 ++++ lxd/networks.go | 11 +++++++++++ shared/version/api.go | 1 + 3 files changed, 16 insertions(+) diff --git a/doc/api-extensions.md b/doc/api-extensions.md index 9ec7dcfe6a63..7865f1263610 100644 --- a/doc/api-extensions.md +++ b/doc/api-extensions.md @@ -2520,3 +2520,7 @@ contains the total available logical CPUs available when LXD started. ## `vm_limits_cpu_pin_strategy` Adds a new {config:option}`instance-resource-limits:limits.cpu.pin_strategy` configuration option for virtual machines. This option controls the CPU pinning strategy. When set to `none`, CPU auto pinning is disabled. When set to `auto`, CPU auto pinning is enabled. + +## `network_get_target` + +Adds optional `target` parameter to `GET /1.0/network`. When target is set, forward the request to the specified cluster member and return the non managed interfaces from that member. diff --git a/lxd/networks.go b/lxd/networks.go index a86710f465d9..08c8fbdf7a35 100644 --- a/lxd/networks.go +++ b/lxd/networks.go @@ -200,6 +200,11 @@ func networkAccessHandler(entitlement auth.Entitlement) func(d *Daemon, r *http. // description: Project name // type: string // example: default +// - in: query +// name: target +// description: Cluster member name +// type: string +// example: lxd01 // responses: // "200": // description: API endpoints @@ -231,6 +236,12 @@ func networkAccessHandler(entitlement auth.Entitlement) func(d *Daemon, r *http. func networksGet(d *Daemon, r *http.Request) response.Response { s := d.State() + // If a target was specified, forward the request to the relevant node. + resp := forwardedResponseIfTargetIsRemote(s, r) + if resp != nil { + return resp + } + requestProjectName := request.ProjectParam(r) effectiveProjectName, reqProject, err := project.NetworkProject(s.DB.Cluster, requestProjectName) if err != nil { diff --git a/shared/version/api.go b/shared/version/api.go index 84a109007f67..a654b85c9cf2 100644 --- a/shared/version/api.go +++ b/shared/version/api.go @@ -423,6 +423,7 @@ var APIExtensions = []string{ "network_ovn_uplink_vlan", "state_logical_cpus", "vm_limits_cpu_pin_strategy", + "network_get_target", } // APIExtensionsCount returns the number of available API extensions.