Skip to content

Commit

Permalink
black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
shinmog committed Nov 8, 2023
1 parent 9f7d5d9 commit a9b9d9b
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 47 deletions.
78 changes: 61 additions & 17 deletions panos/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ def element(self, with_children=True, comparable=False):
nextelement = root

for section in path:

if section.find("|") != -1:
# This is an element variable, so create an element containing
# the variables's value
Expand Down Expand Up @@ -1648,7 +1647,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 @@ -1992,7 +1997,9 @@ def delete_similar(self):
for chunk in chunk_instances_for_delete_similar(instances):
dev.xapi.delete(
"{0}/{1}[{2}]".format(
xpath, prefix, " or ".join(joiner.format(x.uid) for x in chunk),
xpath,
prefix,
" or ".join(joiner.format(x.uid) for x in chunk),
),
retry_on_peer=self.HA_SYNC,
)
Expand Down Expand Up @@ -2131,7 +2138,9 @@ def hierarchy_info(self):

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

Expand All @@ -2143,7 +2152,10 @@ def hierarchy_info(self):
configs.pop(num)
for p in parents:
configs.append(
chain + [p,]
chain
+ [
p,
]
)
break
else:
Expand Down Expand Up @@ -2801,7 +2813,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 @@ -2886,9 +2899,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 @@ -3722,7 +3733,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 @@ -3744,18 +3760,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 @@ -3903,10 +3934,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 @@ -4836,7 +4873,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 Expand Up @@ -5602,7 +5644,9 @@ def is_ready(self, minutes=None, seconds=None):
"""
end = None
if minutes is not None or seconds is not None:
end = datetime.datetime.now() + datetime.timedelta(minutes=minutes or 0, seconds=seconds or 0)
end = datetime.datetime.now() + datetime.timedelta(
minutes=minutes or 0, seconds=seconds or 0
)

while True:
response = None
Expand Down
Loading

0 comments on commit a9b9d9b

Please sign in to comment.