Revision 69266fae

b/lib/backend.py
647 647
  return result
648 648

  
649 649

  
650
def GetBlockDevSizes(devices):
651
  """Return the size of the given block devices
652

  
653
  @type devices: list
654
  @param devices: list of block device nodes to query
655
  @rtype: dict
656
  @return:
657
    dictionary of all block devices under /dev (key). The value is their
658
    size in MiB.
659

  
660
    {'/dev/disk/by-uuid/123456-12321231-312312-312': 124}
661

  
662
  """
663
  DEV_PREFIX = "/dev/"
664
  blockdevs = {}
665

  
666
  for devpath in devices:
667
    if os.path.commonprefix([DEV_PREFIX, devpath]) != DEV_PREFIX:
668
      continue
669

  
670
    try:
671
      st = os.stat(devpath)
672
    except EnvironmentError, err:
673
      logging.warning("Error stat()'ing device %s: %s", devpath, str(err))
674
      continue
675

  
676
    if stat.S_ISBLK(st.st_mode):
677
      result = utils.RunCmd(["blockdev", "--getsize64", devpath])
678
      if result.failed:
679
        # We don't want to fail, just do not list this device as available
680
        logging.warning("Cannot get size for block device %s", devpath)
681
        continue
682

  
683
      size = int(result.stdout) / (1024 * 1024)
684
      blockdevs[devpath] = size
685
  return blockdevs
686

  
687

  
650 688
def GetVolumeList(vg_names):
651 689
  """Compute list of logical volumes and their size.
652 690

  
b/lib/rpc.py
590 590
  #
591 591

  
592 592
  @_RpcTimeout(_TMO_URGENT)
593
  def call_bdev_sizes(self, node_list, devices):
594
    """Gets the sizes of requested block devices present on a node
595

  
596
    This is a multi-node call.
597

  
598
    """
599
    return self._MultiNodeCall(node_list, "bdev_sizes", [devices])
600

  
601
  @_RpcTimeout(_TMO_URGENT)
593 602
  def call_lv_list(self, node_list, vg_name):
594 603
    """Gets the logical volumes present in a given volume group.
595 604

  
b/lib/server/noded.py
457 457
    export = params[0]
458 458
    return backend.RemoveExport(export)
459 459

  
460
  # block device ---------------------
461
  @staticmethod
462
  def perspective_bdev_sizes(params):
463
    """Query the list of block devices
464

  
465
    """
466
    devices = params[0]
467
    return backend.GetBlockDevSizes(devices)
468

  
460 469
  # volume  --------------------------
461 470

  
462 471
  @staticmethod

Also available in: Unified diff