Revision 468c5f77 lib/bdev.py

b/lib/bdev.py
26 26
import errno
27 27
import pyparsing as pyp
28 28
import os
29
import logging
29 30

  
30 31
from ganeti import utils
31
from ganeti import logger
32 32
from ganeti import errors
33 33
from ganeti import constants
34 34

  
......
337 337
               "--separator=:"]
338 338
    result = utils.RunCmd(command)
339 339
    if result.failed:
340
      logger.Error("Can't get the PV information: %s - %s" %
341
                   (result.fail_reason, result.output))
340
      logging.error("Can't get the PV information: %s - %s",
341
                    result.fail_reason, result.output)
342 342
      return None
343 343
    data = []
344 344
    for line in result.stdout.splitlines():
345 345
      fields = line.strip().split(':')
346 346
      if len(fields) != 4:
347
        logger.Error("Can't parse pvs output: line '%s'" % line)
347
        logging.error("Can't parse pvs output: line '%s'", line)
348 348
        return None
349 349
      # skip over pvs from another vg or ones which are not allocatable
350 350
      if fields[1] != vg_name or fields[3][0] != 'a':
......
363 363
    result = utils.RunCmd(["lvremove", "-f", "%s/%s" %
364 364
                           (self._vg_name, self._lv_name)])
365 365
    if result.failed:
366
      logger.Error("Can't lvremove: %s - %s" %
367
                   (result.fail_reason, result.output))
366
      logging.error("Can't lvremove: %s - %s",
367
                    result.fail_reason, result.output)
368 368

  
369 369
    return not result.failed
370 370

  
......
398 398
                           "-olv_attr,lv_kernel_major,lv_kernel_minor",
399 399
                           self.dev_path])
400 400
    if result.failed:
401
      logger.Error("Can't find LV %s: %s, %s" %
402
                   (self.dev_path, result.fail_reason, result.output))
401
      logging.error("Can't find LV %s: %s, %s",
402
                    self.dev_path, result.fail_reason, result.output)
403 403
      return False
404 404
    out = result.stdout.strip().rstrip(',')
405 405
    out = out.split(",")
406 406
    if len(out) != 3:
407
      logger.Error("Can't parse LVS output, len(%s) != 3" % str(out))
407
      logging.error("Can't parse LVS output, len(%s) != 3", str(out))
408 408
      return False
409 409

  
410 410
    status, major, minor = out[:3]
411 411
    if len(status) != 6:
412
      logger.Error("lvs lv_attr is not 6 characters (%s)" % status)
412
      logging.error("lvs lv_attr is not 6 characters (%s)", status)
413 413
      return False
414 414

  
415 415
    try:
416 416
      major = int(major)
417 417
      minor = int(minor)
418 418
    except ValueError, err:
419
      logger.Error("lvs major/minor cannot be parsed: %s" % str(err))
419
      logging.error("lvs major/minor cannot be parsed: %s", str(err))
420 420

  
421 421
    self.major = major
422 422
    self.minor = minor
......
434 434
    """
435 435
    result = utils.RunCmd(["lvchange", "-ay", self.dev_path])
436 436
    if result.failed:
437
      logger.Error("Can't activate lv %s: %s" % (self.dev_path, result.output))
437
      logging.error("Can't activate lv %s: %s", self.dev_path, result.output)
438 438
    return not result.failed
439 439

  
440 440
  def Shutdown(self):
......
742 742
    """
743 743
    result = utils.RunCmd(["blockdev", "--getsize", meta_device])
744 744
    if result.failed:
745
      logger.Error("Failed to get device size: %s - %s" %
746
                   (result.fail_reason, result.output))
745
      logging.error("Failed to get device size: %s - %s",
746
                    result.fail_reason, result.output)
747 747
      return False
748 748
    try:
749 749
      sectors = int(result.stdout)
750 750
    except ValueError:
751
      logger.Error("Invalid output from blockdev: '%s'" % result.stdout)
751
      logging.error("Invalid output from blockdev: '%s'", result.stdout)
752 752
      return False
753 753
    bytes = sectors * 512
754 754
    if bytes < 128 * 1024 * 1024: # less than 128MiB
