forked from PaloAltoNetworks/pango
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_interface_test.go
52 lines (44 loc) · 1.35 KB
/
example_interface_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package pango_test
import (
"log"
"github.com/PaloAltoNetworks/pango"
"github.com/PaloAltoNetworks/pango/netw/interface/eth"
)
// ExampleCreateInterface demonstrates how to use pango to create an interface
// if the interface is not already configured.
func Example_createInterface() {
var err error
// Connect to the firewall.
fw := pango.Firewall{Client: pango.Client{
Hostname: "192.168.1.1",
Username: "admin",
Password: "admin",
}}
// Connect to the firewall and verify authentication params.
if err = fw.Initialize(); err != nil {
log.Fatalf("Failed to connect to %s: %s", fw.Hostname, err)
}
// Define the ethernet interface we want to configure.
e := eth.Entry{
Name: "ethernet1/7",
Mode: "layer3",
Comment: "Made by pango",
StaticIps: []string{"10.1.1.1/24", "10.2.1.1/24"},
}
// If the interface is already present, leave it alone.
ethList, err := fw.Network.EthernetInterface.GetList()
if err != nil {
log.Fatalf("Failed to get interface listing: %s", err)
}
for i := range ethList {
if ethList[i] == e.Name {
log.Printf("Interface %q already exists, quitting.", e.Name)
return
}
}
// Since the interface is not present, configure it.
if err = fw.Network.EthernetInterface.Set("vsys1", e); err != nil {
log.Fatalf("Failed to create %q: %s", e.Name, err)
}
log.Printf("Created %q ok", e.Name)
}