Revision ad24e046 lib/objects.py
b/lib/objects.py | ||
---|---|---|
594 | 594 |
|
595 | 595 |
return ret |
596 | 596 |
|
597 |
def FindDisk(self, name):
|
|
598 |
"""Find a disk given having a specified name.
|
|
597 |
def FindDisk(self, idx):
|
|
598 |
"""Find a disk given having a specified index.
|
|
599 | 599 |
|
600 |
This will return the disk which has the given iv_name.
|
|
600 |
This is just a wrapper that does validation of the index.
|
|
601 | 601 |
|
602 |
""" |
|
603 |
for disk in self.disks: |
|
604 |
if disk.iv_name == name: |
|
605 |
return disk |
|
602 |
@type idx: int |
|
603 |
@param idx: the disk index |
|
604 |
@rtype: L{Disk} |
|
605 |
@return: the corresponding disk |
|
606 |
@raise errors.OpPrereqError: when the given index is not valid |
|
606 | 607 |
|
607 |
return None |
|
608 |
""" |
|
609 |
try: |
|
610 |
idx = int(idx) |
|
611 |
return self.disks[idx] |
|
612 |
except ValueError, err: |
|
613 |
raise errors.OpPrereqError("Invalid disk index: '%s'" % str(err)) |
|
614 |
except IndexError: |
|
615 |
raise errors.OpPrereqError("Invalid disk index: %d (instace has disks" |
|
616 |
" 0 to %d" % (idx, len(self.disks))) |
|
608 | 617 |
|
609 | 618 |
def ToDict(self): |
610 | 619 |
"""Instance-specific conversion to standard python types. |
Also available in: Unified diff