summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--guestmetric/guestmetric_linux.go14
-rw-r--r--xe-daemon/xe-daemon.go12
2 files changed, 19 insertions, 7 deletions
diff --git a/guestmetric/guestmetric_linux.go b/guestmetric/guestmetric_linux.go
index da0515f..b4553b2 100644
--- a/guestmetric/guestmetric_linux.go
+++ b/guestmetric/guestmetric_linux.go
@@ -79,26 +79,31 @@ func EnumNetworkAddresses(iface string) (GuestMetric, error) {
const (
IP_RE string = `(\d{1,3}\.){3}\d{1,3}`
IPV6_RE string = `[\da-f:]+[\da-f]`
+ MAC_RE string = `[\da-fA-F:]+`
)
var (
+ IP_MAC_ADDR_RE = regexp.MustCompile(`link\/ether\s*(` + MAC_RE + `)`)
IP_IPV4_ADDR_RE = regexp.MustCompile(`inet\s*(` + IP_RE + `).*\se[a-zA-Z0-9]+[\s\n]`)
IP_IPV6_ADDR_RE = regexp.MustCompile(`inet6\s*(` + IPV6_RE + `)`)
IFCONFIG_IPV4_ADDR_RE = regexp.MustCompile(`inet addr:\s*(` + IP_RE + `)`)
IFCONFIG_IPV6_ADDR_RE = regexp.MustCompile(`inet6 addr:\s*(` + IPV6_RE + `)`)
+ IFCONFIG_MAC_ADDR_RE = regexp.MustCompile(`HWaddr\s*(` + MAC_RE + `)`)
)
d := make(GuestMetric, 0)
- var v4re, v6re *regexp.Regexp
+ var v4re, v6re, macre *regexp.Regexp
var out string
var err error
if out, err = runCmd("ip", "addr", "show", iface); err == nil {
v4re = IP_IPV4_ADDR_RE
v6re = IP_IPV6_ADDR_RE
+ macre = IP_MAC_ADDR_RE
} else if out, err = runCmd("ifconfig", iface); err == nil {
v4re = IFCONFIG_IPV4_ADDR_RE
v6re = IFCONFIG_IPV6_ADDR_RE
+ macre = IFCONFIG_MAC_ADDR_RE
} else {
return nil, fmt.Errorf("Cannot find ip/ifconfig command")
}
@@ -115,6 +120,13 @@ func EnumNetworkAddresses(iface string) (GuestMetric, error) {
d[fmt.Sprintf("ipv6/%d/addr", i)] = parts[1]
}
}
+
+ m = macre.FindAllStringSubmatch(out, -1)
+ if m != nil {
+ for i, parts := range m {
+ d[fmt.Sprintf("mac/%d", i)] = parts[1]
+ }
+ }
return d, nil
}
diff --git a/xe-daemon/xe-daemon.go b/xe-daemon/xe-daemon.go
index eaee8c7..7b07873 100644
--- a/xe-daemon/xe-daemon.go
+++ b/xe-daemon/xe-daemon.go
@@ -128,12 +128,12 @@ func main() {
}
}
}
- if count%DivisorLeastMultiple == 0 {
- if cx, ok := xs.(*xenstoreclient.CachedXenStore); ok {
- err := cx.InvalidCacheFlush()
- if err != nil {
- logger.Printf("InvalidCacheFlush error: %#v\n", err)
- }
+ }
+ if count%DivisorLeastMultiple == 0 {
+ if cx, ok := xs.(*xenstoreclient.CachedXenStore); ok {
+ err := cx.InvalidCacheFlush()
+ if err != nil {
+ logger.Printf("InvalidCacheFlush error: %#v\n", err)
}
}
}