diff options
author | hochikong <1097225749@qq.com> | 2016-08-24 14:41:35 +0800 |
---|---|---|
committer | hochikong <1097225749@qq.com> | 2016-08-24 14:41:35 +0800 |
commit | 5c7c56264681faa44b2bca036973b08cecf168ae (patch) | |
tree | e8c917d971e8585924515612d068eb672c4d2b9c /vymgmt/error_distinguish.py | |
parent | 2528aa7872958c8e4507d8f42ba0fe767989b19b (diff) | |
download | python-vyos-mgmt-5c7c56264681faa44b2bca036973b08cecf168ae.tar.gz python-vyos-mgmt-5c7c56264681faa44b2bca036973b08cecf168ae.zip |
T133 Add a generic method set() and delete()
Fix all problems from now on
Diffstat (limited to 'vymgmt/error_distinguish.py')
-rw-r--r-- | vymgmt/error_distinguish.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/vymgmt/error_distinguish.py b/vymgmt/error_distinguish.py new file mode 100644 index 0000000..d58db2f --- /dev/null +++ b/vymgmt/error_distinguish.py @@ -0,0 +1,64 @@ +# Copyright (c) 2016 Hochikong + + +def distinguish_for_set(message): + """Distinguish the error type,PathError or ValueError + + :param message: A error message string from VyOS + :return: The type of error + """ + path_error_string = ['Configuration path:', 'is not valid'] + value_error_string = ['Value validation failed'] + all_strings = [path_error_string, value_error_string] + condition = 0 + for i in all_strings: + for x in i: + if x in message: + condition += 1 + + if condition == 2: + return "ConfigPathError" + elif condition == 1: + return "ConfigValueError" + else: + return "NonsupportButError" + + +def distinguish_for_delete(message): + """Distinguish the error type,PathError or ValueError + + :param message: A error message string from VyOS + :return: The type of error + """ + path_error_string = ['Configuration path:', 'is not valid', 'Delete failed'] + value_error_string = ['Nothing to delete', 'the specified value does not exist'] + all_strings = [path_error_string, value_error_string] + condition = 0 + + for i in all_strings: + for x in i: + if x in message: + condition += 1 + + if condition == 3: + return "ConfigPathError" + elif condition == 2: + return "ConfigValueError" + else: + return "NonsupportButError" + + +def distinguish_for_commit(message): + """Distinguish the error type + + :param message: A error message string from VyOS + :return: The type of error + """ + all_strings = ['Commit failed', 'due to another commit in progress'] + + for i in all_strings: + if i in message: + if i == all_strings[0]: + return "CommitFailed" + if i == all_strings[1]: + return "CommitConflict" |