Revision c04bc777

b/lib/bdev.py
959 959
      sectors = int(result.stdout)
960 960
    except (TypeError, ValueError):
961 961
      _ThrowError("Invalid output from blockdev: '%s'", result.stdout)
962
    bytes = sectors * 512
963
    if bytes < 128 * 1024 * 1024: # less than 128MiB
964
      _ThrowError("Meta device too small (%.2fMib)", (bytes / 1024 / 1024))
962
    num_bytes = sectors * 512
963
    if num_bytes < 128 * 1024 * 1024: # less than 128MiB
964
      _ThrowError("Meta device too small (%.2fMib)", (num_bytes / 1024 / 1024))
965 965
    # the maximum *valid* size of the meta device when living on top
966 966
    # of LVM is hard to compute: it depends on the number of stripes
967 967
    # and the PE size; e.g. a 2-stripe, 64MB PE will result in a 128MB
968 968
    # (normal size), but an eight-stripe 128MB PE will result in a 1GB
969 969
    # size meta device; as such, we restrict it to 1GB (a little bit
970 970
    # too generous, but making assumptions about PE size is hard)
971
    if bytes > 1024 * 1024 * 1024:
972
      _ThrowError("Meta device too big (%.2fMiB)", (bytes / 1024 / 1024))
971
    if num_bytes > 1024 * 1024 * 1024:
972
      _ThrowError("Meta device too big (%.2fMiB)", (num_bytes / 1024 / 1024))
973 973

  
974 974
  def Rename(self, new_id):
975 975
    """Rename a device.
b/lib/cli.py
2000 2000

  
2001 2001
  if separator is None:
2002 2002
    mlens = [0 for name in fields]
2003
    format = ' '.join(format_fields)
2003
    format_str = ' '.join(format_fields)
2004 2004
  else:
2005
    format = separator.replace("%", "%%").join(format_fields)
2005
    format_str = separator.replace("%", "%%").join(format_fields)
2006 2006

  
2007 2007
  for row in data:
2008 2008
    if row is None:
......
2028 2028
        mlens[idx] = max(mlens[idx], len(hdr))
2029 2029
        args.append(mlens[idx])
2030 2030
      args.append(hdr)
2031
    result.append(format % tuple(args))
2031
    result.append(format_str % tuple(args))
2032 2032

  
2033 2033
  if separator is None:
2034 2034
    assert len(mlens) == len(fields)
......
2044 2044
      if separator is None:
2045 2045
        args.append(mlens[idx])
2046 2046
      args.append(line[idx])
2047
    result.append(format % tuple(args))
2047
    result.append(format_str % tuple(args))
2048 2048

  
2049 2049
  return result
2050 2050

  
b/scripts/gnt-job
200 200
  @return: the desired exit code
201 201

  
202 202
  """
203
  def format(level, text):
203
  def format_msg(level, text):
204 204
    """Display the text indented."""
205 205
    ToStdout("%s%s", "  " * level, text)
206 206

  
......
222 222

  
223 223
  for idx, entry in enumerate(result):
224 224
    if not first:
225
      format(0, "")
225
      format_msg(0, "")
226 226
    else:
227 227
      first = False
228 228

  
229 229
    if entry is None:
230 230
      if idx <= len(args):
231
        format(0, "Job ID %s not found" % args[idx])
231
        format_msg(0, "Job ID %s not found" % args[idx])
232 232
      else:
233 233
        # this should not happen, when we don't pass args it will be a
234 234
        # valid job returned
235
        format(0, "Job ID requested as argument %s not found" % (idx + 1))
235
        format_msg(0, "Job ID requested as argument %s not found" % (idx + 1))
236 236
      continue
237 237

  
238 238
    (job_id, status, ops, opresult, opstatus, oplog,
239 239
     opstart, opexec, opend, recv_ts, start_ts, end_ts) = entry
240
    format(0, "Job ID: %s" % job_id)
240
    format_msg(0, "Job ID: %s" % job_id)
241 241
    if status in _USER_JOB_STATUS:
242 242
      status = _USER_JOB_STATUS[status]
243 243
    else:
244 244
      raise errors.ProgrammerError("Unknown job status code '%s'" % status)
245 245

  
246
    format(1, "Status: %s" % status)
246
    format_msg(1, "Status: %s" % status)
247 247

  
248 248
    if recv_ts is not None:
249
      format(1, "Received:         %s" % FormatTimestamp(recv_ts))
249
      format_msg(1, "Received:         %s" % FormatTimestamp(recv_ts))
250 250
    else:
251
      format(1, "Missing received timestamp (%s)" % str(recv_ts))
251
      format_msg(1, "Missing received timestamp (%s)" % str(recv_ts))
252 252

  
253 253
    if start_ts is not None:
254 254
      if recv_ts is not None:
......
256 256
        delta = " (delta %.6fs)" % d1
257 257
      else:
258 258
        delta = ""
