Skip to content

Commit

Permalink
Change to reuse get_config method, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
itdependsnetworks committed Feb 11, 2022
1 parent 7371d46 commit 37d2431
Show file tree
Hide file tree
Showing 4 changed files with 647 additions and 22 deletions.
24 changes: 13 additions & 11 deletions napalm_panos/panos.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def get_route_to(

return routes

def get_interfaces(self):
def get_interfaces(self): # pylint: disable=too-many-locals
"""PANOS version of `get_interfaces` method, see NAPALM for documentation."""
subif_defaults = {
"is_up": True,
Expand All @@ -531,21 +531,23 @@ def get_interfaces(self):
interface_dict = {}
interface_descr = {}
interface_list = self._extract_interface_list()


self.device.get(xpath="/config/devices/entry[@name='localhost.localdomain']/network/interface")
for eth_int in self.device.element_result.findall(".//ethernet/entry"):

config = xml.etree.ElementTree.fromstring(self.get_config()["running"])
for eth_int in config.findall(".//ethernet/entry"):
name = eth_int.attrib["name"]
description = eth_int.findtext(".//comment") or ''
description = eth_int.findtext(".//comment") or ""
interface_descr[name] = description.strip()
for eth_int in self.device.element_result.findall(".//vlan/units/entry"):
for eth_int in config.findall(".//vlan/units/entry"):
name = eth_int.attrib["name"]
description = eth_int.findtext(".//comment") or ''
description = eth_int.findtext(".//comment") or ""
interface_descr[name] = description.strip()
for eth_int in self.device.element_result.findall(".//tunnel/units/entry"):
for eth_int in config.findall(".//tunnel/units/entry"):
name = eth_int.attrib["name"]
description = eth_int.findtext(".//comment") or ''
description = eth_int.findtext(".//comment") or ""
interface_descr[name] = description.strip()
interface_descr["loopback"] = self.device.element_result.findtext(".//loopback/comment") or ''
interface_descr["loopback"] = config.findtext(".//loopback/comment") or ""

for intf in interface_list:
interface = {}
Expand All @@ -557,8 +559,8 @@ def get_interfaces(self):
interface_info_json = json.dumps(interface_info_xml["response"]["result"]["hw"])
interface_info = json.loads(interface_info_json)
except KeyError as err:
if intf.startswith(("loopback.", "tunnel.")) and 'hw' in str(err):
# loopback sub-ifs don't return a 'hw' key
if interface_pattern.search(intf) and "hw" in str(err):
# physical/ae/tunnel/loopback sub-ifs don't return a 'hw' key
interface_dict[intf] = subif_defaults
continue
raise
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,304 @@
<response status="success"><result><config urldb="paloaltonetworks" version="7.0.0">
<mgt-config>
<users>
<entry name="admin">
<phash>fnRL/G5lXVMug</phash>
<permissions>
<role-based>
<superuser>yes</superuser>
</role-based>
</permissions>
</entry>
<entry name="ntc">
<permissions>
<role-based>
<superuser>yes</superuser>
</role-based>
</permissions>
<phash>$1$vbxmfoed$3DpWw/eU1C7S5PUOqZnJ2.</phash>
</entry>
</users>
</mgt-config>
<shared>
<application />
<application-group />
<service />
<service-group />
<botnet>
<configuration>
<http>
<dynamic-dns>
<enabled>yes</enabled>
<threshold>5</threshold>
</dynamic-dns>
<malware-sites>
<enabled>yes</enabled>
<threshold>5</threshold>
</malware-sites>
<recent-domains>
<enabled>yes</enabled>
<threshold>5</threshold>
</recent-domains>
<ip-domains>
<enabled>yes</enabled>
<threshold>10</threshold>
</ip-domains>
<executables-from-unknown-sites>
<enabled>yes</enabled>
<threshold>5</threshold>
</executables-from-unknown-sites>
</http>
<other-applications>
<irc>yes</irc>
</other-applications>
<unknown-applications>
<unknown-tcp>
<destinations-per-hour>10</destinations-per-hour>
<sessions-per-hour>10</sessions-per-hour>
<session-length>
<maximum-bytes>100</maximum-bytes>
<minimum-bytes>50</minimum-bytes>
</session-length>
</unknown-tcp>
<unknown-udp>
<destinations-per-hour>10</destinations-per-hour>
<sessions-per-hour>10</sessions-per-hour>
<session-length>
<maximum-bytes>100</maximum-bytes>
<minimum-bytes>50</minimum-bytes>
</session-length>
</unknown-udp>
</unknown-applications>
</configuration>
<report>
<topn>100</topn>
<scheduled>yes</scheduled>
</report>
</botnet>
<local-user-database>
<user />
</local-user-database>
</shared>
<devices>
<entry name="localhost.localdomain">
<network>
<interface>
<ethernet />
</interface>
<profiles>
<monitor-profile>
<entry name="default">
<interval>3</interval>
<threshold>5</threshold>
<action>wait-recover</action>
</entry>
</monitor-profile>
</profiles>
<ike>
<crypto-profiles>
<ike-crypto-profiles>
<entry name="default">
<encryption>
<member>aes-128-cbc</member>
<member>3des</member>
</encryption>
<hash>
<member>sha1</member>
</hash>
<dh-group>
<member>group2</member>
</dh-group>
<lifetime>
<hours>8</hours>
</lifetime>
</entry>
<entry name="Suite-B-GCM-128">
<encryption>
<member>aes-128-cbc</member>
</encryption>
<hash>
<member>sha256</member>
</hash>
<dh-group>
<member>group19</member>
</dh-group>
<lifetime>
<hours>8</hours>
</lifetime>
</entry>
<entry name="Suite-B-GCM-256">
<encryption>
<member>aes-256-cbc</member>
</encryption>
<hash>
<member>sha384</member>
</hash>
<dh-group>
<member>group20</member>
</dh-group>
<lifetime>
<hours>8</hours>
</lifetime>
</entry>
</ike-crypto-profiles>
<ipsec-crypto-profiles>
<entry name="default">
<esp>
<encryption>
<member>aes-128-cbc</member>
<member>3des</member>
</encryption>
<authentication>
<member>sha1</member>
</authentication>
</esp>
<dh-group>group2</dh-group>
<lifetime>
<hours>1</hours>
</lifetime>
</entry>
<entry name="Suite-B-GCM-128">
<esp>
<encryption>
<member>aes-128-gcm</member>
</encryption>
<authentication>
<member>none</member>
</authentication>
</esp>
<dh-group>group19</dh-group>
<lifetime>
<hours>1</hours>
</lifetime>
</entry>
<entry name="Suite-B-GCM-256">
<esp>
<encryption>
<member>aes-256-gcm</member>
</encryption>
<authentication>
<member>none</member>
</authentication>
</esp>
<dh-group>group20</dh-group>
<lifetime>
<hours>1</hours>
</lifetime>
</entry>
</ipsec-crypto-profiles>
<global-protect-app-crypto-profiles>
<entry name="default">
<encryption>
<member>aes-128-cbc</member>
</encryption>
<authentication>
<member>sha1</member>
</authentication>
</entry>
</global-protect-app-crypto-profiles>
</crypto-profiles>
</ike>
<qos>
<profile>
<entry name="default">
<class>
<entry name="class1">
<priority>real-time</priority>
</entry>
<entry name="class2">
<priority>high</priority>
</entry>
<entry name="class3">
<priority>high</priority>
</entry>
<entry name="class4">
<priority>medium</priority>
</entry>
<entry name="class5">
<priority>medium</priority>
</entry>
<entry name="class6">
<priority>low</priority>
</entry>
<entry name="class7">
<priority>low</priority>
</entry>
<entry name="class8">
<priority>low</priority>
</entry>
</class>
</entry>
</profile>
</qos>
<virtual-router>
<entry name="default">
<protocol>
<bgp>
<enable>no</enable>
<dampening-profile>
<entry name="default">
<cutoff>1.25</cutoff>
<reuse>0.5</reuse>
<max-hold-time>900</max-hold-time>
<decay-half-life-reachable>300</decay-half-life-reachable>
<decay-half-life-unreachable>900</decay-half-life-unreachable>
<enable>yes</enable>
</entry>
</dampening-profile>
</bgp>
</protocol>
</entry>
</virtual-router>
</network>
<deviceconfig>
<system>
<ip-address>10.0.0.90</ip-address>
<netmask>255.255.255.0</netmask>
<update-server>updates.paloaltonetworks.com</update-server>
<update-schedule>
<threats>
<recurring>
<weekly>
<day-of-week>wednesday</day-of-week>
<at>01:02</at>
<action>download-only</action>
</weekly>
</recurring>
</threats>
</update-schedule>
<timezone>US/Pacific</timezone>
<service>
<disable-telnet>yes</disable-telnet>
<disable-http>yes</disable-http>
</service>
<hostname>test</hostname>
<default-gateway>10.0.0.2</default-gateway>
<dns-setting>
<servers>
<primary>8.8.8.8</primary>
</servers>
</dns-setting>
</system>
<setting>
<config>
<rematch>yes</rematch>
</config>
<management>
<hostname-type-in-syslog>FQDN</hostname-type-in-syslog>
</management>
</setting>
</deviceconfig>
<vsys>
<entry name="vsys1">
<application />
<application-group />
<zone />
<service />
<service-group />
<schedule />
<rulebase />
</entry>
</vsys>
</entry>
</devices>
</config></result></response>
Loading

0 comments on commit 37d2431

Please sign in to comment.