Revision 60975797 lib/cmdlib.py

b/lib/cmdlib.py
1329 1329
    return result
1330 1330

  
1331 1331

  
1332
class LURepairDiskSizes(NoHooksLU):
1333
  """Verifies the cluster disks sizes.
1334

  
1335
  """
1336
  _OP_REQP = ["instances"]
1337
  REQ_BGL = False
1338

  
1339
  def ExpandNames(self):
1340

  
1341
    if not isinstance(self.op.instances, list):
1342
      raise errors.OpPrereqError("Invalid argument type 'instances'")
1343

  
1344
    if self.op.instances:
1345
      self.wanted_names = []
1346
      for name in self.op.instances:
1347
        full_name = self.cfg.ExpandInstanceName(name)
1348
        if full_name is None:
1349
          raise errors.OpPrereqError("Instance '%s' not known" % name)
1350
        self.wanted_names.append(full_name)
1351
      self.needed_locks[locking.LEVEL_INSTANCE] = self.wanted_names
1352
      self.needed_locks = {
1353
        locking.LEVEL_NODE: [],
1354
        locking.LEVEL_INSTANCE: self.wanted_names,
1355
        }
1356
      self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE
1357
    else:
1358
      self.wanted_names = None
1359
      self.needed_locks = {
1360
        locking.LEVEL_NODE: locking.ALL_SET,
1361
        locking.LEVEL_INSTANCE: locking.ALL_SET,
1362
        }
1363
    self.share_locks = dict(((i, 1) for i in locking.LEVELS))
1364

  
1365
  def DeclareLocks(self, level):
1366
    if level == locking.LEVEL_NODE and self.wanted_names is not None:
1367
      self._LockInstancesNodes(primary_only=True)
1368

  
1369
  def CheckPrereq(self):
1370
    """Check prerequisites.
1371

  
1372
    This only checks the optional instance list against the existing names.
1373

  
1374
    """
1375
    if self.wanted_names is None:
1376
      self.wanted_names = self.acquired_locks[locking.LEVEL_INSTANCE]
1377

  
1378
    self.wanted_instances = [self.cfg.GetInstanceInfo(name) for name
1379
                             in self.wanted_names]
1380

  
1381
  def Exec(self, feedback_fn):
1382
    """Verify the size of cluster disks.
1383

  
1384
    """
1385
    # TODO: check child disks too
1386
    # TODO: check differences in size between primary/secondary nodes
1387
    per_node_disks = {}
1388
    for instance in self.wanted_instances:
1389
      pnode = instance.primary_node
1390
      if pnode not in per_node_disks:
1391
        per_node_disks[pnode] = []
1392
      for idx, disk in enumerate(instance.disks):
1393
        per_node_disks[pnode].append((instance, idx, disk))
1394

  
1395
    changed = []
1396
    for node, dskl in per_node_disks.items():
1397
      result = self.rpc.call_blockdev_getsizes(node, [v[2] for v in dskl])
1398
      if result.failed:
1399
        self.LogWarning("Failure in blockdev_getsizes call to node"
1400
                        " %s, ignoring", node)
1401
        continue
1402
      if len(result.data) != len(dskl):
1403
        self.LogWarning("Invalid result from node %s, ignoring node results",
1404
                        node)
1405
        continue
1406
      for ((instance, idx, disk), size) in zip(dskl, result.data):
1407
        if size is None:
1408
          self.LogWarning("Disk %d of instance %s did not return size"
1409
                          " information, ignoring", idx, instance.name)
1410
          continue
1411
        if not isinstance(size, (int, long)):
1412
          self.LogWarning("Disk %d of instance %s did not return valid"
1413
                          " size information, ignoring", idx, instance.name)
1414
          continue
1415
        size = size >> 20
1416
        if size != disk.size:
1417
          self.LogInfo("Disk %d of instance %s has mismatched size,"
1418
                       " correcting: recorded %d, actual %d", idx,
1419
                       instance.name, disk.size, size)
1420
          disk.size = size
1421
          self.cfg.Update(instance)
1422
          changed.append((instance.name, idx, size))
1423
    return changed
1424

  
1425

  
1332 1426
class LURenameCluster(LogicalUnit):
1333 1427
  """Rename the cluster.
1334 1428

  

Also available in: Unified diff