func (nm *NetlinkMonitor) ensureBridge(link *netlink.Bridge) canvas.Node { b := nm.g.NodeByPath("b:" + link.Attrs().Name) if b == nil { a := canvas.NewBridgeAdapter(link) node := canvas.NewAdapterNode(a) node.SetID(nm.g.NewNodeID()) nm.g.AddNode(node) b = node } return b }
// handleModulePost processes creation of a new Module func (s *HoverServer) handleModulePost(r *http.Request) routeResponse { var req api.Module if err := json.NewDecoder(r.Body).Decode(&req); err != nil { panic(err) } id := s.g.NewNodeID() stub := canvas.NewNodeBase(id, -1, "stub:", strconv.Itoa(id), 1) s.g.AddNode(&stub) adapter, err := canvas.NewAdapter(req.ModuleBase, s.g, id) if err != nil { panic(err) } node := canvas.NewAdapterNode(adapter) s.adapterEntries.Add(node) node.SetID(id) s.g.RemoveNode(&stub) s.g.AddNode(node) s.patchPanel.modules.Set(strconv.Itoa(node.ID()), strconv.Itoa(node.FD())) s.recomputePolicies() entry := adapterToModuleEntry(adapter) return routeResponse{body: entry} }