resources: net: Add net resource

This patch adds a net resource for managing nework interfaces, based
around netlink.
This commit is contained in:
jonathangold
2017-12-18 07:18:09 -05:00
committed by Jonathan Gold
parent 8500339ba6
commit 7d7eb3d1cd
7 changed files with 957 additions and 0 deletions

View File

@@ -270,3 +270,27 @@ func GetGID(group string) (int, error) {
return -1, errwrap.Wrapf(err, "group lookup error (%s)", group)
}
// StrSortedSliceCompare takes two lists of strings and returns whether or not
// they are equivalent. It will return nil if both sets contain the same
// elements, regardless of order, and an error if they do not.
func StrSortedSliceCompare(a, b []string) error {
if len(a) != len(b) {
return fmt.Errorf("slices have different lengths: %d vs %d", len(a), len(b))
}
// make a copy of each to sort, so we don't reorder the inputs
x := make([]string, len(a))
y := make([]string, len(b))
copy(x, a)
copy(y, b)
sort.Strings(x)
sort.Strings(y)
for i := range x {
if x[i] != y[i] {
return fmt.Errorf("values do not match: %s vs %s", x[i], y[i])
}
}
return nil
}