// See also https://libvirt.org/html/libvirt-libvirt-network.html#virConnectNumOfNetworks
508675
func (c *Connect) NumOfNetworks() (int, error) {
	var err C.virError
	result := int(C.virConnectNumOfNetworksWrapper(c.ptr, &err))
	if result == -1 {
		return 0, makeError(&err)
	}
	return result, nil
}
338652
func (vm *VM) getVirtualNetworkClient() (virtualnetwork.VirtualNetworkClient, error) {
	c, err := vm.getClient()
	if err != nil {
		return virtualnetwork.VirtualNetworkClient{}, err
	}

	return virtualnetwork.NewClient(c), nil
}
885115
func (d *PacketFilter) NumberOfConns() int {
	d.mut.Lock()
	n := len(d.conns)
	d.mut.Unlock()
	return n
}
342509
func (daemon *Daemon) getAllNetworks() []libnetwork.Network {
	c := daemon.netController
	if c == nil {
		return nil
	}
	return c.Networks()
}
1262558
func (c *container) connectWithNetworks(adHoc bool) {
	containerNetworks := c.Networks()
	for name, params := range containerNetworks {
		network := cfg.Network(name)
		if network == nil {
			panic(StatusError{fmt.Errorf("Error when parsing network `%v`: container network is not in main networks block.\n", name), 78})
		}
		networkName := network.ActualName()
		args := []string{"network", "connect"}
		for _, alias := range params.Alias(c.Name()) {
			args = append(args, "--alias", alias)
		}
		if len(params.Ip()) > 0 {
			args = append(args, "--ip", params.Ip())
		}
		if len(params.Ip6()) > 0 {
			args = append(args, "--ip6", params.Ip6())
		}
		args = append(args, networkName, c.ActualName(adHoc))
		executeCommand("docker", args, c.CommandsOut(), c.CommandsErr())
	}
}
1297833
func (daemon *Daemon) GetNetworks(filter filters.Args, config types.NetworkListConfig) ([]types.NetworkResource, error) {
	networks := daemon.getAllNetworks()

	list := make([]types.NetworkResource, 0, len(networks))
	var idx map[string]libnetwork.Network
	if config.Detailed {
		idx = make(map[string]libnetwork.Network)
	}

	for _, n := range networks {
		nr := buildNetworkResource(n)
		list = append(list, nr)
		if config.Detailed {
			idx[nr.ID] = n
		}
	}

	var err error
	list, err = internalnetwork.FilterNetworks(list, filter)
	if err != nil {
		return nil, err
	}

	if config.Detailed {
		for i, n := range list {
			np := &n
			buildDetailedNetworkResources(np, idx[n.ID], config.Verbose)
			list[i] = *np
		}
	}

	return list, nil
}
1357127
func Convert_v1_NetNamespaceList_To_network_NetNamespaceList(in *v1.NetNamespaceList, out *network.NetNamespaceList, s conversion.Scope) error {
	return autoConvert_v1_NetNamespaceList_To_network_NetNamespaceList(in, out, s)
}
942995
func (c *Connect) ListNWFilters() ([]string, error) {
	const maxFilters = 1024
	var names [maxFilters](*C.char)
	namesPtr := unsafe.Pointer(&names)
	var err C.virError
	numNWFilters := C.virConnectListNWFiltersWrapper(
		c.ptr,
		(**C.char)(namesPtr),
		maxFilters, &err)
	if numNWFilters == -1 {
		return nil, makeError(&err)
	}
	goNames := make([]string, numNWFilters)
	for k := 0; k < int(numNWFilters); k++ {
		goNames[k] = C.GoString(names[k])
		C.free(unsafe.Pointer(names[k]))
	}
	return goNames, nil
}
449122
func (c *Connect) LookupNetworkByName(name string) (*Network, error) {
	cName := C.CString(name)
	defer C.free(unsafe.Pointer(cName))
	var err C.virError
	ptr := C.virNetworkLookupByNameWrapper(c.ptr, cName, &err)
	if ptr == nil {
		return nil, makeError(&err)
	}
	return &Network{ptr: ptr}, nil
}
435543
func (vm VirtualMachine) NicByNetworkID(networkID UUID) *Nic {
	for _, nic := range vm.Nic {
		if nic.NetworkID.Equal(networkID) {
			n := nic
			n.VirtualMachineID = vm.ID
			return &n
		}
	}
	return nil
}
332498
func (r *rpcServer) GetNetworkInfo(ctx context.Context,
	_ *lnrpc.NetworkInfoRequest) (*lnrpc.NetworkInfo, error) {

	graph := r.server.chanDB.ChannelGraph()

	var (
		numNodes             uint32
		numChannels          uint32
		maxChanOut           uint32
		totalNetworkCapacity btcutil.Amount
		minChannelSize       btcutil.Amount = math.MaxInt64
		maxChannelSize       btcutil.Amount
		medianChanSize       btcutil.Amount
	)

	// We'll use this map to de-duplicate channels during our traversal.
	// This is needed since channels are directional, so there will be two
	// edges for each channel within the graph.
	seenChans := make(map[uint64]struct{})

	// We also keep a list of all encountered capacities, in order to
	// calculate the median channel size.
	var allChans []btcutil.Amount

	// We'll run through all the known nodes in the within our view of the
	// network, tallying up the total number of nodes, and also gathering
	// each node so we can measure the graph diameter and degree stats
	// below.
	if err := graph.ForEachNode(nil, func(tx *bbolt.Tx, node *channeldb.LightningNode) error {
		// Increment the total number of nodes with each iteration.
		numNodes++

		// For each channel we'll compute the out degree of each node,
		// and also update our running tallies of the min/max channel
		// capacity, as well as the total channel capacity. We pass
		// through the db transaction from the outer view so we can
		// re-use it within this inner view.
		var outDegree uint32
		if err := node.ForEachChannel(tx, func(_ *bbolt.Tx,
			edge *channeldb.ChannelEdgeInfo, _, _ *channeldb.ChannelEdgePolicy) error {

			// Bump up the out degree for this node for each
			// channel encountered.
			outDegree++

			// If we've already seen this channel, then we'll
			// return early to ensure that we don't double-count
			// stats.
			if _, ok := seenChans[edge.ChannelID]; ok {
				return nil
			}

			// Compare the capacity of this channel against the
			// running min/max to see if we should update the
			// extrema.
			chanCapacity := edge.Capacity
			if chanCapacity < minChannelSize {
				minChannelSize = chanCapacity
			}
			if chanCapacity > maxChannelSize {
				maxChannelSize = chanCapacity
			}

			// Accumulate the total capacity of this channel to the
			// network wide-capacity.
			totalNetworkCapacity += chanCapacity

			numChannels++

			seenChans[edge.ChannelID] = struct{}{}
			allChans = append(allChans, edge.Capacity)
			return nil
		}); err != nil {
			return err
		}

		// Finally, if the out degree of this node is greater than what
		// we've seen so far, update the maxChanOut variable.
		if outDegree > maxChanOut {
			maxChanOut = outDegree
		}

		return nil
	}); err != nil {
		return nil, err
	}

	// Find the median.
	medianChanSize = autopilot.Median(allChans)

	// If we don't have any channels, then reset the minChannelSize to zero
	// to avoid outputting NaN in encoded JSON.
	if numChannels == 0 {
		minChannelSize = 0
	}

	// TODO(roasbeef): graph diameter

	// TODO(roasbeef): also add oldest channel?
	netInfo := &lnrpc.NetworkInfo{
		MaxOutDegree:         maxChanOut,
		AvgOutDegree:         float64(2*numChannels) / float64(numNodes),
		NumNodes:             numNodes,
		NumChannels:          numChannels,
		TotalNetworkCapacity: int64(totalNetworkCapacity),
		AvgChannelSize:       float64(totalNetworkCapacity) / float64(numChannels),

		MinChannelSize:       int64(minChannelSize),
		MaxChannelSize:       int64(maxChannelSize),
		MedianChannelSizeSat: int64(medianChanSize),
	}

	// Similarly, if we don't have any channels, then we'll also set the
	// average channel size to zero in order to avoid weird JSON encoding
	// outputs.
	if numChannels == 0 {
		netInfo.AvgChannelSize = 0
	}

	return netInfo, nil
}
387432
func (r Network_Component) GetNetworkVlanTrunks() (resp []datatypes.Network_Component_Network_Vlan_Trunk, err error) {
	err = r.Session.DoRequest("SoftLayer_Network_Component", "getNetworkVlanTrunks", nil, &r.Options, &resp)
	return
}
185941
func (c *Calcium) ListNetworks(ctx context.Context, podname string, driver string) ([]*enginetypes.Network, error) {
	networks := []*enginetypes.Network{}
	nodes, err := c.ListPodNodes(ctx, podname, false)
	if err != nil {
		return networks, err
	}

	if len(nodes) == 0 {
		return networks, types.NewDetailedErr(types.ErrPodNoNodes, podname)
	}

	drivers := []string{}
	if driver != "" {
		drivers = append(drivers, driver)
	}

	node := nodes[0]
	return node.Engine.NetworkList(ctx, drivers)
}
1011639
func (d *driver) getNetworks() []*network {
	d.Lock()
	defer d.Unlock()

	ls := make([]*network, 0, len(d.networks))
	for _, nw := range d.networks {
		ls = append(ls, nw)
	}

	return ls
}
970166
func (_m *Cluster) ListNetworks(ctx context.Context, podname string, driver string) ([]*enginetypes.Network, error) {
	ret := _m.Called(ctx, podname, driver)

	var r0 []*enginetypes.Network
	if rf, ok := ret.Get(0).(func(context.Context, string, string) []*enginetypes.Network); ok {
		r0 = rf(ctx, podname, driver)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).([]*enginetypes.Network)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(context.Context, string, string) error); ok {
		r1 = rf(ctx, podname, driver)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
643440
func (c *Connect) NumOfDevices(cap string, flags uint32) (int, error) {
	ccap := C.CString(cap)
	defer C.free(unsafe.Pointer(ccap))
	var err C.virError
	result := int(C.virNodeNumOfDevicesWrapper(c.ptr, ccap, C.uint(flags), &err))
	if result == -1 {
		return 0, makeError(&err)
	}
	return result, nil
}
1232811
func (daemon *Daemon) GetNetworksByIDPrefix(partialID string) []libnetwork.Network {
	c := daemon.netController
	if c == nil {
		return nil
	}
	list := []libnetwork.Network{}
	l := func(nw libnetwork.Network) bool {
		if strings.HasPrefix(nw.ID(), partialID) {
			list = append(list, nw)
		}
		return false
	}
	c.WalkNetworks(l)

	return list
}