func listHostOnlyAdapters(vbox VBoxManager) (map[string]*hostOnlyNetwork, error) {
	out, err := vbox.vbmOut("list", "hostonlyifs")
	if err != nil {
		return nil, err
	}

	byName := map[string]*hostOnlyNetwork{}
	byIP := map[string]*hostOnlyNetwork{}
	n := &hostOnlyNetwork{}

	err = parseKeyValues(out, reColonLine, func(key, val string) error {
		switch key {
		case "Name":
			n.Name = val
		case "GUID":
			n.GUID = val
		case "DHCP":
			n.DHCP = (val != "Disabled")
		case "IPAddress":
			n.IPv4.IP = net.ParseIP(val)
		case "NetworkMask":
			n.IPv4.Mask = parseIPv4Mask(val)
		case "HardwareAddress":
			mac, err := net.ParseMAC(val)
			if err != nil {
				return err
			}
			n.HwAddr = mac
		case "MediumType":
			n.Medium = val
		case "Status":
			n.Status = val
		case "VBoxNetworkName":
			n.NetworkName = val

			if _, present := byName[n.NetworkName]; present {
				return fmt.Errorf("VirtualBox is configured with multiple host-only adapters with the same name %q. Please remove one", n.NetworkName)
			}
			byName[n.NetworkName] = n

			if len(n.IPv4.IP) != 0 {
				if _, present := byIP[n.IPv4.IP.String()]; present {
					return fmt.Errorf("VirtualBox is configured with multiple host-only adapters with the same IP %q. Please remove one", n.IPv4.IP)
				}
				byIP[n.IPv4.IP.String()] = n
			}

			n = &hostOnlyNetwork{}
		}

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

	return byName, nil
}
func listHostOnlyAdapters(vbox VBoxManager) (map[string]*hostOnlyNetwork, error) {
	out, err := vbox.vbmOut("list", "hostonlyifs")
	if err != nil {
		return nil, err
	}

	byName := map[string]*hostOnlyNetwork{}
	byIP := map[string]*hostOnlyNetwork{}
	n := &hostOnlyNetwork{}

	err = parseKeyValues(out, reColonLine, func(key, val string) error {
		switch key {
		case "Name":
			n.Name = val
		case "GUID":
			n.GUID = val
		case "DHCP":
			n.DHCP = (val != "Disabled")
		case "IPAddress":
			n.IPv4.IP = net.ParseIP(val)
		case "NetworkMask":
			n.IPv4.Mask = parseIPv4Mask(val)
		case "HardwareAddress":
			mac, err := net.ParseMAC(val)
			if err != nil {
				return err
			}
			n.HwAddr = mac
		case "MediumType":
			n.Medium = val
		case "Status":
			n.Status = val
		case "VBoxNetworkName":
			n.NetworkName = val

			if _, present := byName[n.NetworkName]; present {
				return fmt.Errorf("VirtualBox is configured with multiple host-only adapters with the same name %q. Please remove one", n.NetworkName)
			}
			byName[n.NetworkName] = n

			if len(n.IPv4.IP) != 0 {
				if _, present := byIP[n.IPv4.IP.String()]; present {
					return fmt.Errorf("VirtualBox is configured with multiple host-only adapters with the same IP %q. Please remove one", n.IPv4.IP)
				}
				byIP[n.IPv4.IP.String()] = n
			}

			n = &hostOnlyNetwork{}
		}

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

	return byName, nil
}
func listHostOnlyAdapters ( vbox VBoxManager ) ( map [ string ] * hostOnlyNetwork , error ) { out , err := vbox . vbmOut ( " " , " " ) if err != nil { return nil , err } byName := map [ string ] * hostOnlyNetwork { } byIP := map [ string ] * hostOnlyNetwork { } n := & hostOnlyNetwork { } err = parseKeyValues ( out , reColonLine , func ( key , val string ) error { switch key { case " " : n . Name = val case " " : n . GUID = val case " " : n . DHCP = ( val != " " ) case " " : n . IPv4 . IP = net . ParseIP ( val ) case " " : n . IPv4 . Mask = parseIPv4Mask ( val ) case " " : mac , err := net . ParseMAC ( val ) if err != nil { return err } n . HwAddr = mac case " " : n . Medium = val case " " : n . Status = val case " " : n . NetworkName = val if _ , present := byName [ n . NetworkName ] ; present { return fmt . Errorf ( " " , n . NetworkName ) } byName [ n . NetworkName ] = n if len ( n . IPv4 . IP ) != 0 { if _ , present := byIP [ n . IPv4 . IP . String ( ) ] ; present { return fmt . Errorf ( " " , n . IPv4 . IP ) } byIP [ n . IPv4 . IP . String ( ) ] = n } n = & hostOnlyNetwork { } } return nil } ) if err != nil { return nil , err } return byName , nil }
// listHostOnlyAdapters gets all host-only adapters in a  map keyed by NetworkName.
listHostOnlyAdapters gets all host - only adapters in a map keyed by NetworkName .