From cae654bf5d50284490a8b501f5d802f9bd4ca31b Mon Sep 17 00:00:00 2001 From: Everton Marques Date: Fri, 10 Mar 2017 10:59:47 -0300 Subject: [PATCH] Handle FortiOS devices with vdom. --- dev/model_fortios.go | 9 ++++++++- dev/model_fortios_test.go | 7 +++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/dev/model_fortios.go b/dev/model_fortios.go index 72b91ce..12d95ed 100644 --- a/dev/model_fortios.go +++ b/dev/model_fortios.go @@ -18,7 +18,14 @@ func registerModelFortiOS(logger hasPrintf, t *DeviceTable) { */ // preferred method for disabling pager - a.CommandList = []string{"config system console", "set output standard", "end", "get system status", "show"} + a.CommandList = []string{ + "config system global", // enter config: valid only for vdom + "config system console", // enter config: valid only for non-vdom + "set output standard", // disable paging + "end", // exit config + "get system status", // system information + "show", // get configuration + } promptPattern := `\S+\s#\s$` // "hostname # " a.DisabledPromptPattern = promptPattern diff --git a/dev/model_fortios_test.go b/dev/model_fortios_test.go index 5d92ed2..3ed2525 100644 --- a/dev/model_fortios_test.go +++ b/dev/model_fortios_test.go @@ -15,6 +15,7 @@ import ( type optionsFortiOS struct { requestPassword bool breakConn bool + vdom bool } func TestFortiOS1(t *testing.T) { @@ -57,7 +58,7 @@ func TestFortiOS2(t *testing.T) { // launch bogus test server addr := ":2002" - s, listenErr := spawnServerFortiOS(t, addr, optionsFortiOS{}) + s, listenErr := spawnServerFortiOS(t, addr, optionsFortiOS{vdom: true}) if listenErr != nil { t.Errorf("could not spawn bogus FortiOS server: %v", listenErr) } @@ -214,7 +215,9 @@ LOOP: break LOOP case strings.HasPrefix(str, "ex"): //exit break LOOP - case strings.HasPrefix(str, "config system console"): + case !options.vdom && strings.HasPrefix(str, "config system console"): + config = true + case options.vdom && strings.HasPrefix(str, "config system global"): config = true case strings.HasPrefix(str, "end"): config = false