Beispiel #1
0
func Example_diff2() {

	app, c := setup_diff()

	f := func(s string) {
		if err := command.Dispatch(app, s, c, command.CONF, false); err != nil {
			log.Printf("dispatch: [%s]: %v", s, err)
		}
	}

	f("hostname bgp1")
	f("hostname bgp2")
	f("router bgp 1 neighbor 1.1.1.1 remote-as 1")
	f("router bgp 1 neighbor 2.2.2.2 remote-as 1")
	f("router bgp 1 neighbor 3.3.3.3 remote-as 2")
	f("router bgp 2 neighbor 3.3.3.3 remote-as 2")
	f("router bgp 2 neighbor 4.4.4.4 remote-as 2")
	f("router bgp 2 neighbor 4.4.4.4 remote-as 3")

	if err := command.Dispatch(app, "commit", c, command.CONF, false); err != nil {
		log.Printf("dispatch: [commit]: %v", err)
	}

	nonet := "no router bgp 1"
	if err := command.CmdNo(app, nil, nonet, c); err != nil {
		log.Printf("cmd failed: [%s] error=[%v]", nonet, err)
		return
	}

	command.WriteConfig(app.confRootCandidate, &outputWriter{})
	// Output:
	// hostname bgp2
	// router bgp 2 neighbor 3.3.3.3 remote-as 2
	// router bgp 2 neighbor 4.4.4.4 remote-as 3
}
Beispiel #2
0
func Example_diff1() {

	app, c := setup_diff()

	f := func(s string) {
		if err := command.Dispatch(app, s, c, command.CONF, false); err != nil {
			log.Printf("dispatch: [%s]: %v", s, err)
		}
	}

	f("hostname bgp1")
	f("hostname bgp2")
	f("router bgp 1 neighbor 1.1.1.1 description  A  BB   C")
	f("router bgp 1 neighbor 1.1.1.1 description  AA  BB   C")
	f("router bgp 1 neighbor 1.1.1.1 remote-as 1")
	f("router bgp 1 neighbor 2.2.2.2 remote-as 1")
	f("router bgp 1 neighbor 3.3.3.3 remote-as 2")
	f("router bgp 2 neighbor 3.3.3.3 remote-as 2")
	f("router bgp 2 neighbor 4.4.4.4 remote-as 2")
	f("router bgp 2 neighbor 4.4.4.4 remote-as 3")

	command.WriteConfig(app.confRootCandidate, &outputWriter{})
	// Output:
	// hostname bgp2
	// router bgp 1 neighbor 1.1.1.1 description  AA  BB   C
	// router bgp 1 neighbor 1.1.1.1 remote-as 1
	// router bgp 1 neighbor 2.2.2.2 remote-as 1
	// router bgp 1 neighbor 3.3.3.3 remote-as 2
	// router bgp 2 neighbor 3.3.3.3 remote-as 2
	// router bgp 2 neighbor 4.4.4.4 remote-as 3
}
Beispiel #3
0
func Example_diff2() {

	app, c := setup_diff()

	f := func(s string) {
		if err := command.Dispatch(app, s, c, command.CONF, false); err != nil {
			log.Printf("dispatch: [%s]: %v", s, err)
		}
	}

	f("hostname rip1")
	f("hostname rip2")
	f("router rip network 1.1.1.0/24")
	f("router rip network 1.1.2.0/24")
	f("router rip network 1.1.3.0/24 cost 2")
	f("router rip network 1.1.4.0/24 cost 15")
	f("router rip vrf X network 1.1.1.0/24")
	f("router rip vrf X network 1.1.2.0/24")
	f("router rip vrf X network 1.1.3.0/24 cost 3")
	f("router rip vrf X network 1.1.3.0/24 cost 4")
	f("router rip vrf x network 1.1.1.1/32")
	f("username guest1 password secret1")
	f("username guest1 password secret2")
	f("username guest2 password secret3")

	if err := command.Dispatch(app, "commit", c, command.CONF, false); err != nil {
		log.Printf("dispatch: [commit]: %v", err)
	}

	/*
		noCmd, err := command.CmdFind(app.cmdRoot, "no X", command.CONF, true)
		if err != nil {
			log.Printf("could not find 'no' command: %v", err)
			return
		}
	*/

	nonet := "no router rip network"
	if err := command.CmdNo(app, nil, nonet, c); err != nil {
		log.Printf("cmd failed: [%s] error=[%v]", nonet, err)
		return
	}

	command.WriteConfig(app.confRootCandidate, &outputWriter{})
	// Output:
	// hostname rip2
	// router rip vrf X network 1.1.1.0/24
	// router rip vrf X network 1.1.2.0/24
	// router rip vrf X network 1.1.3.0/24 cost 4
	// router rip vrf x network 1.1.1.1/32
	// username guest1 password secret2
	// username guest2 password secret3
}
Beispiel #4
0
func Example_diff1() {

	app, c := setup_diff()

	f := func(s string) {
		if err := command.Dispatch(app, s, c, command.CONF, false); err != nil {
			log.Printf("dispatch: [%s]: %v", s, err)
		}
	}

	f("hostname rip1")
	f("hostname rip2")
	f("router rip network 1.1.1.0/24")
	f("router rip network 1.1.2.0/24")
	f("router rip network 1.1.3.0/24 cost 2")
	f("router rip network 1.1.4.0/24 cost 15")
	f("router rip vrf X network 1.1.1.0/24")
	f("router rip vrf X network 1.1.2.0/24")
	f("router rip vrf X network 1.1.3.0/24 cost 3")
	f("router rip vrf X network 1.1.3.0/24 cost 4")
	f("router rip vrf x network 1.1.1.1/32")
	f("username guest1 password secret1")
	f("username guest1 password secret2")
	f("username guest2 password secret3")

	command.WriteConfig(app.confRootCandidate, &outputWriter{})
	// Output:
	// hostname rip2
	// router rip network 1.1.1.0/24
	// router rip network 1.1.2.0/24
	// router rip network 1.1.3.0/24 cost 2
	// router rip network 1.1.4.0/24 cost 15
	// router rip vrf X network 1.1.1.0/24
	// router rip vrf X network 1.1.2.0/24
	// router rip vrf X network 1.1.3.0/24 cost 4
	// router rip vrf x network 1.1.1.1/32
	// username guest1 password secret2
	// username guest2 password secret3
}
Beispiel #5
0
func dumpConf(root *command.ConfNode, label string) {
	fmt.Println(label)
	command.WriteConfig(root, &outputWriter{})
}