cord-776 create build / runtime containers for autmation uservices
Change-Id: I246973192adef56a250ffe93a5f65fff488840c1
diff --git a/automation/vendor/github.com/juju/utils/network.go b/automation/vendor/github.com/juju/utils/network.go
new file mode 100644
index 0000000..505a6e9
--- /dev/null
+++ b/automation/vendor/github.com/juju/utils/network.go
@@ -0,0 +1,46 @@
+// Copyright 2013 Canonical Ltd.
+// Licensed under the LGPLv3, see LICENCE file for details.
+
+package utils
+
+import (
+ "fmt"
+ "net"
+
+ "github.com/juju/loggo"
+)
+
+var logger = loggo.GetLogger("juju.utils")
+
+// GetIPv4Address iterates through the addresses expecting the format from
+// func (ifi *net.Interface) Addrs() ([]net.Addr, error)
+func GetIPv4Address(addresses []net.Addr) (string, error) {
+ for _, addr := range addresses {
+ ip, _, err := net.ParseCIDR(addr.String())
+ if err != nil {
+ return "", err
+ }
+ ipv4 := ip.To4()
+ if ipv4 == nil {
+ continue
+ }
+ return ipv4.String(), nil
+ }
+ return "", fmt.Errorf("no addresses match")
+}
+
+// GetAddressForInterface looks for the network interface
+// and returns the IPv4 address from the possible addresses.
+func GetAddressForInterface(interfaceName string) (string, error) {
+ iface, err := net.InterfaceByName(interfaceName)
+ if err != nil {
+ logger.Errorf("cannot find network interface %q: %v", interfaceName, err)
+ return "", err
+ }
+ addrs, err := iface.Addrs()
+ if err != nil {
+ logger.Errorf("cannot get addresses for network interface %q: %v", interfaceName, err)
+ return "", err
+ }
+ return GetIPv4Address(addrs)
+}