github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/provider/oracle/network/util.go (about)

     1  // Copyright 2017 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package network
     5  
     6  import (
     7  	"net"
     8  
     9  	"github.com/juju/errors"
    10  )
    11  
    12  // GetMacAndIp is a helper function that returns a mac and an IP,
    13  // given a list of strings containing both. This type of array
    14  // is returned by the oracle API as part of instance details.
    15  func GetMacAndIP(address []string) (mac string, ip string, err error) {
    16  	if address == nil {
    17  		err = errors.New("Empty address slice given")
    18  		return
    19  	}
    20  	for _, val := range address {
    21  		valIp := net.ParseIP(val)
    22  		if valIp != nil {
    23  			ip = val
    24  			continue
    25  		}
    26  		if _, err = net.ParseMAC(val); err != nil {
    27  			err = errors.Errorf("The address is not an mac neither an ip %s", val)
    28  			break
    29  		}
    30  		mac = val
    31  	}
    32  	return
    33  }