Revision 1c474f2b lib/config.py

b/lib/config.py
478 478
    """
479 479
    return self._UnlockedGetDiskInfo(disk_uuid)
480 480

  
481
  # pylint: disable=R0201
482 481
  def _UnlockedGetInstanceNodes(self, instance, disks=None):
483 482
    """Get all disk-releated nodes for an instance.
484 483

  
......
486 485

  
487 486
    """
488 487
    all_nodes = []
489
    inst_disks = instance.disks
488
    inst_disks = self._UnlockedGetInstanceDisks(instance)
490 489
    if disks is not None:
491 490
      inst_disks.extend(disks)
492 491
    for disk in inst_disks:
......
564 563
      ret = None
565 564

  
566 565
    node_uuid = instance.primary_node
567
    devs = instance.disks
566
    devs = self._UnlockedGetInstanceDisks(instance)
568 567
    _MapLVsByNode(lvmap, devs, node_uuid)
569 568
    return ret
570 569

  
......
787 786
        lvnames.update(lv_list)
788 787
    return lvnames
789 788

  
790
  def _AllDisks(self):
791
    """Compute the list of all Disks (recursively, including children).
792

  
793
    """
794
    def DiskAndAllChildren(disk):
795
      """Returns a list containing the given disk and all of his children.
796

  
797
      """
798
      disks = [disk]
799
      if disk.children:
800
        for child_disk in disk.children:
801
          disks.extend(DiskAndAllChildren(child_disk))
802
      return disks
803

  
804
    disks = []
805
    for instance in self._config_data.instances.values():
806
      for disk in instance.disks:
807
        disks.extend(DiskAndAllChildren(disk))
808
    return disks
809

  
810 789
  def _AllNICs(self):
811 790
    """Compute the list of all NICs.
812 791

  
......
889 868
          helper(child, result)
890 869

  
891 870
    result = []
892
    for instance in self._config_data.instances.values():
893
      for disk in instance.disks:
894
        helper(disk, result)
871
    for disk in self._config_data.disks.values():
872
      helper(disk, result)
895 873

  
896 874
    return result
897 875

  
898
  def _CheckDiskIDs(self, disk, l_ids):
899
    """Compute duplicate disk IDs
900

  
901
    @type disk: L{objects.Disk}
902
    @param disk: the disk at which to start searching
903
    @type l_ids: list
904
    @param l_ids: list of current logical ids
905
    @rtype: list
906
    @return: a list of error messages
907

  
908
    """
909
    result = []
910
    if disk.logical_id is not None:
911
      if disk.logical_id in l_ids:
912
        result.append("duplicate logical id %s" % str(disk.logical_id))
913
      else:
914
        l_ids.append(disk.logical_id)
915

  
916
    if disk.children:
917
      for child in disk.children:
918
        result.extend(self._CheckDiskIDs(child, l_ids))
919
    return result
920

  
921 876
  def _UnlockedVerifyConfig(self):
922 877
    """Verify function.
923 878

  
......
932 887
    ports = {}
933 888
    data = self._config_data
934 889
    cluster = data.cluster
935
    seen_lids = []
936 890

  
937 891
    # global cluster checks
938 892
    if not cluster.enabled_hypervisors:
......
1033 987
          )
1034 988
        )
1035 989

  
990
    # per-disk checks
991
    for disk_uuid in data.disks:
992
      disk = data.disks[disk_uuid]
993
      if disk.uuid != disk_uuid:
994
        result.append("disk '%s' is indexed by wrong UUID '%s'" %
995
                      (disk.name, disk_uuid))
996

  
1036 997
    # per-instance checks
1037 998
    for instance_uuid in data.instances:
1038 999
      instance = data.instances[instance_uuid]
......
1069 1030
        _helper("instance %s" % instance.name, "beparams",
1070 1031
                cluster.FillBE(instance), constants.BES_PARAMETER_TYPES)
1071 1032

  
1033
      # check that disks exists
1034
      for disk_uuid in instance.disks:
1035
        if disk_uuid not in data.disks:
1036
          result.append("Instance '%s' has invalid disk '%s'" %
1037
                        (instance.name, disk_uuid))
1038

  
1039
      inst_disks = self._UnlockedGetInstanceDisks(instance)
1072 1040
      # gather the drbd ports for duplicate checks
1073
      for (idx, dsk) in enumerate(instance.disks):
1041
      for (idx, dsk) in enumerate(inst_disks):
1074 1042
        if dsk.dev_type in constants.DTS_DRBD:
1075 1043
          tcp_port = dsk.logical_id[2]
1076 1044
          if tcp_port not in ports:
......
1083 1051
          ports[net_port] = []
1084 1052
        ports[net_port].append((instance.name, "network port"))
1085 1053

  
1086
      # instance disk verify
1087
      for idx, disk in enumerate(instance.disks):
1088
        result.extend(["instance '%s' disk %d error: %s" %
1089
                       (instance.name, idx, msg) for msg in disk.Verify()])
1090
        result.extend(self._CheckDiskIDs(disk, seen_lids))
1091

  
1092
      wrong_names = _CheckInstanceDiskIvNames(instance.disks)
1054
      wrong_names = _CheckInstanceDiskIvNames(inst_disks)
1093 1055
      if wrong_names:
1094 1056
        tmp = "; ".join(("name of disk %s should be '%s', but is '%s'" %
1095 1057
                         (idx, exp_name, actual_name))
......
1308 1270
    duplicates = []
1309 1271
    my_dict = dict((node_uuid, {}) for node_uuid in self._config_data.nodes)
1310 1272
    for instance in self._config_data.instances.itervalues():
1311
      for disk in instance.disks:
1273
      for disk in self._UnlockedGetInstanceDisks(instance):
1312 1274
        duplicates.extend(_AppendUsedMinors(self._UnlockedGetNodeName,
1313 1275
                                            instance, disk, my_dict))
1314 1276
    for (node_uuid, minor), inst_uuid in self._temporary_drbds.iteritems():
......
1929 1891
    inst = self._config_data.instances[inst_uuid]
1930 1892
    inst.name = new_name
1931 1893

  
1932
    for (_, disk) in enumerate(inst.disks):
1894
    inst_disks = self._UnlockedGetInstanceDisks(inst)
1895
    for (_, disk) in enumerate(inst_disks):
1933 1896
      if disk.dev_type in [constants.DT_FILE, constants.DT_SHARED_FILE]:
1934 1897
        # rename the file paths in logical and physical id
1935 1898
        file_storage_dir = os.path.dirname(os.path.dirname(disk.logical_id[1]))
......
2675 2638
            self._config_data.nodes.values() +
2676 2639
            self._config_data.nodegroups.values() +
2677 2640
            self._config_data.networks.values() +
2678
            self._AllDisks() +
2641
            self._config_data.disks.values() +
2679 2642
            self._AllNICs() +
2680 2643
            [self._config_data.cluster])
2681 2644

  

Also available in: Unified diff