Skip to content

Commit 8fb36e4

Browse files
authored
Change establish session to allow for several commands (#20)
Fixes #6
1 parent 21db0a8 commit 8fb36e4

File tree

7 files changed

+14
-7
lines changed

7 files changed

+14
-7
lines changed

pkg/netrasp/asa.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ type asa struct {
1111

1212
// Dial opens a connection to a device.
1313
func (a asa) Dial(ctx context.Context) error {
14-
return establishConnection(ctx, a, a.Connection, a.basePrompt(), "no terminal pager")
14+
return establishConnection(ctx, a, a.Connection, a.basePrompt(), []string{"no terminal pager"})
1515
}

pkg/netrasp/helpers.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"regexp"
77
)
88

9-
func establishConnection(ctx context.Context, p Platform, c connection, prompt *regexp.Regexp, disablePager string) error {
9+
func establishConnection(ctx context.Context, p Platform, c connection, prompt *regexp.Regexp, preparationCommands []string) error {
1010
err := c.Dial(ctx)
1111
if err != nil {
1212
return fmt.Errorf("unable to open connection: %w", err)
@@ -19,9 +19,11 @@ func establishConnection(ctx context.Context, p Platform, c connection, prompt *
1919
return fmt.Errorf("unable to find the initial prompt: %w", err)
2020
}
2121

22-
_, err = p.Run(ctx, disablePager)
23-
if err != nil {
24-
return fmt.Errorf("unable to disable terminal paging: %w", err)
22+
for _, command := range preparationCommands {
23+
output, err := p.Run(ctx, command)
24+
if err != nil {
25+
return fmt.Errorf("unable to prepare session using the command '%s': %w", output, err)
26+
}
2527
}
2628

2729
return nil

pkg/netrasp/ios.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ func (i ios) Configure(ctx context.Context, commands []string) (string, error) {
4646

4747
// Dial opens a connection to a device.
4848
func (i ios) Dial(ctx context.Context) error {
49-
return establishConnection(ctx, i, i.Connection, i.basePrompt(), "terminal length 0")
49+
commands := []string{"terminal length 0", "terminal width 511"}
50+
51+
return establishConnection(ctx, i, i.Connection, i.basePrompt(), commands)
5052
}
5153

5254
// Enable elevates privileges.

pkg/netrasp/sros.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (s sros) Configure(ctx context.Context, commands []string) (string, error)
4848

4949
// Dial opens a connection to a device.
5050
func (s sros) Dial(ctx context.Context) error {
51-
return establishConnection(ctx, s, s.Connection, s.basePrompt(), "environment more false")
51+
return establishConnection(ctx, s, s.Connection, s.basePrompt(), []string{"environment more false"})
5252
}
5353

5454
// Enable elevates privileges.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
router1#
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
router1#
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sr#

0 commit comments

Comments
 (0)