1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
# Copyright 2017 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import six
from smutLayer import msgs
from zvmconnector import restclient
from zvmconnector import socketclient
from zvmsdk import returncode
SDK_ERR_KEYS = (
'input',
'guest',
'network',
'volume',
'image',
'monitor',
'RESTAPI',
'notExist',
'conflict',
'deleted',
'internal',
'serviceUnavail',
)
def generate_errcode():
_lines = []
# add zvmsdk error codes and messages
for k in SDK_ERR_KEYS:
_error = returncode.errors[k]
_lines.append('**' + _error[2] + '**\n')
if _error[1] == {}:
# no reason code (rs) defined
_line = ';'.join((
six.text_type(_error[0]['overallRC']),
six.text_type(_error[0]['modID']),
six.text_type(_error[0]['rc']),
'',
_error[2],
))
_line += '\n'
_lines.append(_line)
else:
for rs, errmsg in _error[1].items():
_line = ';'.join((
six.text_type(_error[0]['overallRC']),
six.text_type(_error[0]['modID']),
six.text_type(_error[0]['rc']),
six.text_type(rs),
errmsg,
))
_line += '\n'
_lines.append(_line)
# add smut error codes and messages
_lines.append('**' + "smut errors" + '**\n')
_smut_orcs = {}
_smut_errkeys = msgs.msg.keys()
_smut_errkeys.sort()
for k in _smut_errkeys:
_orcs = msgs.msg[k]
_orrc = _orcs[0].get('overallRC')
if _smut_orcs.get(_orrc) is not None:
_smut_orcs[_orrc].append(_orcs)
else:
_smut_orcs[_orrc] = [_orcs]
orcs = _smut_orcs.keys()
orcs.sort()
for orc in orcs:
for _msg in _smut_orcs[orc]:
_orc = _msg[0].get('overallRC')
_mid = '1'
_rc = _msg[0].get('rc')
_rs = _msg[0].get('rs')
_err = _msg[1].replace('%i', '%s') % _msg[2]
_line = ';'.join((
six.text_type(_orc),
six.text_type(_mid),
six.text_type(_rc),
six.text_type(_rs),
six.text_type(_err),
))
_line += '\n'
_lines.append(_line)
# add client error codes and messages
_lines.append('**' + "client errors" + '**\n')
# add restclient errors
for rs, errmsg in restclient.REST_REQUEST_ERROR[1].items():
_line = ';'.join((
six.text_type(restclient.REST_REQUEST_ERROR[0]['overallRC']),
six.text_type(restclient.REST_REQUEST_ERROR[0]['modID']),
six.text_type(restclient.REST_REQUEST_ERROR[0]['rc']),
six.text_type(rs),
errmsg,
))
_line += '\n'
_lines.append(_line)
# add socketclient errors
for rs, errmsg in socketclient.SOCKET_ERROR[1].items():
_line = ';'.join((
six.text_type(socketclient.SOCKET_ERROR[0]['overallRC']),
six.text_type(socketclient.SOCKET_ERROR[0]['modID']),
six.text_type(socketclient.SOCKET_ERROR[0]['rc']),
six.text_type(rs),
errmsg,
))
_line += '\n'
_lines.append(_line)
# add invalid api client errors
_lines.append(';'.join((
six.text_type(restclient.INVALID_API_ERROR[0]['overallRC']),
six.text_type(restclient.INVALID_API_ERROR[0]['modID']),
six.text_type(restclient.INVALID_API_ERROR[0]['rc']),
'1',
six.text_type(restclient.INVALID_API_ERROR[1][1]),
)) + '\n')
# add service unavailable error
_lines.append(';'.join((
six.text_type(restclient.SERVICE_UNAVAILABLE_ERROR[0]['overallRC']),
six.text_type(restclient.SERVICE_UNAVAILABLE_ERROR[0]['modID']),
six.text_type(restclient.SERVICE_UNAVAILABLE_ERROR[0]['rc']),
'2',
six.text_type(restclient.SERVICE_UNAVAILABLE_ERROR[1][2]),
)) + '\n')
return _lines
if __name__ == "__main__":
csv_file = "./errcode.csv"
err_codes = generate_errcode()
with open(csv_file, 'w') as f:
f.writelines(err_codes)
|