755
      logger.Error("Meta device too small (%.2fMib)" % (bytes / 1024 / 1024))
755
      logging.error("Meta device too small (%.2fMib)", (bytes / 1024 / 1024))
756 756
      return False
757 757
    if bytes > (128 + 32) * 1024 * 1024: # account for an extra (big) PE on LVM
758
      logger.Error("Meta device too big (%.2fMiB)" % (bytes / 1024 / 1024))
758
      logging.error("Meta device too big (%.2fMiB)", (bytes / 1024 / 1024))
759 759
      return False
760 760
    return True
761 761

  
......
840 840
    if highest is None: # there are no minors in use at all
841 841
      return 0
842 842
    if highest >= cls._MAX_MINORS:
843
      logger.Error("Error: no free drbd minors!")
843
      logging.error("Error: no free drbd minors!")
844 844
      raise errors.BlockDeviceError("Can't find a free DRBD minor")
845 845
    return highest + 1
846 846

  
......
855 855
                           "v08", meta_device, "0",
856 856
                           "dstate"])
857 857
    if result.failed:
858
      logger.Error("Invalid meta device %s: %s" % (meta_device, result.output))
858
      logging.error("Invalid meta device %s: %s", meta_device, result.output)
859 859
      return False
860 860
    return True
861 861

  
......
916 916
    """
917 917
    result = utils.RunCmd(["drbdsetup", cls._DevPath(minor), "show"])
918 918
    if result.failed:
919
      logger.Error("Can't display the drbd config: %s - %s" %
920
                   (result.fail_reason, result.output))
919
      logging.error("Can't display the drbd config: %s - %s",
920
                    result.fail_reason, result.output)
921 921
      return None
922 922
    return result.stdout
923 923

  
......
1030 1030
            backend, meta, "0", "-e", "detach", "--create-device"]
1031 1031
    result = utils.RunCmd(args)
1032 1032
    if result.failed:
1033
      logger.Error("Can't attach local disk: %s" % result.output)
1033
      logging.error("Can't attach local disk: %s", result.output)
1034 1034
    return not result.failed
1035 1035

  
1036 1036
  @classmethod
......
1057 1057
      args.extend(["-a", hmac, "-x", secret])
1058 1058
    result = utils.RunCmd(args)
1059 1059
    if result.failed:
1060
      logger.Error("Can't setup network for dbrd device: %s - %s" %
1061
                   (result.fail_reason, result.output))
1060
      logging.error("Can't setup network for dbrd device: %s - %s",
1061
                    result.fail_reason, result.output)
1062 1062
      return False
1063 1063

  
1064 1064
    timeout = time.time() + 10
......
1075 1075
      ok = True
1076 1076
      break
1077 1077
    if not ok:
1078
      logger.Error("Timeout while configuring network")
1078
      logging.error("Timeout while configuring network")
1079 1079
      return False
1080 1080
    return True
1081 1081

  
......
1120 1120
      raise errors.BlockDeviceError("We don't have two children: %s" %
1121 1121
                                    self._children)
1122 1122
    if self._children.count(None) == 2: # we don't actually have children :)
1123
      logger.Error("Requested detach while detached")
1123
      logging.error("Requested detach while detached")
1124 1124
      return
1125 1125
    if len(devices) != 2:
1126 1126
      raise errors.BlockDeviceError("We need two children in RemoveChildren")
......
1140 1140
    """
1141 1141
    children_result = super(DRBD8, self).SetSyncSpeed(kbytes)
1142 1142
    if self.minor is None:
1143
      logger.Info("Instance not attached to a device")
1143
      logging.info("Instance not attached to a device")
1144 1144
      return False
1145 1145
    result = utils.RunCmd(["drbdsetup", self.dev_path, "syncer", "-r", "%d" %
1146 1146
                           kbytes])
1147 1147
    if result.failed:
1148
      logger.Error("Can't change syncer rate: %s - %s" %
1149
                   (result.fail_reason, result.output))
1148
      logging.error("Can't change syncer rate: %s - %s",
1149
                    result.fail_reason, result.output)
1150 1150
    return not result.failed and children_result
