Revision 86f046a8

b/invitations/invitations.py
49 49
from synnefo.logic.email_send import send_async, send
50 50
from synnefo.api.common import method_not_allowed
51 51
from synnefo.db.models import Invitations, SynnefoUser
52
from synnefo.logic import users, log
52
from synnefo.logic import users
53
from synnefo.util.log import getLogger
53 54

  
54 55
from Crypto.Cipher import AES
55 56

  
56
_logger = log.get_logger("synnefo.invitations")
57
log = getLogger('synnefo.invitations')
57 58

  
58 59

  
59 60
def process_form(request):
......
81 82
                       (name, email, e.messages[0])]
82 83
        except Exception as e:
83 84
            remove_invitation(invitation)
84
            _logger.exception(e)
85
            log.exception(e)
85 86
            errors += ["Invitation to %s <%s> could not be sent. An unexpected"
86 87
                       " error occurred. Please try again later." %
87 88
                       (name, email)]
......
97 98
                                     get_invitations_left(request.user)},
98 99
                                context_instance=RequestContext(request))
99 100
        response = HttpResponse(data)
100
        _logger.warn("Error adding invitation %s -> %s: %s" %
101
                     (request.user.uniq, email, errors))
101
        log.warn("Error adding invitation %s -> %s: %s",
102
                    request.user.uniq, email, errors)
102 103
    else:
103 104
        # form submitted
104 105
        data = render_to_string('invitations.html',
......
108 109
                                    get_invitations_left(request.user)},
109 110
                                context_instance=RequestContext(request))
110 111
        response = HttpResponse(data)
111
        _logger.info("Added invitation %s -> %s" % (request.user.uniq, email))
112
        log.info("Added invitation %s -> %s", request.user.uniq, email)
112 113

  
113 114
    return response
114 115

  
......
214 215
    inv.accepted = True
215 216
    inv.save()
216 217

  
217
    _logger.info("Invited user %s logged in", inv.target.uniq)
218
    log.info("Invited user %s logged in", inv.target.uniq)
218 219

  
219 220
    data = dict()
220 221
    data['user'] = user.realname
......
255 256

  
256 257
    data = render_to_string('invitation.txt', {'email': email})
257 258

  
258
    _logger.debug("Invitation URL: %s" % email['url'])
259
    log.debug("Invitation URL: %s", email['url'])
259 260

  
260 261
    # send_async(
261 262
    #    frm = "%s"%(settings.DEFAULT_FROM_EMAIL),
......
310 311
    try:
311 312
        send_invitation(inv)
312 313
    except Exception as e:
313
        _logger.exception(e)
314
        log.exception(e)
314 315
        return HttpResponseServerError("Error sending invitation email")
315 316

  
316 317
    return HttpResponse("Invitation has been resent")
b/logic/callbacks.py
30 30
# Callback functions used by the dispatcher to process incoming notifications
31 31
# from AMQP queues.
32 32

  
33
import logging
33 34
import socket
34 35
import traceback
35 36
import json
36 37
import sys
37 38

  
38 39
from synnefo.db.models import VirtualMachine
39
from synnefo.logic import utils, backend, email_send, log
40
from synnefo.logic import utils, backend, email_send
40 41

  
41
_logger = log.get_logger("synnefo.dispatcher")
42

  
43
log = logging.getLogger()
42 44

  
43 45

  
44 46
def update_db(message):
45 47
    """Process a notification of type 'ganeti-op-status'"""
46
    _logger.debug("Processing ganeti-op-status msg: %s", message.body)
48
    log.debug("Processing ganeti-op-status msg: %s", message.body)
47 49
    msg = None
48 50
    try:
49 51
        msg = json.loads(message.body)
50 52

  
51 53
        if msg["type"] != "ganeti-op-status":
52
            _logger.error("Message is of unknown type %s.", msg["type"])
54
            log.error("Message is of unknown type %s.", msg["type"])
53 55
            return
54 56

  
55 57
        if msg["operation"] == "OP_INSTANCE_QUERY_DATA":
......
60 62

  
61 63
        backend.process_op_status(vm, msg["jobId"], msg["operation"],
62 64
                                  msg["status"], msg["logmsg"])
