Commit ad24e046 authored by Iustin Pop's avatar Iustin Pop
Browse files

Change GrowDisk to work with multi-disk

This patch changes the instance.FindDisk method to take index arguments
(instead of iv_names), and changes GrowDisk and list instances
accordingly.

Reviewed-by: ultrotter
parent eafd8762
......@@ -2858,11 +2858,11 @@ class LUQueryInstances(NoHooksLU):
elif field == "mac":
val = instance.nics[0].mac
elif field == "sda_size" or field == "sdb_size":
disk = instance.FindDisk(field[:3])
if disk is None:
idx = ord(field[2]) - ord('a')
try:
val = instance.FindDisk(idx).size
except errors.OpPrereqError:
val = None
else:
val = disk.size
elif field == "tags":
val = list(instance.GetTags())
elif field == "serial_no":
......@@ -4479,9 +4479,7 @@ class LUGrowDisk(LogicalUnit):
raise errors.OpPrereqError("Instance's disk layout does not support"
" growing.")
if instance.FindDisk(self.op.disk) is None:
raise errors.OpPrereqError("Disk '%s' not found for instance '%s'" %
(self.op.disk, instance.name))
self.disk = instance.FindDisk(self.op.disk)
nodenames = [instance.primary_node] + list(instance.secondary_nodes)
nodeinfo = self.rpc.call_node_info(nodenames, self.cfg.GetVGName(),
......@@ -4505,7 +4503,7 @@ class LUGrowDisk(LogicalUnit):
"""
instance = self.instance
disk = instance.FindDisk(self.op.disk)
disk = self.disk
for node in (instance.secondary_nodes + (instance.primary_node,)):
self.cfg.SetDiskID(disk, node)
result = self.rpc.call_blockdev_grow(node, disk, self.op.amount)
......
......@@ -594,17 +594,26 @@ class Instance(TaggableObject):
return ret
def FindDisk(self, name):
"""Find a disk given having a specified name.
def FindDisk(self, idx):
"""Find a disk given having a specified index.
This will return the disk which has the given iv_name.
This is just a wrapper that does validation of the index.
"""
for disk in self.disks:
if disk.iv_name == name:
return disk
@type idx: int
@param idx: the disk index
@rtype: L{Disk}
@return: the corresponding disk
@raise errors.OpPrereqError: when the given index is not valid
return None
"""
try:
idx = int(idx)
return self.disks[idx]
except ValueError, err:
raise errors.OpPrereqError("Invalid disk index: '%s'" % str(err))
except IndexError:
raise errors.OpPrereqError("Invalid disk index: %d (instace has disks"
" 0 to %d" % (idx, len(self.disks)))
def ToDict(self):
"""Instance-specific conversion to standard python types.
......
......@@ -631,6 +631,10 @@ def GrowDisk(opts, args):
"""
instance = args[0]
disk = args[1]
try:
disk = int(disk)
except ValueError, err:
raise errors.OpPrereqError("Invalid disk index: %s" % str(err))
amount = utils.ParseUnit(args[2])
op = opcodes.OpGrowDisk(instance_name=instance, disk=disk, amount=amount,
wait_for_sync=opts.wait_for_sync)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment