python
>>> import pandevice
# Instantiate a Firewall with hostname and credentials
fw = Firewall("10.0.0.1", "admin", "mypassword")
Direct to Panorama
# Instantiate a Panorama with hostname and credentials
pano = Panorama("10.0.0.5", "admin", "mypassword")
Panorama as proxy
# Instantiate a Panorama with hostname and credentials
pano = Panorama("10.0.0.5", "admin", "mypassword")
# Instantiate a Firewall with serial
fw = Firewall(serial="0002487YR3880")
# Add the Firewall as a child of Panorama
pano.add(fw)
# Instantiate a Firewall with hostname and credentials
fw = Firewall('10.0.0.1', 'admin', 'mypassword')
# Create an address object
webserver = AddressObject("Apache-webserver", "5.5.5.5")
# Add the address object as a child of the firewall object
fw.add(webserver)
# Create the address object on the live firewall device
webserver.create()
# Instantiate a Firewall object that represents vsys2
fw_vsys2 = Firewall("10.0.0.1", "admin", "mypassword", vsys="vsys2")
# Instantiate a Firewall object that represents vsys3
fw_vsys3 = Firewall("10.0.0.1", "admin", "mypassword", vsys="vsys3")
# Add an address object to vsys3
fw_vsys3.add(AddressObject("MyIP", "2.2.2.2")).create()
# Instantiate two firewall objects
fw_1 = Firewall("10.0.0.1", "admin", "mypassword")
fw_2 = Firewall("10.0.0.2", "admin", "mypassword")
# Set as HA pair
fw_1.set_ha_peer(fw_2)
fw1.refresh_active()
# Create an address object
# (performed on active unit, not necessarily fw_1)
fw_1.add(AddressObject("MyIP", "2.2.2.2")).create()
# Commit on active unit syncs address object to passive unit
fw_1.commit()
# Instantiate a firewall object
fw = Firewall("10.0.0.1", "admin", "mypassword")
try:
# Issue a commit that throws exceptions on error
fw.commit(sync=True, exceptions=True)
except PanCommitNotNeeded:
# Ignore
pass
except PanCommitFailed as e:
# Display the error and continue
print "Error while committing: %s" % str(e)
# Instantiate a Firewall object
fw = Firewall("10.0.0.1", "admin", "mypassword")
# Begin a batch User-ID operation
fw.userid.batch_start()
# Add two login events to the batch
fw.userid.logins([("user1", "4.4.4.4"), ("user2", "5.5.5.5")])
# Add a logout event to the batch
fw.userid.logout("user3", "3.3.3.3")
# Register an IP with 4 tags added to the batch
fw.userid.register("2.2.2.2", ("linux", "server", "apache", "web"))
# Close the batch and send in a single API call to the live device
fw.userid.batch_end()
# 'show clock' with pan-python
key = PanXapi(None, "admin", "mypassword", None, "10.0.1.1").keygen()
xapi = PanXapi(hostname="10.0.1.1", api_key=key)
xapi.op("show clock", cmd_xml=False)
# 'show clock' with pandevice
fw = Firewall("10.0.0.1", "admin", "mypassword")
fw.xapi.op("show clock", cmd_xml=False)