259
      format(1, "Processing start: %s%s" % (FormatTimestamp(start_ts), delta))
259
      format_msg(1, "Processing start: %s%s" %
260
                 (FormatTimestamp(start_ts), delta))
260 261
    else:
261
      format(1, "Processing start: unknown (%s)" % str(start_ts))
262
      format_msg(1, "Processing start: unknown (%s)" % str(start_ts))
262 263

  
263 264
    if end_ts is not None:
264 265
      if start_ts is not None:
......
266 267
        delta = " (delta %.6fs)" % d2
267 268
      else:
268 269
        delta = ""
269
      format(1, "Processing end:   %s%s" % (FormatTimestamp(end_ts), delta))
270
      format_msg(1, "Processing end:   %s%s" %
271
                 (FormatTimestamp(end_ts), delta))
270 272
    else:
271
      format(1, "Processing end:   unknown (%s)" % str(end_ts))
273
      format_msg(1, "Processing end:   unknown (%s)" % str(end_ts))
272 274

  
273 275
    if end_ts is not None and recv_ts is not None:
274 276
      d3 = end_ts[0] - recv_ts[0] + (end_ts[1] - recv_ts[1]) / 1000000.0
275
      format(1, "Total processing time: %.6f seconds" % d3)
277
      format_msg(1, "Total processing time: %.6f seconds" % d3)
276 278
    else:
277
      format(1, "Total processing time: N/A")
278
    format(1, "Opcodes:")
279
      format_msg(1, "Total processing time: N/A")
280
    format_msg(1, "Opcodes:")
279 281
    for (opcode, result, status, log, s_ts, x_ts, e_ts) in \
280 282
            zip(ops, opresult, opstatus, oplog, opstart, opexec, opend):
281
      format(2, "%s" % opcode["OP_ID"])
282
      format(3, "Status: %s" % status)
283
      format_msg(2, "%s" % opcode["OP_ID"])
284
      format_msg(3, "Status: %s" % status)
283 285
      if isinstance(s_ts, (tuple, list)):
284
        format(3, "Processing start: %s" % FormatTimestamp(s_ts))
286
        format_msg(3, "Processing start: %s" % FormatTimestamp(s_ts))
285 287
      else:
286
        format(3, "No processing start time")
288
        format_msg(3, "No processing start time")
287 289
      if isinstance(x_ts, (tuple, list)):
288
        format(3, "Execution start:  %s" % FormatTimestamp(x_ts))
290
        format_msg(3, "Execution start:  %s" % FormatTimestamp(x_ts))
289 291
      else:
290
        format(3, "No execution start time")
292
        format_msg(3, "No execution start time")
291 293
      if isinstance(e_ts, (tuple, list)):
292
        format(3, "Processing end:   %s" % FormatTimestamp(e_ts))
294
        format_msg(3, "Processing end:   %s" % FormatTimestamp(e_ts))
293 295
      else:
294
        format(3, "No processing end time")
295
      format(3, "Input fields:")
296
        format_msg(3, "No processing end time")
297
      format_msg(3, "Input fields:")
296 298
      for key, val in opcode.iteritems():
297 299
        if key == "OP_ID":
298 300
          continue
299 301
        if isinstance(val, (tuple, list)):
300 302
          val = ",".join([str(item) for item in val])
301
        format(4, "%s: %s" % (key, val))
303
        format_msg(4, "%s: %s" % (key, val))
302 304
      if result is None:
303
        format(3, "No output data")
305
        format_msg(3, "No output data")
304 306
      elif isinstance(result, (tuple, list)):
305 307
        if not result:
306
          format(3, "Result: empty sequence")
308
          format_msg(3, "Result: empty sequence")
307 309
        else:
308
          format(3, "Result:")
310
          format_msg(3, "Result:")
309 311
          for elem in result:
310
            format(4, result_helper(elem))
312
            format_msg(4, result_helper(elem))
311 313
      elif isinstance(result, dict):
312 314
        if not result:
313
          format(3, "Result: empty dictionary")
315
          format_msg(3, "Result: empty dictionary")
314 316
        else:
315 317
          for key, val in result.iteritems():
316
            format(4, "%s: %s" % (key, result_helper(val)))
318
            format_msg(4, "%s: %s" % (key, result_helper(val)))
317 319
      else:
318
        format(3, "Result: %s" % result)
319
      format(3, "Execution log:")
320
        format_msg(3, "Result: %s" % result)
321
      format_msg(3, "Execution log:")
320 322
      for serial, log_ts, log_type, log_msg in log:
321 323
        time_txt = FormatTimestamp(log_ts)
322 324
        encoded = utils.SafeEncode(log_msg)
323
        format(4, "%s:%s:%s %s" % (serial, time_txt, log_type, encoded))
325
        format_msg(4, "%s:%s:%s %s" % (serial, time_txt, log_type, encoded))
324 326
  return 0
325 327

  
326 328

  

Also available in: Unified diff