1151 1151

  
1152 1152
  def GetProcStatus(self):
......
1196 1196

  
1197 1197
    """
1198 1198
    if self.minor is None and not self.Attach():
1199
      logger.Error("DRBD cannot attach to a device during open")
1199
      logging.error("DRBD cannot attach to a device during open")
1200 1200
      return False
1201 1201
    cmd = ["drbdsetup", self.dev_path, "primary"]
1202 1202
    if force:
......
1204 1204
    result = utils.RunCmd(cmd)
1205 1205
    if result.failed:
1206 1206
      msg = ("Can't make drbd device primary: %s" % result.output)
1207
      logger.Error(msg)
1207
      logging.error(msg)
1208 1208
      raise errors.BlockDeviceError(msg)
1209 1209

  
1210 1210
  def Close(self):
......
1214 1214

  
1215 1215
    """
1216 1216
    if self.minor is None and not self.Attach():
1217
      logger.Info("Instance not attached to a device")
1217
      logging.info("Instance not attached to a device")
1218 1218
      raise errors.BlockDeviceError("Can't find device")
1219 1219
    result = utils.RunCmd(["drbdsetup", self.dev_path, "secondary"])
1220 1220
    if result.failed:
1221 1221
      msg = ("Can't switch drbd device to"
1222 1222
             " secondary: %s" % result.output)
1223
      logger.Error(msg)
1223
      logging.error(msg)
1224 1224
      raise errors.BlockDeviceError(msg)
1225 1225

  
1226 1226
  def Attach(self):
......
1300 1300
    """
1301 1301
    self.Attach()
1302 1302
    if self.minor is not None:
1303
      logger.Info("Already assembled")
1303
      logging.info("Already assembled")
1304 1304
      return True
1305 1305

  
1306 1306
    result = super(DRBD8, self).Assemble()
......
1323 1323
      if not result:
1324 1324
        if need_localdev_teardown:
1325 1325
          # we will ignore failures from this
1326
          logger.Error("net setup failed, tearing down local device")
1326
          logging.error("net setup failed, tearing down local device")
1327 1327
          self._ShutdownAll(minor)
1328 1328
        return False
1329 1329
    self._SetFromMinor(minor)
......
1339 1339
    """
1340 1340
    result = utils.RunCmd(["drbdsetup", cls._DevPath(minor), "detach"])
1341 1341
    if result.failed:
1342
      logger.Error("Can't detach local device: %s" % result.output)
1342
      logging.error("Can't detach local device: %s", result.output)
1343 1343
    return not result.failed
1344 1344

  
1345 1345
  @classmethod
......
1351 1351
    """
1352 1352
    result = utils.RunCmd(["drbdsetup", cls._DevPath(minor), "disconnect"])
1353 1353
    if result.failed:
1354
      logger.Error("Can't shutdown network: %s" % result.output)
1354
      logging.error("Can't shutdown network: %s", result.output)
1355 1355
    return not result.failed
1356 1356

  
1357 1357
  @classmethod
......
1363 1363
    """
1364 1364
    result = utils.RunCmd(["drbdsetup", cls._DevPath(minor), "down"])
1365 1365
    if result.failed:
1366
      logger.Error("Can't shutdown drbd device: %s" % result.output)
1366
      logging.error("Can't shutdown drbd device: %s", result.output)
1367 1367
    return not result.failed
1368 1368

  
1369 1369
  def Shutdown(self):
......
1371 1371

  
1372 1372
    """
1373 1373
    if self.minor is None and not self.Attach():
1374
      logger.Info("DRBD device not attached to a device during Shutdown")
1374
      logging.info("DRBD device not attached to a device during Shutdown")
1375 1375
      return True
1376 1376
    if not self._ShutdownAll(self.minor):
1377 1377
      return False
......
1491 1491
      os.remove(self.dev_path)
1492 1492
      return True
1493 1493
    except OSError, err:
1494
      logger.Error("Can't remove file '%s': %s"
1495
                   % (self.dev_path, err))
1494
      logging.error("Can't remove file '%s': %s", self.dev_path, err)
1496 1495
      return False
1497 1496

  
1498 1497
  def Attach(self):

Also available in: Unified diff