63
        _logger.debug("Done processing ganeti-op-status msg for vm %s.",
65
        log.debug("Done processing ganeti-op-status msg for vm %s.",
64 66
                      msg["instance"])
65 67
        message.channel.basic_ack(message.delivery_tag)
66 68
    except KeyError:
67
        _logger.error("Malformed incoming JSON, missing attributes: %s",
69
        log.error("Malformed incoming JSON, missing attributes: %s",
68 70
                      message.body)
69 71
    except VirtualMachine.InvalidBackendIdError:
70
        _logger.debug("Ignoring msg for unknown instance %s.",
71
                      msg["instance"])
72
        log.debug("Ignoring msg for unknown instance %s.", msg["instance"])
72 73
    except VirtualMachine.InvalidBackendMsgError, e:
73
        _logger.debug("Ignoring msg of unknown type: %s.", e)
74
        log.debug("Ignoring msg of unknown type: %s.", e)
74 75
    except VirtualMachine.DoesNotExist:
75
        _logger.error("VM for instance %s with id %d not found in DB.",
76
        log.error("VM for instance %s with id %d not found in DB.",
76 77
                      msg["instance"], vmid)
77 78
    except Exception as e:
78
        _logger.exception("Unexpected error, msg: %s", msg)
79
        log.exception("Unexpected error, msg: %s", msg)
79 80

  
80 81

  
81 82
def update_net(message):
82 83
    """Process a notification of type 'ganeti-net-status'"""
83
    _logger.debug("Processing ganeti-net-status msg: %s", message.body)
84
    log.debug("Processing ganeti-net-status msg: %s", message.body)
84 85
    msg = None
85 86
    try:
86 87
        msg = json.loads(message.body)
87 88

  
88 89
        if msg["type"] != "ganeti-net-status":
89
            _logger.error("Message is of unknown type %s", msg["type"])
90
            log.error("Message is of unknown type %s", msg["type"])
90 91
            return
91 92

  
92 93
        vmid = utils.id_from_instance_name(msg["instance"])
93 94
        vm = VirtualMachine.objects.get(id=vmid)
94 95

  
95 96
        backend.process_net_status(vm, msg["nics"])
96
        _logger.debug("Done processing ganeti-net-status msg for vm %s.",
97
        log.debug("Done processing ganeti-net-status msg for vm %s.",
97 98
                      msg["instance"])
98 99
        message.channel.basic_ack(message.delivery_tag)
99 100
    except KeyError:
100
        _logger.error("Malformed incoming JSON, missing attributes: %s",
101
        log.error("Malformed incoming JSON, missing attributes: %s",
101 102
                      message.body)
102 103
    except VirtualMachine.InvalidBackendIdError:
103
        _logger.debug("Ignoring msg for unknown instance %s.",
104
                      msg["instance"])
104
        log.debug("Ignoring msg for unknown instance %s.", msg["instance"])
105 105
    except VirtualMachine.DoesNotExist:
106
        _logger.error("VM for instance %s with id %d not found in DB.",
106
        log.error("VM for instance %s with id %d not found in DB.",
107 107
                      msg["instance"], vmid)
108 108
    except Exception as e:
109
        _logger.exception("Unexpected error, msg: %s", msg)
109
        log.exception("Unexpected error, msg: %s", msg)
110 110

  
111 111

  
112 112
def send_email(message):
......
119 119
                        body=msg['body'], subject=msg['subject'])
120 120

  
121 121
        if not sent:
122
            _logger.warn("Failed to send email to %s", msg['to'])
122
            log.warn("Failed to send email to %s", msg['to'])
123 123
        else:
124 124
            message.channel.basic_ack(message.delivery_tag)
125 125
    except KeyError:
126
        _logger.error("Malformed incoming JSON, missing attributes: %s",
126
        log.error("Malformed incoming JSON, missing attributes: %s",
127 127
                      message.body)
128 128
    except socket.error as e:
129
        _logger.error("Cannot connect to SMTP server:%s\n", e)
129
        log.error("Cannot connect to SMTP server:%s\n", e)
130 130
    except Exception as e:
131
        _logger.exception("Unexpected error, msg: %s", msg)
131
        log.exception("Unexpected error, msg: %s", msg)
132 132
        raise
133 133

  
134 134

  
135 135
def update_credits(message):
136
    _logger.debug("Request to update credits")
136
    log.debug("Request to update credits")
137 137
    message.channel.basic_ack(message.delivery_tag)
138 138

  
139 139

  
140 140
def update_build_progress(message):
141 141
    """Process a create progress message"""
142
    _logger.debug("Processing ganeti-create-progress msg: %s", message.body)
142
    log.debug("Processing ganeti-create-progress msg: %s", message.body)
143 143
    msg = None
144 144
    try:
145 145
        msg = json.loads(message.body)
146 146

  
147 147
        if msg['type'] != "ganeti-create-progress":
148
            _logger.error("Message is of unknown type %s", msg["type"])
148
            log.error("Message is of unknown type %s", msg["type"])
149 149
            return
150 150

  
151 151
        # XXX: The following assumes names like snf-12
......
153 153
        vm = VirtualMachine.objects.get(id=vmid)
154 154

  
155 155
        backend.process_create_progress(vm, msg['rprogress'], None)
156
        _logger.debug("Done processing ganeti-create-progress msg for vm %s.",
156
        log.debug("Done processing ganeti-create-progress msg for vm %s.",
157 157
                      msg["instance"])
158 158
        message.channel.basic_ack(message.delivery_tag)
159 159
    except KeyError:
160
        _logger.error("Malformed incoming JSON, missing attributes: %s",
160
        log.error("Malformed incoming JSON, missing attributes: %s",
161 161
                      message.body)
162 162
    except Exception as e:
163
        _logger.exception("Unexpected error, msg: %s", msg)
163
        log.exception("Unexpected error, msg: %s", msg)
164 164
        raise
165 165

  
166 166

  
167 167
def trigger_status_update(message):
168 168
    """Triggers a status update job for a specific VM id"""
169
    _logger.debug("Request to trigger status update: %s", message.body)
169
    log.debug("Request to trigger status update: %s", message.body)
170 170
    msg = None
171 171
    try:
172 172
        msg = json.loads(message.body)
173 173

  
174 174
        if msg["type"] != "reconcile":
175
             _logger.error("Message is of unknown type %s", msg["type"])
175
             log.error("Message is of unknown type %s", msg["type"])
176 176
             return
177 177

  
178 178
        if msg["vmid"] == "":
179
            _logger.error("Reconciliation message does not specify a VM id")
179
            log.error("Reconciliation message does not specify a VM id")
180 180
            return
181 181

  
182 182
        vm = VirtualMachine.objects.get(id=msg["vmid"])
......
184 184

  
185 185
        message.channel.basic_ack(message.delivery_tag)
186 186
    except KeyError as k:
187
        _logger.error("Malformed incoming JSON, missing attributes: %s", k)
187
        log.error("Malformed incoming JSON, missing attributes: %s", k)
188 188
    except Exception as e:
189
        _logger.exception("Unexpected error, msg: %s", msg)
189
        log.exception("Unexpected error, msg: %s", msg)
190 190

  
191 191

  
192 192
def status_job_finished(message):
......
196 196
        msg = json.loads(message.body)
197 197

  
198 198
        if msg["operation"] != 'OP_INSTANCE_QUERY_DATA':
199
            _logger.error("Message is of unknown type %s", msg["operation"])
199
            log.error("Message is of unknown type %s", msg["operation"])
200 200
            return
201 201

  
202 202
        if msg["status"] != "success":
203
            _logger.warn("Ignoring non-success status update from job %d on VM %s",
203
            log.warn("Ignoring non-success status update from job %d on VM %s",
204 204
                          msg['jobId'], msg['instance'])
205 205
            message.channel.basic_ack(message.delivery_tag)
206 206
            return
207 207

  
208 208
        status = backend.get_job_status(msg['jobId'])
209 209

  
210
        _logger.debug("Node status job result: %s" % status)
210
        log.debug("Node status job result: %s", status)
211 211

  
212 212
        if status['summary'][0] != u'INSTANCE_QUERY_DATA':
213
             _logger.error("Status update is of unknown type %s", status['summary'])
213
             log.error("Status update is of unknown type %s",
214
                        status['summary'])
214 215
             return
215 216

  
216 217
        conf_state = status['opresult'][0][msg['instance']]['config_state']
......
232 233

  
233 234
        message.channel.basic_ack(message.delivery_tag)
234 235
    except KeyError as k:
235
        _logger.error("Malformed incoming JSON, missing attributes: %s", k)
236
        log.error("Malformed incoming JSON, missing attributes: %s", k)
236 237
    except Exception as e:
237
        _logger.exception("Unexpected error, msg: %s", msg)
238
        log.exception("Unexpected error, msg: %s", msg)
238 239

  
239 240

  
240 241
def dummy_proc(message):
241 242
    try:
242
        _logger.debug("Msg: %s", message.body)
243
        log.debug("Msg: %s", message.body)
243 244
        message.channel.basic_ack(message.delivery_tag)
244 245
    except Exception as e:
245
        _logger.exception("Could not receive message")
246
        log.exception("Could not receive message")
246 247
        pass

Also available in: Unified diff