summaryrefslogtreecommitdiff
path: root/vymgmt/mgmt_common.py
diff options
context:
space:
mode:
Diffstat (limited to 'vymgmt/mgmt_common.py')
-rw-r--r--vymgmt/mgmt_common.py33
1 files changed, 29 insertions, 4 deletions
diff --git a/vymgmt/mgmt_common.py b/vymgmt/mgmt_common.py
index 1ccb96a..1153c54 100644
--- a/vymgmt/mgmt_common.py
+++ b/vymgmt/mgmt_common.py
@@ -1,5 +1,7 @@
# Copyright (c) 2016 Hochikong
+CODEC = 'utf8'
+
def messenger(obj, config):
"""This method used for sending configuration to VyOS
@@ -11,8 +13,9 @@ def messenger(obj, config):
try:
obj.sendline(config)
obj.prompt()
- if len(obj.before) > obj.before.index('\r\n') + 2:
- return obj.before
+ result = decodetool(obj.before, CODEC)
+ if len(result) > result.index('\r\n') + 2:
+ return result
else:
return "Result : Configured successfully"
except Exception as e:
@@ -26,12 +29,34 @@ def committer(obj, config):
:param config: A configuration string
:return: A message or an error
"""
+ exception_string = "enhanced syslogd: rsyslogd"
try:
obj.sendline(config)
obj.prompt()
- if len(obj.before) > obj.before.index('\r\n') + 2:
- return obj.before
+ result = decodetool(obj.before, CODEC)
+ if len(result) > result.index('\r\n') + 2:
+ if exception_string in result:
+ return "Result : Commit successfully"
+ else:
+ return result
else:
return "Result : Commit successfully"
except Exception as e:
return e
+
+
+def decodetool(target, codec):
+ """This method is used for decoding obj.before to string when run this
+ library under python3
+
+ :param target: The obj.before
+ :param codec: The codec use to decode
+ :return:
+ """
+ try:
+ if type(target) == str:
+ return target
+ if type(target) == bytes:
+ return target.decode(codec)
+ except Exception as e:
+ return e