[lxc-devel] [lxd/master] network: Move and rename isOnBridge
stgraber on Github
lxc-bot at linuxcontainers.org
Fri Sep 16 22:56:32 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160916/f42ad6d7/attachment.bin>
-------------- next part --------------
From 64e369f817bd9e170761a75466c7cbf33e9ac57e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 6 Sep 2016 23:16:50 -0400
Subject: [PATCH] network: Move and rename isOnBridge
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/networks.go | 54 ++++++++++++++++++++++++++++--------------------------
1 file changed, 28 insertions(+), 26 deletions(-)
diff --git a/lxd/networks.go b/lxd/networks.go
index f705f6e..cfd1e72 100644
--- a/lxd/networks.go
+++ b/lxd/networks.go
@@ -12,6 +12,33 @@ import (
"github.com/lxc/lxd/shared"
)
+// Helper functions
+func networkIsInUse(c container, name string) bool {
+ devices := c.ExpandedDevices()
+ for _, name := range devices.DeviceNames() {
+ device := devices[name]
+
+ if device["type"] != "nic" {
+ continue
+ }
+
+ if !shared.StringInSlice(device["nictype"], []string{"bridged", "macvlan"}) {
+ continue
+ }
+
+ if device["parent"] == "" {
+ continue
+ }
+
+ if device["parent"] == name {
+ return true
+ }
+ }
+
+ return false
+}
+
+// API endpoints
func networksGet(d *Daemon, r *http.Request) Response {
recursionStr := r.FormValue("recursion")
recursion, err := strconv.Atoi(recursionStr)
@@ -54,31 +81,6 @@ type network struct {
UsedBy []string `json:"used_by"`
}
-func isOnBridge(c container, bridge string) bool {
- devices := c.ExpandedDevices()
- for _, name := range devices.DeviceNames() {
- device := devices[name]
-
- if device["type"] != "nic" {
- continue
- }
-
- if !shared.StringInSlice(device["nictype"], []string{"bridged", "macvlan"}) {
- continue
- }
-
- if device["parent"] == "" {
- continue
- }
-
- if device["parent"] == bridge {
- return true
- }
- }
-
- return false
-}
-
func networkGet(d *Daemon, r *http.Request) Response {
name := mux.Vars(r)["name"]
@@ -113,7 +115,7 @@ func doNetworkGet(d *Daemon, name string) (network, error) {
return network{}, err
}
- if isOnBridge(c, n.Name) {
+ if networkIsInUse(c, n.Name) {
n.UsedBy = append(n.UsedBy, fmt.Sprintf("/%s/containers/%s", shared.APIVersion, ct))
}
}
More information about the lxc-devel
mailing list