cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
messages_codes.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 # @COPYRIGHT_begin
3 #
4 # Copyright [2010-2014] Institute of Nuclear Physics PAN, Krakow, Poland
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # @COPYRIGHT_end
19 
20 ##
21 # @package src.wi.utils.messages_codes
22 #
23 # @author Krzysztof Danielowski
24 # @author Piotr W√≥jcik
25 # @date 01.04.2012
26 #
27 
28 import logging
29 
30 from django.template.defaultfilters import force_escape
31 from django.utils.translation import ugettext_lazy as _
32 
33 
34 auth_error_text = _('Authorization error. Re-login required.')
35 
36 # \c errors - dictionary of the errors <b>informations' keys</b> and <b>information</b>
37 # (for error informations without parameters):
38 # - CLM ERRORS dictionary
39 # - CM ERRORS dictionary
40 ERRORS = {
41  'ok': _('No error'),
42  #===============================================================================
43  # CLM ERRORS
44  #===============================================================================
45  'clm_error': _('Server error.'),
46 
47  'cluster_add': _('Error: adding cluster failed.'),
48  'cluster_add_admin': _('Error: adding admin to cluster failed.'),
49  'cluster_add_users': _('Error: adding users to cluster failed.'),
50  'cluster_edit': _('Error: editing cluster failed.'),
51  'cluster_get': _('Error: invalid Cluster Manager - please login again.'),
52  'cluster_lock': _('Error: locking cluster failed.'),
53  'cluster_unlock': _('Error: unlocking cluster failed.'),
54 
55  'group_change_owner': _('Error: changing leader failed.'),
56  'group_create': _('Error: creating group failed.'),
57  'group_get': _('Error: group not found.'),
58  'group_delete': _('Error: deleting group failed.'),
59  'group_delete_user': _('Error: deleting user from group failed.'),
60  'group_edit': _('Error: editing group failed.'),
61 
62  'news_create': _('Error: creating news failed.'),
63  'news_delete': _('Error: deleting news failed.'),
64  'news_edit': _('Error: editing news failed.'),
65  'news_get': _('Error: news not found.'),
66 
67  'reset_password_error': _('Error: mailing server is not active.'),
68  'reset_password_smtp_error': _('Error: sending email.'),
69  'send_issue_error': _('Error: sending email to administrator.'),
70 
71  'ssh_key_already_exist': _('Error: ssh key already exist.'),
72  'ssh_key_format': _('Error: invalid format.'),
73  'ssh_key_generate': _('Error: generating key failed.'),
74  'ssh_key_get': _('Error: key not found.'),
75  'ssh_key_limit': _('Error: key limit.'),
76 
77  'user_activate': _('Error: activating user failed.'),
78  'user_active': _('Error: deleting user account.'),
79  'user_block': _('Error: blocking user failed.'),
80  'user_delete': _('Error: deleting user failed.'),
81  'user_edit': _('Error: editing user data failed.'),
82  'user_get': _('Error: user not found.'),
83  'user_inactive': _("Error: user account isn't activated."),
84  'user_not_in_group': _("Error: user doesn't belong to this group."),
85  'user_permission': _('Error: you have no permissions.'),
86  'user_register': _('Error: registering user failed.'),
87  'user_set_admin': _('Error: setting admin failed.'),
88  'user_set_password': _('Error: setting password failed.'),
89  'user2group_get': _('Error: request for this group not found.'),
90  'user_state': _('Error: user is in wrong state'),
91  'user_unblock': _('Error: unlocking user failed.'),
92  'user_unset_admin': _('Error: unsetting admin failed.'),
93 
94  #===============================================================================
95  # CM ERRORS
96  #===============================================================================
97  'cm_error': _('Server error.'),
98 
99  'admin_add': _('Error: setting admin failed.'),
100 
101  'ctx_error': _('Error in contextualization module.'),
102  'ctx_timeout': _('Error: connecting to contextualization failed.'),
103  'ctx_execute_command': _('Error: executing command failed.'),
104 
105  'farm_create': _('Error: creating farm failed.'),
106  'farm_destroy': _('Error: destroying farm failed.'),
107  'farm_wrong_state': _('Error: wrong farm state.'),
108 
109  'image_attached': _('Error: image already attached.'),
110  'image_calculate_size': _('Error: calculating size of image failed.'),
111  'image_change_type': _('Error: changing type failed.'),
112  'image_create': _('Error: creating image failed.'),
113  'image_delete': _('Error: deleting image failed.'),
114  'image_edit': _('Error: editing image failed.'),
115  'image_get': _('Error: image not found.'),
116  'image_not_found': _('Error: image not found.'),
117  'image_permission': _('Error: you have no permissions.'),
118  'image_set_group': _('Error: attaching image to group failed.'),
119  'image_set_private': _('Error: setting image to private failed.'),
120  'image_set_public': _('Error: setting image to public failed.'),
121  'image_unavailable': _('Error: image is not available.'),
122 
123  'iso_image_get': _('Error: ISO image not found.'),
124  'iso_image_permission': _('Error: you have no permissions.'),
125 
126  'lease_create': _('Error: creating node failed.'),
127  'lease_attached': _('Error: Lease is attached to vm.'),
128 
129  'node_create': _('Error: creating node failed.'),
130  'node_delete': _('Error: deleting node failed.'),
131  'node_edit': _('Error: editing node failed.'),
132  'node_get': _('Error: not enough resources. Choose smaller template or try again later.'),
133  'node_has_vms': _('Error: node has running virtual machines.'),
134  'node_lock': _('Error: locking node failed.'),
135  'node_unlock': _('Error: unlocking node failed.'),
136 
137  'public_lease_assign': _('Error: assigning public IP address failed.'),
138  'public_lease_limit': _('Error: IP limit reached.'),
139  'public_lease_request': _('Error: requesting IP address failed.'),
140  'public_lease_unassign': _('Error: revoking IP address failed.'),
141 
142  'storage_already_exist': _('Error: storage with this name and mountpoint already exist.'),
143  'storage_image_attach': _('Error: attaching disk failed.'),
144  'storage_image_detach': _('Error: detaching disk failed.'),
145  'storage_image_get': _('Error: disk not found.'),
146  'system_image_permission': _('Error: you have no permissions.'),
147 
148  'system_image_get': _('Error: image not found.'),
149  'system_image_permission': _('Error: you have no permissions.'),
150 
151  'template_create': _('Error: creating template failed.'),
152  'template_delete': _('Error: deleting template failed.'),
153  'template_edit': _('Error: editing template failed.'),
154  'template_get': _('Error: template not found.'),
155 
156  'user_change_quota': _('Error: changing quota failed.'),
157  'user_cpu_limit': _('Error: CPU limit reached.'),
158  'user_create': _('Error: creating user failed.'),
159  'user_memory_limit': _('Error: memory limit reached.'),
160  'user_points_limit': _('Error: points limit reached.'),
161  'user_storage_limit': _('Error: user quota exceeded.'),
162 
163  'vm_already_closing': _('Error: virtual machine is already closing.'),
164  'vm_cannot_shutdown': _('Error: shutting down virtual machine failed. Please shutdown your machine from the machine\'s operating system.'),
165  'vm_create': _('Error: creating virtual machine failed.'),
166  'vm_ctx_connect': _('Error: connecting to contextualization failed.'),
167  'vm_destroy': _('Error: destroying virtual machine failed.'),
168  'vm_get': _('Error: virtual machine not found.'),
169  'vm_get_lv_domain': _('System error.'),
170  'vm_hasnt_lease': _('Error: virtual machine does not have an IP address assigned.'),
171  'vm_has_public_lease': _('Error: virtual machine already has an IP address assigned.'),
172  'vm_novnc_not_found': _('Error: cannot find NoVNC port.'),
173  'vm_restart': _('Error: resetting virtual machine failed.'),
174  'vm_save': _('Error: saving virtual machine failed.'),
175  'vm_wrong_state': _('Error: wrong virtual machine state.'),
176  'vm_vnc_attached': _('Error: VNC already attached.'),
177  'vm_vnc_not_found': _('Error: cannot find VNC port.'),
178 
179  'vnc_attach': _('Error: VNC failed.'),
180 
181  'network_delete': _('Error: Cannot delete network.'),
182  'network_in_use': _('Error: Network is still in use.'),
183  'network_not_available': _('Error: No network is available at this moment.'),
184  'network_type': _('Error: Unsupported network type. Contact Administrator.'),
185 }
186 
187 
188 ##
189 #
190 # If error with \c error_key exists, function returns it's message. Otherwise it returns "*Unknown error :(*" message.
191 #
192 def get_error(error_key):
193  return force_escape(ERRORS.get(error_key) or error_key)
194 
195 # message_codes - dictionary of the error <b>messages' keys</b> and <b>messages</b>
196 # (for error messages with parameters).
197 MESSAGE_CODES = {
198  'farm_create': _('Error: starting farm: <em>%(name)s</em> (ID: %(id)s) failed.'),
199  'vm_create': _('Error: starting virtual machine: <em>%(name)s</em> (ID: %(id)s) failed.'),
200  'vm_save': _('Error: saving virtual machine: <em>%(name)s</em> (ID: %(id)s) failed.'),
201  'vm_destroy': _('Error: destroying virtual machine: <em>%(name)s</em> (ID: %(id)s) failed.'),
202  'image_init': _('Error: creating image: <em>%(name)s</em> (ID: %(id)d) failed.'),
203  'image_create': _('Error: creating image: <em>%(name)s</em> (ID: %(id)d, size: %(size)d MB) failed.'),
204  'image_download': _('Error: downloading image: <em>%(name)s</em> (ID: %(id)d) from %(path)s failed.'),
205  'image_format': _('Error: formating image: <em>%(name)s</em> (ID: %(id)d) with filesystem %(filesystem)s failed.'),
206  'group_request': _('<em>%(first_name)s %(last_name)s</em> wants to join to group <a href="%(grp_details_url)s"> <b>%(group_name)s</b></a>.'),
207  'image_created': _('Image <em>%(name)s</em> created.'),
208  'image_downloaded': _('Image <em>%(name)s</em> downloaded (md5sum: <em>%(md5sum)s</em>).'),
209  'point_limit': _('Point limit reached: %(used_points)d / %(point_limit)d.'),
210  'vm_saved': _('VM %(vm_name)s saved successfuly. You can find it on the list of private images.'),
211  'farm_saved': _('Farm %(farm_name)s saved successfuly. You can find it on the list of private images.'),
212 }
213 
214 
215 ##
216 #
217 # Method returns error message containing given parameters.
218 #
219 def get_message(message_key, params):
220  from django.core.urlresolvers import reverse
221  if MESSAGE_CODES.get(message_key) is None:
222  return message_key
223  message = _('Bad message code.')
224  params = dict((k, force_escape(v) if isinstance(v, str) else v) for k, v in params.iteritems())
225  if message_key == 'group_request':
226  params['grp_details_url'] = reverse('grp_details', args=[params['group_id']])
227  try:
228  message = MESSAGE_CODES.get(message_key) % params
229  except Exception:
230  wi_logger = logging.getLogger('wi_logger')
231  wi_logger.error('get_message( message_key=%s, params=%s)' % (message_key, params))
232  return message
233