Skip to content

Commit

Permalink
Python3 unicode fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ktbyers committed Jan 12, 2017
1 parent 60ccca9 commit 8a1779b
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions napalm_fortios/fortios.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
from __future__ import unicode_literals

import re
from pyFG.fortios import FortiOS, FortiConfig, logger
from pyFG.exceptions import FailedCommit, CommandExecutionException
from napalm_base.base import NetworkDriver
from napalm_base.exceptions import ReplaceConfigException, MergeConfigException
from napalm_base.utils.string_parsers import colon_separated_string_to_dict,\
convert_uptime_string_seconds
from napalm_base.utils import py23_compat


class FortiOSDriver(NetworkDriver):
Expand Down Expand Up @@ -164,7 +167,7 @@ def get_config(self, retrieve="all"):

return {
'startup': u"",
'running': unicode(text_result),
'running': py23_compat.text_type(text_result),
'candidate': u"",
}

Expand All @@ -188,12 +191,12 @@ def get_facts(self):
vdom='global')['domain']

return {
'vendor': unicode('Fortigate'),
'os_version': unicode(system_status['Version'].split(',')[0].split()[1]),
'vendor': py23_compat.text_type('Fortigate'),
'os_version': py23_compat.text_type(system_status['Version'].split(',')[0].split()[1]),
'uptime': convert_uptime_string_seconds(performance_status['Uptime']),
'serial_number': unicode(system_status['Serial-Number']),
'model': unicode(system_status['Version'].split(',')[0].split()[0]),
'hostname': unicode(system_status['Hostname']),
'serial_number': py23_compat.text_type(system_status['Serial-Number']),
'model': py23_compat.text_type(system_status['Version'].split(',')[0].split()[0]),
'hostname': py23_compat.text_type(system_status['Hostname']),
'fqdn': u'{}.{}'.format(system_status['Hostname'], domain),
'interface_list': interface_list
}
Expand Down Expand Up @@ -239,7 +242,7 @@ def get_interfaces(self):
elif line.startswith('Link'):
parsed_data['is_up'] = line.split('\t')[-1] is 'up'
elif line.startswith('Current_HWaddr'):
parsed_data['mac_address'] = unicode(line.split('\t')[-1])
parsed_data['mac_address'] = py23_compat.text_type(line.split('\t')[-1])
parsed_data['is_enabled'] = True
parsed_data['description'] = u''
parsed_data['last_flapped'] = -1.0
Expand All @@ -252,7 +255,7 @@ def get_interfaces(self):
elif line.startswith('PHY Speed'):
parsed_data['speed'] = int(line.split(':')[-1])
elif line.startswith('Current_HWaddr'):
parsed_data['mac_address'] = unicode(line.split(' ')[-1])
parsed_data['mac_address'] = py23_compat.text_type(line.split(' ')[-1])
parsed_data['description'] = u''
parsed_data['last_flapped'] = -1.0
interface_statistics[interface] = parsed_data
Expand Down Expand Up @@ -294,16 +297,16 @@ def get_firewall_policies(self):
policy_item['position'] = position
policy_item['packet_hits'] = -1
policy_item['byte_hits'] = -1
policy_item['id'] = unicode(key)
policy_item['id'] = py23_compat.text_type(key)
policy_item['enabled'] = enabled
policy_item['schedule'] = unicode(policy[key]['schedule'])
policy_item['log'] = unicode(logtraffic)
policy_item['l3_src'] = unicode(policy[key]['srcaddr'])
policy_item['l3_dst'] = unicode(policy[key]['dstaddr'])
policy_item['service'] = unicode(policy[key]['service'])
policy_item['src_zone'] = unicode(policy[key]['srcintf'])
policy_item['dst_zone'] = unicode(policy[key]['dstintf'])
policy_item['action'] = unicode(action)
policy_item['schedule'] = py23_compat.text_type(policy[key]['schedule'])
policy_item['log'] = py23_compat.text_type(logtraffic)
policy_item['l3_src'] = py23_compat.text_type(policy[key]['srcaddr'])
policy_item['l3_dst'] = py23_compat.text_type(policy[key]['dstaddr'])
policy_item['service'] = py23_compat.text_type(policy[key]['service'])
policy_item['src_zone'] = py23_compat.text_type(policy[key]['srcintf'])
policy_item['dst_zone'] = py23_compat.text_type(policy[key]['dstintf'])
policy_item['action'] = py23_compat.text_type(action)
default_policy[key].append(policy_item)

position = position + 1
Expand Down Expand Up @@ -346,7 +349,7 @@ def get_bgp_neighbors(self):
self._execute_command_with_vdom(command_detail.format(neighbor))]
m = re.search('remote router id (.+?)\n', '\n'.join(detail_output))
if m:
neighbor_dict['remote_id'] = unicode(m.group(1))
neighbor_dict['remote_id'] = py23_compat.text_type(m.group(1))
else:
raise Exception('cannot find remote router id for %s' % neighbor)

Expand All @@ -371,7 +374,7 @@ def get_bgp_neighbors(self):

return {
'global': {
'router_id': unicode(bgp_sum[0].split()[3]),
'router_id': py23_compat.text_type(bgp_sum[0].split()[3]),
'peers': peers
}
}
Expand Down

0 comments on commit 8a1779b

Please sign in to comment.