From df860e11435241582fafd1fbd47649cdf4823ba6 Mon Sep 17 00:00:00 2001 From: Ma Shimiao Date: Tue, 23 Aug 2016 16:13:34 +0800 Subject: [PATCH] validate: add network host-specific check Signed-off-by: Ma Shimiao --- cmd/ocitools/validate.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/cmd/ocitools/validate.go b/cmd/ocitools/validate.go index 246979aab..c172fc998 100644 --- a/cmd/ocitools/validate.go +++ b/cmd/ocitools/validate.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "io/ioutil" + "net" "os" "path" "path/filepath" @@ -397,6 +398,26 @@ func checkLinuxResources(r rspec.Resources, hostCheck bool) (msgs []string) { msgs = append(msgs, fmt.Sprintf("Minimum memory limit should be larger than memory reservation")) } } + if r.Network != nil && hostCheck { + var exist bool + interfaces, err := net.Interfaces() + if err != nil { + msgs = append(msgs, err.Error()) + return + } + for _, prio := range r.Network.Priorities { + exist = false + for _, ni := range interfaces { + if prio.Name == ni.Name { + exist = true + break + } + } + if !exist { + msgs = append(msgs, fmt.Sprintf("Interface %s does not exist on host", prio.Name)) + } + } + } return }