Revision 20faaa74 lib/rpc.py

b/lib/rpc.py
610 610
  if lvm_pv_info:
611 611
    result["spindles_free"] = lvm_pv_info["storage_free"]
612 612
    result["spindles_total"] = lvm_pv_info["storage_size"]
613
  else:
614
    raise errors.OpExecError("No spindle storage information available.")
613 615

  
614 616

  
615
def _AddDefaultStorageInfoToLegacyNodeInfo(result, space_info,
616
                                           require_vg_info=True):
617
def _AddDefaultStorageInfoToLegacyNodeInfo(result, space_info):
617 618
  """Extracts the storage space information of the default storage type from
618 619
  the space info and adds it to the result dictionary.
619 620

  
620 621
  @see: C{_AddSpindlesToLegacyNodeInfo} for parameter information.
621
  @type require_vg_info: boolean
622
  @param require_vg_info: indicates whether volume group information is
623
    required or not
624 622

  
625 623
  """
626 624
  # Check if there is at least one row for non-spindle storage info.
......
633 631
  else:
634 632
    default_space_info = space_info[0]
635 633

  
636
  if require_vg_info:
637
    # if lvm storage is required, ignore the actual default and look for LVM
638
    lvm_info_found = False
639
    for space_entry in space_info:
640
      if space_entry["type"] == constants.ST_LVM_VG:
641
        default_space_info = space_entry
642
        lvm_info_found = True
643
        continue
644
    if not lvm_info_found:
645
      raise errors.OpExecError("LVM volume group info required, but not"
646
                               " provided.")
647

  
648 634
  if default_space_info:
649 635
    result["name"] = default_space_info["name"]
650 636
    result["storage_free"] = default_space_info["storage_free"]
651 637
    result["storage_size"] = default_space_info["storage_size"]
652 638

  
653 639

  
654
def MakeLegacyNodeInfo(data, require_vg_info=True):
640
def MakeLegacyNodeInfo(data, require_spindles=False):
655 641
  """Formats the data returned by L{rpc.RpcRunner.call_node_info}.
656 642

  
657 643
  Converts the data into a single dictionary. This is fine for most use cases,
658 644
  but some require information from more than one volume group or hypervisor.
659 645

  
660
  @param require_vg_info: raise an error if the returnd vg_info
661
      doesn't have any values
646
  @param require_spindles: add spindle storage information to the legacy node
647
      info
662 648

  
663 649
  """
664 650
  (bootid, space_info, (hv_info, )) = data
665 651

  
666 652
  ret = utils.JoinDisjointDicts(hv_info, {"bootid": bootid})
667 653

  
668
  _AddSpindlesToLegacyNodeInfo(ret, space_info)
669
  _AddDefaultStorageInfoToLegacyNodeInfo(ret, space_info,
670
                                         require_vg_info=require_vg_info)
654
  if require_spindles:
655
    _AddSpindlesToLegacyNodeInfo(ret, space_info)
656
  _AddDefaultStorageInfoToLegacyNodeInfo(ret, space_info)
671 657

  
672 658
  return ret
673 659

  

Also available in: Unified diff