Revision acf931b7 lib/mcpu.py

b/lib/mcpu.py
153 153

  
154 154
    """
155 155

  
156
  def ReportLocks(self, msg):
157
    """Report lock operations.
156
  def CheckCancel(self):
157
    """Check whether job has been cancelled.
158 158

  
159 159
    """
160 160

  
......
238 238
    self.rpc = rpc.RpcRunner(context.cfg)
239 239
    self.hmclass = HooksMaster
240 240

  
241
  def _ReportLocks(self, level, names, shared, timeout, acquired, result):
242
    """Reports lock operations.
243

  
244
    @type level: int
245
    @param level: Lock level
246
    @type names: list or string
247
    @param names: Lock names
248
    @type shared: bool
249
    @param shared: Whether the locks should be acquired in shared mode
250
    @type timeout: None or float
251
    @param timeout: Timeout for acquiring the locks
252
    @type acquired: bool
253
    @param acquired: Whether the locks have already been acquired
254
    @type result: None or set
255
    @param result: Result from L{locking.GanetiLockManager.acquire}
256

  
257
    """
258
    parts = []
259

  
260
    # Build message
261
    if acquired:
262
      if result is None:
263
        parts.append("timeout")
264
      else:
265
        parts.append("acquired")
266
    else:
267
      parts.append("waiting")
268
      if timeout is None:
269
        parts.append("blocking")
270
      else:
271
        parts.append("timeout=%0.6fs" % timeout)
272

  
273
    parts.append(locking.LEVEL_NAMES[level])
274

  
275
    if names == locking.ALL_SET:
276
      parts.append("ALL")
277
    elif isinstance(names, basestring):
278
      parts.append(names)
279
    else:
280
      parts.append(",".join(sorted(names)))
281

  
282
    if shared:
283
      parts.append("shared")
284
    else:
285
      parts.append("exclusive")
286

  
287
    msg = "/".join(parts)
288

  
289
    logging.debug("LU locks %s", msg)
290

  
291
    if self._cbs:
292
      self._cbs.ReportLocks(msg)
293

  
294 241
  def _AcquireLocks(self, level, names, shared, timeout):
295 242
    """Acquires locks via the Ganeti lock manager.
296 243

  
......
304 251
    @param timeout: Timeout for acquiring the locks
305 252

  
306 253
    """
307
    self._ReportLocks(level, names, shared, timeout, False, None)
254
    if self._cbs:
255
      self._cbs.CheckCancel()
308 256

  
309 257
    acquired = self.context.glm.acquire(level, names, shared=shared,
310 258
                                        timeout=timeout)
311 259

  
312
    self._ReportLocks(level, names, shared, timeout, True, acquired)
313

  
314 260
    return acquired
315 261

  
316 262
  def _ExecLU(self, lu):

Also available in: Unified diff