forked from PaloAltoNetworks/pango
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Objects namespace to Panorama and Panorama namespace with devi…
…ce group support - PaloAltoNetworks#1; adding pango.Connect; adding Panorama.CommitAll(); restructuring directory a bit
- Loading branch information
Showing
48 changed files
with
2,688 additions
and
890 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,36 @@ | ||
package pango | ||
|
||
/* | ||
Connect opens a connection to the PAN-OS client, then uses the "model" info | ||
to return a pointer to either a Firewall or Panorama struct. | ||
The Initialize function is invoked as part of this discovery, so there is no | ||
need to Initialize() the Client connection prior to invoking this. | ||
*/ | ||
func Connect(c Client) (interface{}, error) { | ||
var err error | ||
|
||
logg := c.Logging | ||
c.Logging = LogQuiet | ||
|
||
if err = c.Initialize(); err != nil { | ||
return nil, err | ||
} | ||
|
||
model := c.SystemInfo["model"] | ||
if model == "Panorama" || model[:2] == "M-" { | ||
pano := &Panorama{Client: c} | ||
pano.Logging = logg | ||
if err = pano.Initialize(); err != nil { | ||
return nil, err | ||
} | ||
return pano, nil | ||
} else { | ||
fw := &Firewall{Client: c} | ||
fw.Logging = logg | ||
if err = fw.Initialize(); err != nil { | ||
return nil, err | ||
} | ||
return fw, nil | ||
} | ||
} |
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,132 @@ | ||
/* | ||
Package pango is a golang cross version mechanism for interacting with Palo Alto | ||
Networks devices (including physical and virtualized Next-generation Firewalls | ||
and Panorama). Versioning support is in place for PAN-OS 6.1 to 8.1. | ||
To start, create a client connection with the desired parameters and then | ||
initialize the connection: | ||
package main | ||
import ( | ||
"log" | ||
"github.com/PaloAltoNetworks/pango" | ||
) | ||
func main() { | ||
var err error | ||
c := pango.Firewall{Client: pango.Client{ | ||
Hostname: "127.0.0.1", | ||
Username: "admin", | ||
Password: "admin", | ||
Logging: pango.LogAction | pango.LogOp, | ||
}} | ||
if err = c.Initialize(); err != nil { | ||
log.Printf("Failed to initialize client: %s", err) | ||
return | ||
} | ||
log.Printf("Initialize ok") | ||
} | ||
Initializing the connection creates the API key (if it was not already | ||
specified), then performs "show system info" to get the PAN-OS version. Once | ||
the firewall client is created, you can query and configure the Palo | ||
Alto Networks device from the functions inside the various namespaces of the | ||
client connection. Namespaces correspond to the various configuration areas | ||
available in the GUI. For example: | ||
err = c.Network.EthernetInterface.Set(...) | ||
myPolicies, err := c.Policies.Security.GetList(...) | ||
Generally speaking, there are the following functions inside each namespace: | ||
* GetList | ||
* ShowList | ||
* Get | ||
* Show | ||
* Set | ||
* Edit | ||
* Delete | ||
These functions correspond with PAN-OS Get, Show, Set, Edit, and | ||
Delete API calls. Get(), Set(), and Edit() take and return normalized, | ||
version independent objects. These version safe objects are typically named | ||
Entry, which corresponds to how the object is placed in the PAN-OS XPATH. | ||
Some Entry objects have a special function, Defaults(). Invoking this | ||
function will initialize the object with some default values. Each Entry | ||
that implements Defaults() calls out in its documentation what parameters | ||
are affected by this, and what the defaults are. | ||
For any version safe object, attempting to configure a parameter that your | ||
PAN-OS doesn't support will be safely ignored in the resultant XML sent to the | ||
firewall / Panorama. | ||
Using Edit Functions | ||
The PAN-OS XML API Edit command can be used to both create as well as update | ||
existing config, however it can also truncate config for the given XPATH. Due | ||
to this, if you want to use Edit(), you need to make sure that you perform | ||
either a Get() or a Show() first, make your modification, then invoke | ||
Edit() using that object. If you don't do this, you will truncate any sub | ||
config. | ||
To learn more about PAN-OS XML API, please refer to the Palo Alto Netowrks | ||
API documentation. | ||
Examples | ||
The following program will create ethernet1/7 as a DHCP interface and import | ||
it into vsys1 if it isn't already present: | ||
package main | ||
import ( | ||
"log" | ||
"github.com/PaloAltoNetworks/pango" | ||
"github.com/PaloAltoNetworks/pango/netw/eth" | ||
) | ||
func main() { | ||
var err error | ||
c := &pango.Firewall{Client: pango.Client{ | ||
Hostname: "127.0.0.1", | ||
Username: "admin", | ||
Password: "admin", | ||
Logging: pango.LogAction | pango.LogOp, | ||
}} | ||
if err = c.Initialize(); err != nil { | ||
log.Printf("Failed to initialize client: %s", err) | ||
return | ||
} | ||
e := eth.Entry{ | ||
Name: "ethernet1/7", | ||
Mode: "layer3", | ||
EnableDhcp: true, | ||
CreateDhcpDefaultRoute: true, | ||
} | ||
interfaces, err := c.Network.EthernetInterface.GetList() | ||
if err != nil { | ||
log.Printf("Failed to get data interfaces: %s", err) | ||
return | ||
} | ||
for i := range interfaces { | ||
if e.Name == interfaces[i] { | ||
log.Printf("%s already exists", e.Name) | ||
return | ||
} | ||
} | ||
err = c.Network.EthernetInterface.Set("vsys1", e) | ||
if err != nil { | ||
log.Printf("Failed to create %s: %s", e.Name, err) | ||
return | ||
} | ||
log.Printf("Created %s ok", e.Name) | ||
} | ||
*/ | ||
package pango |
Oops, something went wrong.