-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from nitinsoniism/junos_shell_adaptation
Junos Regex and config load fixes. Adds another example.
- Loading branch information
Showing
4 changed files
with
91 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
|
||
"github.com/scrapli/scrapligo/driver/base" | ||
"github.com/scrapli/scrapligo/driver/core" | ||
"github.com/scrapli/scrapligo/cfg" | ||
) | ||
|
||
//Pushes config from a file to a file on device and | ||
//loads it to the device. Cleans up afterwords. | ||
func main() { | ||
d, err := core.NewCoreDriver( | ||
"hostname", | ||
"juniper_junos", | ||
base.WithPort(22), | ||
base.WithAuthUsername("root"), | ||
base.WithAuthPassword("password"), | ||
) | ||
|
||
if err != nil { | ||
fmt.Printf("failed to create driver; error: %+v\n", err) | ||
return | ||
} | ||
|
||
err = d.Open() | ||
if err != nil { | ||
fmt.Printf("failed to open driver; error: %+v\n", err) | ||
return | ||
} | ||
defer d.Close() | ||
|
||
c, err := cfg.NewCfgDriver( | ||
d, | ||
"juniper_junos", | ||
) | ||
if err != nil { | ||
fmt.Printf("failed to create cfg driver; error: %+v\n", err) | ||
return | ||
} | ||
|
||
b, err := ioutil.ReadFile("sample.conf") | ||
if err != nil { | ||
fmt.Print(err) | ||
} | ||
fmt.Print(string(b)) | ||
|
||
prepareErr := c.Prepare() | ||
if prepareErr != nil { | ||
fmt.Printf("failed running prepare method: %v", prepareErr) | ||
} | ||
|
||
_, err = c.LoadConfig( | ||
string(b), | ||
false, //don't load replace. Load merge/set instead | ||
) | ||
if err != nil { | ||
fmt.Printf("failed to load config; error: %+v\n", err) | ||
return | ||
} | ||
|
||
_, err = c.CommitConfig() | ||
if err != nil { | ||
fmt.Printf("failed to commit config; error: %+v\n", err) | ||
return | ||
} | ||
fmt.Printf("Done loading config\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
interfaces { | ||
ge-0/0/1 { | ||
unit 0 { | ||
family inet { | ||
address 192.168.100.1/24; | ||
} | ||
} | ||
} | ||
} | ||
|