correct hostname and fqdn parsing

This commit is contained in:
Petr Klima committed 2020-11-11 18:58:05 +00:00
1 parent 3e97500230
commit e3f760faf9
1 file changed
+31 -13
+31 -13
View File
@@ -35,7 +35,6 @@ from napalm.base.exceptions import (
import napalm.base.constants as C import napalm.base.constants as C
import napalm.base.helpers import napalm.base.helpers
class S350Driver(NetworkDriver): class S350Driver(NetworkDriver):
"""Napalm driver for S350.""" """Napalm driver for S350."""
@@ -222,7 +221,7 @@ class S350Driver(NetworkDriver):
def get_facts(self): def get_facts(self):
"""Return a set of facts from the device.""" """Return a set of facts from the device."""
serial_number, fqdn, os_version, hostname, domain_name = ('Unknown',) * 5 serial_number, fqdn, os_version, hostname, domainname = ('Unknown',) * 5
# Submit commands to the device. # Submit commands to the device.
show_ver = self._send_command('show version') show_ver = self._send_command('show version')
@@ -233,13 +232,13 @@ class S350Driver(NetworkDriver):
os_version = self._get_facts_parse_os_version(show_ver) os_version = self._get_facts_parse_os_version(show_ver)
# hostname, uptime # hostname
hostname = '' hostname = self._get_facts_hostname(show_sys)
for line in show_sys.splitlines(): # special case for SG500 fw v1.4.x
if line.startswith('System Name:'): if hostname == 'Unknown':
_, hostname = line.split('System Name:') hostname = self._get_facts_hostname_from_config(
hostname = hostname.strip() self._send_command('show running-config')
continue )
# uptime # uptime
uptime_str = self._get_facts_uptime(show_sys) uptime_str = self._get_facts_uptime(show_sys)
@@ -255,10 +254,8 @@ class S350Driver(NetworkDriver):
show_hosts)[0] show_hosts)[0]
domainname = domainname['domain_name'] domainname = domainname['domain_name']
if domainname == 'Domain': if domainname == 'Domain':
domainname = '' domainname = 'Unknown'
if domainname == '' and hostname == '': if domainname != "Unknown" and hostname != "Unknown":
fqdn = ''
else:
fqdn = '{0}.{1}'.format(hostname, domainname) fqdn = '{0}.{1}'.format(hostname, domainname)
# interface_list # interface_list
@@ -286,6 +283,27 @@ class S350Driver(NetworkDriver):
'vendor': u'Cisco', 'vendor': u'Cisco',
} }
def _get_facts_hostname_from_config(self, show_running):
# special case for SG500 fw v1.4.x
hostname = 'Unknown'
for line in show_running.splitlines():
if line.startswith('hostname '):
_, hostname = line.split('hostname')
hostname = hostname.strip()
break
return hostname
def _get_facts_hostname(self, show_sys):
hostname = 'Unknown'
for line in show_sys.splitlines():
if line.startswith('System Name:'):
_, hostname = line.split('System Name:')
hostname = hostname.strip()
break
return hostname
def _get_facts_uptime(self, show_sys): def _get_facts_uptime(self, show_sys):
i = 0 i = 0
syslines = [] syslines = []