fix unicode errors in iosxr
This commit is contained in:
parent
045f0ff520
commit
0b5b5ec50a
2 changed files with 6 additions and 5 deletions
|
@ -29,7 +29,7 @@ import re
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
from ansible.module_utils.six.moves import zip
|
from ansible.module_utils.six.moves import zip
|
||||||
from ansible.module_utils._text import to_bytes
|
from ansible.module_utils._text import to_bytes, to_native
|
||||||
from ansible.module_utils.network_common import to_list
|
from ansible.module_utils.network_common import to_list
|
||||||
|
|
||||||
DEFAULT_COMMENT_TOKENS = ['#', '!', '/*', '*/', 'echo']
|
DEFAULT_COMMENT_TOKENS = ['#', '!', '/*', '*/', 'echo']
|
||||||
|
@ -205,6 +205,7 @@ class NetworkConfig(object):
|
||||||
def parse(self, lines, comment_tokens=None):
|
def parse(self, lines, comment_tokens=None):
|
||||||
toplevel = re.compile(r'\S')
|
toplevel = re.compile(r'\S')
|
||||||
childline = re.compile(r'^\s*(.+)$')
|
childline = re.compile(r'^\s*(.+)$')
|
||||||
|
entry_reg = re.compile(r'([{};])')
|
||||||
|
|
||||||
ancestors = list()
|
ancestors = list()
|
||||||
config = list()
|
config = list()
|
||||||
|
@ -212,8 +213,8 @@ class NetworkConfig(object):
|
||||||
curlevel = 0
|
curlevel = 0
|
||||||
prevlevel = 0
|
prevlevel = 0
|
||||||
|
|
||||||
for linenum, line in enumerate(str(lines).split('\n')):
|
for linenum, line in enumerate(to_native(lines, errors='surrogate_or_strict').split('\n')):
|
||||||
text = str(re.sub(r'([{};])', '', line)).strip()
|
text = entry_reg.sub('', line).strip()
|
||||||
|
|
||||||
cfg = ConfigLine(line)
|
cfg = ConfigLine(line)
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ import time
|
||||||
import glob
|
import glob
|
||||||
|
|
||||||
from ansible.plugins.action.iosxr import ActionModule as _ActionModule
|
from ansible.plugins.action.iosxr import ActionModule as _ActionModule
|
||||||
from ansible.module_utils._text import to_text
|
from ansible.module_utils._text import to_text, to_bytes
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
||||||
from ansible.utils.vars import merge_hash
|
from ansible.utils.vars import merge_hash
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ class ActionModule(_ActionModule):
|
||||||
os.remove(fn)
|
os.remove(fn)
|
||||||
tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time()))
|
tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time()))
|
||||||
filename = '%s/%s_config.%s' % (backup_path, host, tstamp)
|
filename = '%s/%s_config.%s' % (backup_path, host, tstamp)
|
||||||
open(filename, 'w').write(contents)
|
open(filename, 'w').write(to_bytes(contents))
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
def _handle_template(self):
|
def _handle_template(self):
|
||||||
|
|
Loading…
Reference in a new issue