|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
# -*- coding: UTF-8 -*- |
|
3
|
|
|
|
|
4
|
|
|
# Isomer - The distributed application framework |
|
5
|
|
|
# ============================================== |
|
6
|
|
|
# Copyright (C) 2011-2020 Heiko 'riot' Weinen <[email protected]> and others. |
|
7
|
|
|
# |
|
8
|
|
|
# This program is free software: you can redistribute it and/or modify |
|
9
|
|
|
# it under the terms of the GNU Affero General Public License as published by |
|
10
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
|
11
|
|
|
# (at your option) any later version. |
|
12
|
|
|
# |
|
13
|
|
|
# This program is distributed in the hope that it will be useful, |
|
14
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
# GNU Affero General Public License for more details. |
|
17
|
|
|
# |
|
18
|
|
|
# You should have received a copy of the GNU Affero General Public License |
|
19
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
20
|
|
|
|
|
21
|
|
|
""" |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
Module: Error |
|
25
|
|
|
============= |
|
26
|
|
|
|
|
27
|
|
|
Error handling |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
""" |
|
31
|
|
|
|
|
32
|
|
|
import sys |
|
33
|
|
|
|
|
34
|
|
|
from isomer.logger import isolog, critical |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
def log(*args, **kwargs): |
|
38
|
|
|
"""Log as previous emitter""" |
|
39
|
|
|
kwargs.update({"frame_ref": 2}) |
|
40
|
|
|
kwargs["lvl"] = critical |
|
41
|
|
|
if "emitter" not in kwargs: |
|
42
|
|
|
kwargs["emitter"] = "MANAGE" |
|
43
|
|
|
isolog(*args, **kwargs) |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
# TODO: |
|
47
|
|
|
# * Categorize error codes into groups |
|
48
|
|
|
# * Enumerate codes |
|
49
|
|
|
# * Find all calls to abort and fix them up |
|
50
|
|
|
|
|
51
|
|
|
EXIT_INVALID_ENVIRONMENT = {"code": 1, "message": ""} |
|
52
|
|
|
EXIT_INVALID_CONFIGURATION = {"code": 2, "message": ""} |
|
53
|
|
|
EXIT_INVALID_SOURCE = { |
|
54
|
|
|
"code": 3, |
|
55
|
|
|
"message": "Only installing from github or local is currently supported", |
|
56
|
|
|
} |
|
57
|
|
|
EXIT_ROOT_REQUIRED = { |
|
58
|
|
|
"code": 4, |
|
59
|
|
|
"message": "Need root access to install. Use sudo!" |
|
60
|
|
|
} |
|
61
|
|
|
EXIT_NO_PERMISSION = {"code": 5, "message": ""} |
|
62
|
|
|
EXIT_INSTALLATION_FAILED = {"code": 11, "message": ""} |
|
63
|
|
|
EXIT_PROVISIONING_FAILED = {"code": 12, "message": ""} |
|
64
|
|
|
EXIT_INSTANCE_EXISTS = {"code": 21, "message": "Instance already exists"} |
|
65
|
|
|
EXIT_INSTANCE_UNKNOWN = {"code": 22, "message": ""} |
|
66
|
|
|
EXIT_SERVICE_INVALID = {"code": 31, "message": ""} |
|
67
|
|
|
EXIT_USER_BAILED_OUT = {"code": 41, "message": ""} |
|
68
|
|
|
EXIT_NOTHING_TO_ARCHIVE = {"code": 51, "message": ""} |
|
69
|
|
|
EXIT_NO_CONFIGURATION = {"code": 61, "message": ""} |
|
70
|
|
|
EXIT_INVALID_PARAMETER = { |
|
71
|
|
|
"code": 62, |
|
72
|
|
|
"message": "Invalid instance configuration parameter specified", |
|
73
|
|
|
} |
|
74
|
|
|
EXIT_INVALID_VALUE = { |
|
75
|
|
|
"code": 64, |
|
76
|
|
|
"message": "Invalid instance configuration value specified", |
|
77
|
|
|
} |
|
78
|
|
|
EXIT_NO_CERTIFICATE = {"code": 63, "message": ""} |
|
79
|
|
|
EXIT_NO_DATABASE = {"code": 50020, "message": "No database is available"} |
|
80
|
|
|
EXIT_ISOMER_URL_REQUIRED = { |
|
81
|
|
|
"code": 50100, |
|
82
|
|
|
"message": "You need to specify a source url via --url/-u for isomer" |
|
83
|
|
|
} |
|
84
|
|
|
EXIT_STORE_PACKAGE_NOT_FOUND = { |
|
85
|
|
|
"code": 50404, |
|
86
|
|
|
"message": "The requested package is not available in the store" |
|
87
|
|
|
} |
|
88
|
|
|
EXIT_WORK_IN_PROGRESS = { |
|
89
|
|
|
"code": 55555, |
|
90
|
|
|
"message": "This is work in progress" |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
def abort(error_object): |
|
95
|
|
|
"""Abort with a nice error message and if possible an error description |
|
96
|
|
|
url leading to the online documentation.""" |
|
97
|
|
|
|
|
98
|
|
|
url = "https://isomer.readthedocs.io/en/latest/manual/Administration/Errors/%i.html" |
|
99
|
|
View Code Duplication |
if isinstance(error_object, int): |
|
|
|
|
|
|
100
|
|
|
log("Unknown error code.") |
|
101
|
|
|
log("You might be able to find more information above or here:", |
|
102
|
|
|
url % error_object) |
|
103
|
|
|
sys.exit(error_object) |
|
104
|
|
|
else: |
|
105
|
|
|
log( |
|
106
|
|
|
error_object.get( |
|
107
|
|
|
"message", "Sorry, no error message for this specific problem found!" |
|
108
|
|
|
) |
|
109
|
|
|
) |
|
110
|
|
|
log( |
|
111
|
|
|
"Please see ", |
|
112
|
|
|
url % error_object.get("code", "no_code"), |
|
113
|
|
|
"for more information!", |
|
114
|
|
|
) |
|
115
|
|
|
sys.exit(error_object["code"]) |
|
116
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
def warn_error(error_object): |
|
119
|
|
|
"""Warn with a nice error message and if possible an error description |
|
120
|
|
|
url leading to the online documentation.""" |
|
121
|
|
|
|
|
122
|
|
|
url = "https://isomer.readthedocs.io/en/latest/manual/Administration/Errors/%i.html" |
|
123
|
|
View Code Duplication |
if isinstance(error_object, int): |
|
|
|
|
|
|
124
|
|
|
log("Unknown error code.") |
|
125
|
|
|
log("You might be able to find more information above or here:", |
|
126
|
|
|
url % error_object) |
|
127
|
|
|
else: |
|
128
|
|
|
log( |
|
129
|
|
|
error_object.get( |
|
130
|
|
|
"message", "Sorry, no error message for this specific problem found!" |
|
131
|
|
|
) |
|
132
|
|
|
) |
|
133
|
|
|
log( |
|
134
|
|
|
"Please see ", |
|
135
|
|
|
url % error_object.get("code", "no_code"), |
|
136
|
|
|
"for more information!", |
|
137
|
|
|
) |
|
138
|
|
|
|