// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virConnectNumOfInterfaces
341319
func (c *Connect) NumOfInterfaces() (int, error) {
	var err C.virError
	result := int(C.virConnectNumOfInterfacesWrapper(c.ptr, &err))
	if result == -1 {
		return 0, makeError(&err)
	}
	return result, nil
}
123663
func getIPForInterface(name string) (net.IP, error) {
	i, _ := net.InterfaceByName(name)
	addrs, _ := i.Addrs()
	for _, a := range addrs {
		if ipnet, ok := a.(*net.IPNet); ok {
			if ip := ipnet.IP.To4(); ip != nil {
				return ip, nil
			}
		}
	}
	return nil, errors.Errorf("Error finding IPV4 address for %s", name)
}
106937
func (d *Domain) SnapshotNum(flags DomainSnapshotListFlags) (int, error) {
	var err C.virError
	result := int(C.virDomainSnapshotNumWrapper(d.ptr, C.uint(flags), &err))
	if result == -1 {
		return 0, makeError(&err)
	}
	return result, nil
}
606003
func (nc *NetworkContext) allInterfaces() (nics []*InterfaceCreated) {
	nc.slotLock.Lock()
	defer nc.slotLock.Unlock()

	for _, v := range nc.eth {
		if v != nil {
			nics = append(nics, v)
		}
	}
	return
}
423061
func (e Environ) NetworkInterfaces(ctx context.ProviderCallContext, instId instance.Id) ([]network.InterfaceInfo, error) {
	instance, err := e.env.Details(instId)
	if err != nil {
		return nil, err
	}

	if len(instance.Networking) == 0 {
		return []network.InterfaceInfo{}, nil
	}
	subnetInfo, err := e.getSubnetInfoAsMap()
	if err != nil {
		return nil, errors.Trace(err)
	}
	nicAttributes := e.getNicAttributes(instance)

	interfaces := make([]network.InterfaceInfo, 0, len(instance.Networking))
	idx := 0
	for nicName, nicObj := range instance.Networking {
		// gsamfira: While the API may hold any alphanumeric NIC name
		// of up to 4 characters, inside an ubuntu instance,
		// the NIC will always be named eth0 (where 0 is the index of the NIC).
		// NICs inside the instance will be ordered in the same way the API
		// returns them; i.e. first element returned by the API will be eth0,
		// second element will be eth1 and so on. Sorting is done
		// alphanumerically it makes sense to use the name that will be
		// seen by the juju agent instead of the name that shows up
		// in the provider.
		// TODO (gsamfira): Check NIC naming in CentOS and Windows.
		name := fmt.Sprintf("eth%s", strconv.Itoa(idx))
		deviceIndex := idx

		idx += 1

		deviceAttributes, ok := nicAttributes[nicName]
		if !ok {
			return nil, errors.Errorf(
				"failed to get NIC attributes for %q", nicName)
		}
		mac, ip, err := GetMacAndIP(deviceAttributes.Address)
		if err != nil {
			return nil, err
		}
		addr := network.NewScopedAddress(ip, network.ScopeCloudLocal)
		nic := network.InterfaceInfo{
			InterfaceName: name,
			DeviceIndex:   deviceIndex,
			ProviderId:    network.Id(deviceAttributes.Id),
			MACAddress:    mac,
			Address:       addr,
			InterfaceType: network.EthernetInterface,
		}

		// gsamfira: VEthernet NICs are connected to shared networks
		// I have not found a way to interrogate details about the shared
		// networks available inside the oracle cloud. There is some
		// documentation on the matter here:
		//
		// https://docs.oracle.com/cloud-machine/latest/stcomputecs/ELUAP/GUID-8CBE0F4E-E376-4C93-BB56-884836273168.htm
		//
		// but I have not been able to get any information about the
		// shared networks using the resources described there.
		// We only populate Space information for NICs attached to
		// IPNetworks (user defined)
		if nicObj.GetType() == common.VNic {
			nicSubnetDetails := subnetInfo[deviceAttributes.Ipnetwork]
			nic.ProviderSpaceId = nicSubnetDetails.SpaceProviderId
			nic.ProviderSubnetId = nicSubnetDetails.ProviderId
			nic.CIDR = nicSubnetDetails.CIDR
		}
		interfaces = append(interfaces, nic)
	}

	return interfaces, nil
}
682260
func (o *VPort) HostInterfaces(info *bambou.FetchingInfo) (HostInterfacesList, *bambou.Error) {

	var list HostInterfacesList
	err := bambou.CurrentSession().FetchChildren(o, HostInterfaceIdentity, &list, info)
	return list, err
}
151917
func toInterfaceAddresses(networks []customNetwork) (addresses []boship.InterfaceAddress) {
	for _, network := range networks {
		addresses = append(addresses, network.ToInterfaceAddress())
	}
	return
}
1003229
func GetAllInterfaces() (IfAddrs, error) {
	ifs, err := net.Interfaces()
	if err != nil {
		return nil, err
	}

	ifAddrs := make(IfAddrs, 0, len(ifs))
	for _, intf := range ifs {
		addrs, err := intf.Addrs()
		if err != nil {
			return nil, err
		}

		for _, addr := range addrs {
			var ipAddr IPAddr
			ipAddr, err = NewIPAddr(addr.String())
			if err != nil {
				return IfAddrs{}, fmt.Errorf("unable to create an IP address from %q", addr.String())
			}

			ifAddr := IfAddr{
				SockAddr:  ipAddr,
				Interface: intf,
			}
			ifAddrs = append(ifAddrs, ifAddr)
		}
	}

	return ifAddrs, nil
}
1006350
func (r Network_Vlan) GetTotalPrimaryIpAddressCount() (resp uint, err error) {
	err = r.Session.DoRequest("SoftLayer_Network_Vlan", "getTotalPrimaryIpAddressCount", nil, &r.Options, &resp)
	return
}
642694
func (o *VPort) VNFInterfaces(info *bambou.FetchingInfo) (VNFInterfacesList, *bambou.Error) {

	var list VNFInterfacesList
	err := bambou.CurrentSession().FetchChildren(o, VNFInterfaceIdentity, &list, info)
	return list, err
}
1134076
func (p *propInterfaces) GetFirstInterface() *Interface {
	if len(p.Interfaces) == 0 {
		return nil
	}
	return &p.Interfaces[0]
}
1275294
func (r Network_Component) GetInterface() (resp datatypes.Network_Bandwidth_Version1_Interface, err error) {
	err = r.Session.DoRequest("SoftLayer_Network_Component", "getInterface", nil, &r.Options, &resp)
	return
}
1475
func (ncc *SeesawNCC) LBInterfaceInit(iface *ncctypes.LBInterface, out *int) error {
	netIface, err := iface.Interface()
	if err != nil {
		return fmt.Errorf("Failed to get network interface: %v", err)
	}
	nodeIface, err := net.InterfaceByName(iface.NodeInterface)
	if err != nil {
		return fmt.Errorf("Failed to get node interface: %v", err)
	}

	if iface.RoutingTableID < 1 || iface.RoutingTableID > 250 {
		return fmt.Errorf("Invalid routing table ID: %d", iface.RoutingTableID)
	}

	vmac, err := net.ParseMAC(vrrpMAC)
	if err != nil {
		return fmt.Errorf("Failed to parse VRRP MAC %q: %v", vrrpMAC, err)
	}

	// The last byte of the VRRP MAC is determined by the VRID.
	vmac[len(vmac)-1] = iface.VRID
	netIface.HardwareAddr = vmac

	log.Infof("Initialising load balancing interface %s - VRID %d (VMAC %s)", iface.Name, iface.VRID, vmac)

	// Ensure interface is down and set VMAC address.
	if err := ifaceFastDown(netIface); err != nil {
		return fmt.Errorf("Failed to down interface: %v", err)
	}
	if err := ifaceSetMAC(netIface); err != nil {
		return fmt.Errorf("Failed to set MAC: %v", err)
	}

	// Remove VLAN interfaces associated with the load balancing interface.
	if err := ifaceFlushVLANs(netIface); err != nil {
		return fmt.Errorf("Failed to flush VLAN interfaces: %v", err)
	}

	// Configure sysctls for load balancing.
	if err := sysctlInitLB(nodeIface, netIface); err != nil {
		return fmt.Errorf("Failed to initialise sysctls: %v", err)
	}

	// Flush existing IP addresses and add cluster VIPs.
	if err := ifaceFlushIPAddr(netIface); err != nil {
		return fmt.Errorf("Failed to flush IP addresses: %v", err)
	}

	if iface.ClusterVIP.IPv4Addr != nil {
		if err := addClusterVIP(iface, netIface, nodeIface, iface.ClusterVIP.IPv4Addr); err != nil {
			return fmt.Errorf("Failed to add IPv4 cluster VIP: %v", err)
		}
	}
	if iface.ClusterVIP.IPv6Addr != nil {
		if err := addClusterVIP(iface, netIface, nodeIface, iface.ClusterVIP.IPv6Addr); err != nil {
			return fmt.Errorf("Failed to add IPv6 cluster VIP: %v", err)
		}
	}

	// Initialise iptables rules.
	if err := iptablesInit(iface.ClusterVIP); err != nil {
		return err
	}

	// Setup dummy interface.
	dummyIface, err := net.InterfaceByName(iface.DummyInterface)
	if err != nil {
		return fmt.Errorf("Failed to get dummy interface: %v", err)
	}
	if err := ifaceFastDown(dummyIface); err != nil {
		return fmt.Errorf("Failed to down dummy interface: %v", err)
	}
	if err := ifaceFlushIPAddr(dummyIface); err != nil {
		return fmt.Errorf("Failed to flush dummy interface: %v", err)
	}
	if err := ifaceUp(dummyIface); err != nil {
		return fmt.Errorf("Failed to up dummy interface: %v", err)
	}

	return nil
}
1081351
func (env *maasEnviron) NetworkInterfaces(ctx context.ProviderCallContext, instId instance.Id) ([]network.InterfaceInfo, error) {
	inst, err := env.getInstance(ctx, instId)
	if err != nil {
		return nil, errors.Trace(err)
	}
	subnetsMap, err := env.subnetToSpaceIds(ctx)
	if err != nil {
		return nil, errors.Trace(err)
	}
	if env.usingMAAS2() {
		dnsSearchDomains, err := env.Domains(ctx)
		if err != nil {
			return nil, errors.Trace(err)
		}
		return maas2NetworkInterfaces(ctx, inst.(*maas2Instance), subnetsMap, dnsSearchDomains...)
	} else {
		mi := inst.(*maas1Instance)
		return maasObjectNetworkInterfaces(ctx, mi.maasObject, subnetsMap)
	}
}
352884
func (c *Connect) NumOfSecrets() (int, error) {
	var err C.virError
	result := int(C.virConnectNumOfSecretsWrapper(c.ptr, &err))
	if result == -1 {
		return 0, makeError(&err)
	}
	return result, nil
}
559236
func addrsForInterface(iface *net.Interface) ([]net.IP, []net.IP) {
	var v4, v6, v6local []net.IP

	addrs, _ := iface.Addrs()
	for _, address := range addrs {
		if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
			if ipnet.IP.To4() != nil {
				v4 = append(v4, ipnet.IP)
			} else {
				switch ip := ipnet.IP.To16(); ip != nil {
				case ip.IsGlobalUnicast():
					v6 = append(v6, ipnet.IP)
				case ip.IsLinkLocalUnicast():
					v6local = append(v6local, ipnet.IP)
				}
			}
		}
	}
	if len(v6) == 0 {
		v6 = v6local
	}
	return v4, v6
}
1214269
func (_class VIFClass) GetNetwork(sessionID SessionRef, self VIFRef) (_retval NetworkRef, _err error) {
	_method := "VIF.get_network"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_selfArg, _err := convertVIFRefToXen(fmt.Sprintf("%s(%s)", _method, "self"), self)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg, _selfArg)
	if _err != nil {
		return
	}
	_retval, _err = convertNetworkRefToGo(_method + " -> ", _result.Value)
	return
}