Merge pull request #66 from Serverlag/napalm-pip-patch
Fix for pip10, adjust to napalm.base, remove py23 support
This commit is contained in:
2 files changed
+25
-29
No files matched your search
+24
-29
@@ -16,16 +16,11 @@ from __future__ import unicode_literals
|
|||||||
import re
|
import re
|
||||||
from pyFG.fortios import FortiOS, FortiConfig, logger
|
from pyFG.fortios import FortiOS, FortiConfig, logger
|
||||||
from pyFG.exceptions import FailedCommit, CommandExecutionException
|
from pyFG.exceptions import FailedCommit, CommandExecutionException
|
||||||
from napalm_base.exceptions import ReplaceConfigException, MergeConfigException
|
from napalm.base.exceptions import ReplaceConfigException, MergeConfigException
|
||||||
from napalm_base.utils.string_parsers import colon_separated_string_to_dict,\
|
from napalm.base.utils.string_parsers import colon_separated_string_to_dict,\
|
||||||
convert_uptime_string_seconds
|
convert_uptime_string_seconds
|
||||||
from napalm_base.utils import py23_compat
|
import napalm.base.helpers
|
||||||
import napalm_base.helpers
|
from napalm.base.base import NetworkDriver
|
||||||
|
|
||||||
try:
|
|
||||||
from napalm.base.base import NetworkDriver
|
|
||||||
except ImportError:
|
|
||||||
from napalm_base.base import NetworkDriver
|
|
||||||
|
|
||||||
|
|
||||||
class FortiOSDriver(NetworkDriver):
|
class FortiOSDriver(NetworkDriver):
|
||||||
@@ -172,7 +167,7 @@ class FortiOSDriver(NetworkDriver):
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
'startup': u"",
|
'startup': u"",
|
||||||
'running': py23_compat.text_type(text_result),
|
'running': str(text_result),
|
||||||
'candidate': u"",
|
'candidate': u"",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,12 +191,12 @@ class FortiOSDriver(NetworkDriver):
|
|||||||
vdom='global')['domain']
|
vdom='global')['domain']
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'vendor': py23_compat.text_type('Fortigate'),
|
'vendor': str('Fortigate'),
|
||||||
'os_version': py23_compat.text_type(system_status['Version'].split(',')[0].split()[1]),
|
'os_version': str(system_status['Version'].split(',')[0].split()[1]),
|
||||||
'uptime': convert_uptime_string_seconds(performance_status['Uptime']),
|
'uptime': convert_uptime_string_seconds(performance_status['Uptime']),
|
||||||
'serial_number': py23_compat.text_type(system_status['Serial-Number']),
|
'serial_number': str(system_status['Serial-Number']),
|
||||||
'model': py23_compat.text_type(system_status['Version'].split(',')[0].split()[0]),
|
'model': str(system_status['Version'].split(',')[0].split()[0]),
|
||||||
'hostname': py23_compat.text_type(system_status['Hostname']),
|
'hostname': str(system_status['Hostname']),
|
||||||
'fqdn': u'{}.{}'.format(system_status['Hostname'], domain),
|
'fqdn': u'{}.{}'.format(system_status['Hostname'], domain),
|
||||||
'interface_list': interface_list
|
'interface_list': interface_list
|
||||||
}
|
}
|
||||||
@@ -247,7 +242,7 @@ class FortiOSDriver(NetworkDriver):
|
|||||||
elif line.startswith('Link'):
|
elif line.startswith('Link'):
|
||||||
parsed_data['is_up'] = line.split('\t')[-1] is 'up'
|
parsed_data['is_up'] = line.split('\t')[-1] is 'up'
|
||||||
elif line.startswith('Current_HWaddr'):
|
elif line.startswith('Current_HWaddr'):
|
||||||
parsed_data['mac_address'] = py23_compat.text_type(line.split('\t')[-1])
|
parsed_data['mac_address'] = str(line.split('\t')[-1])
|
||||||
parsed_data['is_enabled'] = True
|
parsed_data['is_enabled'] = True
|
||||||
parsed_data['description'] = u''
|
parsed_data['description'] = u''
|
||||||
parsed_data['last_flapped'] = -1.0
|
parsed_data['last_flapped'] = -1.0
|
||||||
@@ -260,7 +255,7 @@ class FortiOSDriver(NetworkDriver):
|
|||||||
elif line.startswith('PHY Speed'):
|
elif line.startswith('PHY Speed'):
|
||||||
parsed_data['speed'] = int(line.split(':')[-1])
|
parsed_data['speed'] = int(line.split(':')[-1])
|
||||||
elif line.startswith('Current_HWaddr'):
|
elif line.startswith('Current_HWaddr'):
|
||||||
parsed_data['mac_address'] = py23_compat.text_type(line.split(' ')[-1])
|
parsed_data['mac_address'] = str(line.split(' ')[-1])
|
||||||
parsed_data['description'] = u''
|
parsed_data['description'] = u''
|
||||||
parsed_data['last_flapped'] = -1.0
|
parsed_data['last_flapped'] = -1.0
|
||||||
interface_statistics[interface] = parsed_data
|
interface_statistics[interface] = parsed_data
|
||||||
@@ -323,16 +318,16 @@ class FortiOSDriver(NetworkDriver):
|
|||||||
policy_item['position'] = position
|
policy_item['position'] = position
|
||||||
policy_item['packet_hits'] = -1
|
policy_item['packet_hits'] = -1
|
||||||
policy_item['byte_hits'] = -1
|
policy_item['byte_hits'] = -1
|
||||||
policy_item['id'] = py23_compat.text_type(key)
|
policy_item['id'] = str(key)
|
||||||
policy_item['enabled'] = enabled
|
policy_item['enabled'] = enabled
|
||||||
policy_item['schedule'] = py23_compat.text_type(policy[key]['schedule'])
|
policy_item['schedule'] = str(policy[key]['schedule'])
|
||||||
policy_item['log'] = py23_compat.text_type(logtraffic)
|
policy_item['log'] = str(logtraffic)
|
||||||
policy_item['l3_src'] = py23_compat.text_type(policy[key]['srcaddr'])
|
policy_item['l3_src'] = str(policy[key]['srcaddr'])
|
||||||
policy_item['l3_dst'] = py23_compat.text_type(policy[key]['dstaddr'])
|
policy_item['l3_dst'] = str(policy[key]['dstaddr'])
|
||||||
policy_item['service'] = py23_compat.text_type(policy[key]['service'])
|
policy_item['service'] = str(policy[key]['service'])
|
||||||
policy_item['src_zone'] = py23_compat.text_type(policy[key]['srcintf'])
|
policy_item['src_zone'] = str(policy[key]['srcintf'])
|
||||||
policy_item['dst_zone'] = py23_compat.text_type(policy[key]['dstintf'])
|
policy_item['dst_zone'] = str(policy[key]['dstintf'])
|
||||||
policy_item['action'] = py23_compat.text_type(action)
|
policy_item['action'] = str(action)
|
||||||
default_policy[key].append(policy_item)
|
default_policy[key].append(policy_item)
|
||||||
|
|
||||||
position = position + 1
|
position = position + 1
|
||||||
@@ -375,7 +370,7 @@ class FortiOSDriver(NetworkDriver):
|
|||||||
self._execute_command_with_vdom(command_detail.format(neighbor))]
|
self._execute_command_with_vdom(command_detail.format(neighbor))]
|
||||||
m = re.search('remote router id (.+?)\n', '\n'.join(detail_output))
|
m = re.search('remote router id (.+?)\n', '\n'.join(detail_output))
|
||||||
if m:
|
if m:
|
||||||
neighbor_dict['remote_id'] = py23_compat.text_type(m.group(1))
|
neighbor_dict['remote_id'] = str(m.group(1))
|
||||||
else:
|
else:
|
||||||
raise Exception('cannot find remote router id for %s' % neighbor)
|
raise Exception('cannot find remote router id for %s' % neighbor)
|
||||||
|
|
||||||
@@ -400,7 +395,7 @@ class FortiOSDriver(NetworkDriver):
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
'global': {
|
'global': {
|
||||||
'router_id': py23_compat.text_type(bgp_sum[0].split()[3]),
|
'router_id': str(bgp_sum[0].split()[3]),
|
||||||
'peers': peers
|
'peers': peers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -518,7 +513,7 @@ class FortiOSDriver(NetworkDriver):
|
|||||||
address, age, mac, interface = line.split()
|
address, age, mac, interface = line.split()
|
||||||
entry = {
|
entry = {
|
||||||
"interface": interface,
|
"interface": interface,
|
||||||
"mac": napalm_base.helpers.mac(mac).rstrip(),
|
"mac": napalm.base.helpers.mac(mac).rstrip(),
|
||||||
"ip": address,
|
"ip": address,
|
||||||
"age": age.replace("-", "-1"),
|
"age": age.replace("-", "-1"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
napalm
|
napalm
|
||||||
pyFG>=0.49_1
|
pyFG>=0.49_1
|
||||||
future
|
future
|
||||||
|
ncclient==0.6.9
|
||||||
Reference in new issue
Block a user