Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local develop #469

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/configtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ def node_style(cls):
style = "style=filled " + nodestyle[module] + " "
except:
pass
result = ' {0} [{1}URL="../module-{2}.html#panos.{3}" target="_top"];\n'.format(
cls_name, style, module, cls
result = (
' {0} [{1}URL="../module-{2}.html#panos.{3}" target="_top"];\n'.format(
cls_name, style, module, cls
)
)
else:
if style:
Expand Down
6 changes: 5 additions & 1 deletion examples/dyn_address_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ def main():
logging.basicConfig(format=logging_format, level=logging_level)

# Connect to the device and determine its type (Firewall or Panorama).
device = PanDevice.create_from_device(args.hostname, args.username, args.password,)
device = PanDevice.create_from_device(
args.hostname,
args.username,
args.password,
)

# Panorama does not have a userid API, so exit.
# You can use the userid API on a firewall with the Panorama 'target'
Expand Down
6 changes: 5 additions & 1 deletion examples/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ def main():

# Connect to the device and determine its type (Firewall or Panorama).
# This is important to know what version to upgrade to next.
device = PanDevice.create_from_device(args.hostname, args.username, args.password,)
device = PanDevice.create_from_device(
args.hostname,
args.username,
args.password,
)

# Perform the upgrades in sequence with reboots between each upgrade
device.software.upgrade_to_version(args.version, args.dryrun)
Expand Down
6 changes: 5 additions & 1 deletion examples/userid.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ def main():
logging.basicConfig(format=logging_format, level=logging_level)

# Connect to the device and determine its type (Firewall or Panorama).
device = PanDevice.create_from_device(args.hostname, args.username, args.password,)
device = PanDevice.create_from_device(
args.hostname,
args.username,
args.password,
)

logging.debug("Detecting type of device")

Expand Down
10 changes: 8 additions & 2 deletions panos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ def tree_legend_dot():
result += (
'{module} [style=filled fillcolor={color} URL="{url}'
'/module-{module}.html" target="_blank"];'.format(
module=module, color=node_color(module), url=DOCUMENTATION_URL,
module=module,
color=node_color(module),
url=DOCUMENTATION_URL,
)
)
result += "}"
Expand Down Expand Up @@ -286,7 +288,11 @@ def string_or_list(value):
value,
]
return (
list(value) if "__iter__" in dir(value) else [value,]
list(value)
if "__iter__" in dir(value)
else [
value,
]
)


Expand Down
78 changes: 63 additions & 15 deletions panos/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,13 @@ def _set_reference(
if var_type == "list":
if var is None:
update_needed = True
setattr(obj, reference_var, [self,])
setattr(
obj,
reference_var,
[
self,
],
)
if update:
obj.update(reference_var)
elif not isinstance(var, list):
Expand Down Expand Up @@ -2100,7 +2106,9 @@ def hierarchy_info(self):

classes = panos.object_classes()
configs = [
[self.__class__,],
[
self.__class__,
],
]
updated_configs = []

Expand All @@ -2112,7 +2120,10 @@ def hierarchy_info(self):
configs.pop(num)
for p in parents:
configs.append(
chain + [p,]
chain
+ [
p,
]
)
break
else:
Expand Down Expand Up @@ -2764,7 +2775,8 @@ def __getattr__(self, name):

raise AttributeError(
"'{0}' object has no attribute '{1}'".format(
self.__class__.__name__, str(name),
self.__class__.__name__,
str(name),
)
)

Expand Down Expand Up @@ -2849,9 +2861,7 @@ def __repr__(self):


class ValueEntry(VersionedPanObject):
"""Base class for objects that only have a value element.

"""
"""Base class for objects that only have a value element."""

ROOT = Root.VSYS
SUFFIX = ENTRY
Expand Down Expand Up @@ -3685,7 +3695,12 @@ def get_device_version(self):

@classmethod
def create_from_device(
cls, hostname, api_username=None, api_password=None, api_key=None, port=443,
cls,
hostname,
api_username=None,
api_password=None,
api_key=None,
port=443,
):
"""Factory method to create a :class:`panos.firewall.Firewall`
or :class:`panos.panorama.Panorama` object from a live device
Expand All @@ -3707,18 +3722,33 @@ def create_from_device(
# Create generic PanDevice to connect and get information
from panos import firewall, panorama

device = PanDevice(hostname, api_username, api_password, api_key, port,)
device = PanDevice(
hostname,
api_username,
api_password,
api_key,
port,
)
system_info = device.refresh_system_info()
version = system_info[0]
model = system_info[1]
if model == "Panorama" or model.startswith("M-"):
instance = panorama.Panorama(
hostname, api_username, api_password, device.api_key, port,
hostname,
api_username,
api_password,
device.api_key,
port,
)
else:
serial = system_info[2]
instance = firewall.Firewall(
hostname, api_username, api_password, device.api_key, serial, port,
hostname,
api_username,
api_password,
device.api_key,
serial,
port,
)
instance._set_version_and_version_info(version)
return instance
Expand Down Expand Up @@ -3866,10 +3896,16 @@ def method(self, *args, **kwargs):

def classify_exception(self, e):
if str(e) == "Invalid credentials.":
return err.PanInvalidCredentials(str(e), pan_device=self.pan_device,)
return err.PanInvalidCredentials(
str(e),
pan_device=self.pan_device,
)
elif str(e).startswith("URLError:"):
if str(e).endswith("timed out"):
return err.PanConnectionTimeout(str(e), pan_device=self.pan_device,)
return err.PanConnectionTimeout(
str(e),
pan_device=self.pan_device,
)
else:
# This could be that we have an old version of OpenSSL
# that doesn't support TLSv1.1, so check for that and give
Expand Down Expand Up @@ -4584,12 +4620,19 @@ def map_ha(self, method_name, *args, **kwargs):
return result1, result2

def show_highavailability_state(self):
from panos.panorama import Panorama

ha_state = self.op("show high-availability state")
enabled = ha_state.findtext("result/enabled")
p = self
if enabled is None or enabled == "no":
return "disabled", None
else:
return ha_state.findtext("result/group/local-info/state"), ha_state
if isinstance(p, Panorama):
xpath = "result/local-info/state"
else:
xpath = "result/group/local-info/state"
return ha_state.findtext(xpath), ha_state

def refresh_ha_active(self):
"""Refresh which device is active using the live device
Expand Down Expand Up @@ -4788,7 +4831,12 @@ def _commit(
logger.debug(
self.id
+ ": commit requested: commit_all:%s sync:%s sync_all:%s cmd:%s"
% (str(commit_all), str(sync), str(sync_all), cmd,)
% (
str(commit_all),
str(sync),
str(sync_all),
cmd,
)
)
if commit_all:
action = "all"
Expand Down
Loading